Cistercian numerals: Difference between revisions

From Rosetta Code
Content added Content deleted
m (→‎{{header|Plain English}}: remove vestigial test)
(→‎{{header|Raku}}: Add a Raku example)
Line 172: Line 172:
{{out}}
{{out}}
https://commons.wikimedia.org/wiki/File:Cistercian_numerals.png
https://commons.wikimedia.org/wiki/File:Cistercian_numerals.png

=={{header|Raku}}==
Handles 0 through 9999 only. No error trapping. If you feed it an unsupported number it will truncate to maximum 4 digits.

<lang perl6>my @line-segments = (0,0,0,100),
(0, 0, 35, 0), (0,35, 35,35), (0, 0, 35,35), (0,35, 35, 0), ( 35, 0, 35, 35),
(0, 0,-35, 0), (0,35,-35,35), (0, 0,-35,35), (0,35,-35, 0), (-35, 0,-35, 35),
(0,100, 35,100), (0,65, 35,65), (0,100, 35,65), (0,65, 35,100), ( 35,65, 35,100),
(0,100,-35,100), (0,65,-35,65), (0,100,-35,65), (0,65,-35,100), (-35,65,-35,100);

my @components = map {@line-segments[$_]}, |((0,5,10,15).map: -> $m {
|((0,), (1,), (2,), (3,), (4,), (1,4), (5,), (1,5), (2,5), (1,2,5)).map: {$_ »+» $m}
});

my $out = 'Cistercian-raku.svg'.IO.open(:w);

$out.say: # header
q|<svg width="1450" height="200" style="stroke:black;" version="1.1" xmlns="http://www.w3.org/2000/svg">
<rect width="100%" height="100%" style="fill:white;" />|;

my $hs = 30; # horizontal spacing

for flat ^10, 20, 300, 4000, 5555, 6789, 9394, 7922 -> $cistercian {
my $vs = 50; # vertical spacing

# base vertical bar
$out.say: @components[0].map: { qq|<line x1="{$_.[0] + $hs}" y1="{$_.[1] + $vs}" x2="{$_.[2] + $hs}" y2="{$_.[3] + $vs}"/>| };

if $cistercian {
my @oom = $cistercian.polymod(10 xx *); # orders of magnitude
for @oom.kv -> $order, $value {
next unless $value;
last if $order > 3;
# draw the component line segments
$out.say: join "\n", @components[$order * 10 + $value].map: {
qq|<line x1="{$_.[0] + $hs}" y1="{$_.[1] + $vs}" x2="{$_.[2] + $hs}" y2="{$_.[3] + $vs}" />|
}
}
}
# insert the decimal number below
$out.say: qq|<text x="{$hs - 5}" y="170" style="fill:black;" >{$cistercian}</text>|;
$hs += 85; # increment horizontal spacing
}
$out.say: q|</svg>|; # footer</lang>
[https://github.com/thundergnat/rc/blob/master/img/Cistercian-raku.svg See SVG image: (offsite link)]


=={{header|Wren}}==
=={{header|Wren}}==

Revision as of 02:10, 8 November 2020

Cistercian numerals is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.

Cistercian numerals were used across Europe by Cistercian monks during the Late Medieval Period as an alternative to Roman numerals. They were used to represent base 10 integers from 0 to 9999.

How they work

All Cistercian numerals begin with a vertical line segment, which by itself represents the number 0. Then, glyphs representing the digits 1 through 9 are optionally added to the four quadrants surrounding the vertical line segment. These glyphs are drawn with vertical and horizontal symmetry about the initial line segment. Each quadrant corresponds to a digit place in the number:

  • The upper-right quadrant represents the ones place.
  • The upper-left quadrant represents the tens place.
  • The lower-right quadrant represents the hundreds place.
  • The lower-left quadrant represents the thousands place.

Please consult the following image for examples of Cistercian numerals showing each glyph: [1]

Task
  • Write a function/procedure/routine to display any given Cistercian numeral. This could be done by drawing to the display, creating an image, or even as text (as long as it is a reasonable facsimile).
  • Use the routine to show the following Cistercian numerals:
  • 0
  • 1
  • 20
  • 300
  • 4000
  • 5555
  • 6789
  • And a number of your choice!
Notes

Due to the inability to upload images to Rosetta Code as of this task's creation, showing output here on this page is not required. However, it is welcomed — especially for text output.

See also


Plain English

<lang plainenglish>To run: Start up. Show some example Cistercian numbers. Wait for the escape key. Shut down.

To show some example Cistercian numbers: Put the screen's left plus 1 inch into the context's spot's x. Clear the screen to the lightest gray color. Use the black color. Use the fat pen. Draw 0. Draw 1. Draw 20. Draw 300. Draw 4000. Draw 5555. Draw 6789. Draw 9394. Refresh the screen.

The mirror flag is a flag.

To draw a Cistercian number: Split the Cistercian number into some thousands and some hundreds and some tens and some ones. Stroke zero. Set the mirror flag. Stroke the ones. Clear the mirror flag. Stroke the tens. Turn around. Stroke the hundreds. Set the mirror flag. Stroke the thousands. Turn around. Label the Cistercian number. Move the context's spot right 1 inch.

To label a Cistercian number: Save the context. Move down the half stem plus the small stem. Imagine a box with the context's spot and the context's spot. Draw "" then the Cistercian number in the center of the box with the dark gray color. Restore the context.

Some tens are a number.

Some ones are a number.

To split a number into some thousands and some hundreds and some tens and some ones: Divide the number by 10 giving a quotient and a remainder. Put the remainder into the ones. Divide the quotient by 10 giving another quotient and another remainder. Put the other remainder into the tens. Divide the other quotient by 10 giving a third quotient and a third remainder. Put the third remainder into the hundreds. Divide the third quotient by 10 giving a fourth quotient and a fourth remainder. Put the fourth remainder into the thousands.

The small stem is a length equal to 1/6 inch.

The half stem is a length equal to 1/2 inch.

The tail is a length equal to 1/3 inch.

The slanted tail is a length equal to 6/13 inch.

To stroke a number: Save the context. If the number is 1, stroke one. If the number is 2, stroke two. If the number is 3, stroke three. If the number is 4, stroke four. If the number is 5, stroke five. If the number is 6, stroke six. If the number is 7, stroke seven. If the number is 8, stroke eight. If the number is 9, stroke nine. Restore the context.

To stroke zero: Save the context. Stroke the half stem. Turn around. Move the half stem. Stroke the half stem. Restore the context.

To stroke one: Move the half stem. If the mirror flag is yes, turn right. If the mirror flag is no, turn left. Stroke the tail.

To stroke two: Move the small stem. If the mirror flag is yes, turn right. If the mirror flag is no, turn left. Stroke the tail.

To stroke three: Move the half stem. If the mirror flag is yes, turn right 3/8 of the way. If the mirror flag is no, turn left 3/8 of the way. Stroke the slanted tail.

To stroke four: Move the small stem. If the mirror flag is yes, turn right 1/8 of the way. If the mirror flag is no, turn left 1/8 of the way. Stroke the slanted tail.

To stroke five: Stroke 1. Stroke 4.

To stroke six: Move the half stem. If the mirror flag is yes, turn right; move the tail; turn right. If the mirror flag is no, turn left; move the tail; turn left. Stroke the tail.

To stroke seven: Stroke 1. Stroke 6.

To stroke eight: Stroke 2. Stroke 6.

To stroke nine: Stroke 1. Stroke 8.</lang>

Output:

https://commons.wikimedia.org/wiki/File:Cistercian_numerals.png

Raku

Handles 0 through 9999 only. No error trapping. If you feed it an unsupported number it will truncate to maximum 4 digits.

<lang perl6>my @line-segments = (0,0,0,100),

        (0,  0, 35,  0), (0,35, 35,35), (0,  0, 35,35), (0,35, 35,  0), ( 35, 0, 35, 35),
        (0,  0,-35,  0), (0,35,-35,35), (0,  0,-35,35), (0,35,-35,  0), (-35, 0,-35, 35),
        (0,100, 35,100), (0,65, 35,65), (0,100, 35,65), (0,65, 35,100), ( 35,65, 35,100),
        (0,100,-35,100), (0,65,-35,65), (0,100,-35,65), (0,65,-35,100), (-35,65,-35,100);

my @components = map {@line-segments[$_]}, |((0,5,10,15).map: -> $m {

     |((0,), (1,), (2,), (3,), (4,), (1,4), (5,), (1,5), (2,5), (1,2,5)).map: {$_ »+» $m}

});

my $out = 'Cistercian-raku.svg'.IO.open(:w);

$out.say: # header q|<svg width="1450" height="200" style="stroke:black;" version="1.1" xmlns="http://www.w3.org/2000/svg">

 <rect width="100%" height="100%" style="fill:white;" />|;

my $hs = 30; # horizontal spacing

for flat ^10, 20, 300, 4000, 5555, 6789, 9394, 7922 -> $cistercian {

   my $vs = 50; # vertical spacing
   # base vertical bar
   $out.say: @components[0].map: { qq|<line x1="{$_.[0] + $hs}" y1="{$_.[1] + $vs}" x2="{$_.[2] + $hs}" y2="{$_.[3] + $vs}"/>| };
   if $cistercian {
       my @oom = $cistercian.polymod(10 xx *); # orders of magnitude
       for @oom.kv -> $order, $value {
           next unless $value;
           last if $order > 3;
           # draw the component line segments
           $out.say: join "\n", @components[$order * 10 + $value].map: {
               qq|<line x1="{$_.[0] + $hs}" y1="{$_.[1] + $vs}" x2="{$_.[2] + $hs}" y2="{$_.[3] + $vs}" />|
           }
       }
   }
   # insert the decimal number below
   $out.say: qq|<text x="{$hs - 5}" y="170" style="fill:black;" >{$cistercian}</text>|;
   $hs += 85; # increment horizontal spacing

} $out.say: q|</svg>|; # footer</lang> See SVG image: (offsite link)

Wren

Library: Wren-fmt

This draws each Cistercian numeral on the terminal within a grid of 30 rows by 21 columns. The vertical line segment is drawn at column 10 (zero indexed) so there are 10 columns at either side. <lang ecmascript>import "/fmt" for Fmt

var n

var init = Fn.new {

   n = List.filled(30, null)
   for (i in 0..29) {
       n[i] = List.filled(21, " ")
       n[i][10] = "x"
   }

}

var draw // map contains recursive closures draw = {

   1: Fn.new { (11..20).each { |j| n[0][j] = "x" } },
   2: Fn.new { (11..20).each { |j| n[9][j] = "x" } },
   3: Fn.new { (0..9).each   { |i| n[i][i + 11] = "x" } },
   4: Fn.new { (0..9).each   { |i| n[i][20-i] = "x" } },
   5: Fn.new {
          draw[1].call()
          draw[4].call()
      },
   6: Fn.new { (0..9).each   { |i| n[i][20] = "x" } },
   7: Fn.new {
          draw[1].call()
          draw[6].call()
      },
   8: Fn.new {
          draw[2].call()
          draw[6].call()
      },
   9: Fn.new {
          draw[1].call()
          draw[2].call()
          draw[6].call()
      },
   10: Fn.new { (0..9).each { |j| n[0][j] = "x" } },
   20: Fn.new { (0..9).each { |j| n[9][j] = "x" } },
   30: Fn.new { (0..9).each { |i| n[i][9-i] = "x" } },
   40: Fn.new { (0..9).each { |i| n[i][i] = "x" } },
   50: Fn.new {
          draw[10].call()
          draw[40].call()
       },
   60: Fn.new { (0..9).each { |i| n[i][0] = "x" } },
   70: Fn.new {
          draw[10].call()
          draw[60].call()
      },
   80: Fn.new {
          draw[20].call()
          draw[60].call()
      },
   90: Fn.new {
          draw[10].call()
          draw[20].call()
          draw[60].call()
      },
   100: Fn.new { (11..20).each { |j| n[29][j] = "x" } },
   200: Fn.new { (11..20).each { |j| n[20][j] = "x" } },
   300: Fn.new { (20..29).each { |i| n[i][40-i] = "x" } },
   400: Fn.new { (20..29).each { |i| n[i][i-9] = "x" } },
   500: Fn.new {
          draw[100].call()
          draw[400].call()
      },
   600: Fn.new { (20..29).each { |i| n[i][20] = "x" } },
   700: Fn.new {
          draw[100].call()
          draw[600].call()
      },
   800: Fn.new {
          draw[200].call()
          draw[600].call()
      },
   900: Fn.new {
          draw[100].call()
          draw[200].call()
          draw[600].call()
      },
   1000: Fn.new { (0..9).each   { |j| n[29][j] = "x" } },
   2000: Fn.new { (0..9).each   { |j| n[20][j] = "x" } },
   3000: Fn.new { (20..29).each { |i| n[i][i-20] = "x" } },
   4000: Fn.new { (20..29).each { |i| n[i][29-i] = "x" } },
   5000: Fn.new {
          draw[1000].call()
          draw[4000].call()
      },
   6000: Fn.new { (20..29).each { |i| n[i][0] = "x" } },
   7000: Fn.new {
          draw[1000].call()
          draw[6000].call()
      },
   8000: Fn.new {
          draw[2000].call()
          draw[6000].call()
      },
   9000: Fn.new {
          draw[1000].call()
          draw[2000].call()
          draw[6000].call()
      }

}

var numbers = [0, 1, 20, 300, 4000, 5555, 6789, 9999] for (number in numbers) {

   init.call()
   System.print("%(number):")
   var thousands = (number/1000).floor
   number = number % 1000
   var hundreds  = (number/100).floor
   number = number % 100
   var tens = (number/10).floor
   var ones = number % 10
   if (thousands > 0) draw[thousands*1000].call()
   if (hundreds > 0) draw[hundreds*100].call()
   if (tens > 0) draw[tens*10].call()
   if (ones > 0) draw[ones].call()
   Fmt.mprint(n, 1, 0, "")
   System.print()

}</lang>

Output:
0:
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    

1:
                    x x x x x x x x x x x
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    

20:
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
x x x x x x x x x x x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    

300:
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                   x
                    x                 x  
                    x               x    
                    x             x      
                    x           x        
                    x         x          
                    x       x            
                    x     x              
                    x   x                
                    x x                  

4000:
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                  x x                    
                x   x                    
              x     x                    
            x       x                    
          x         x                    
        x           x                    
      x             x                    
    x               x                    
  x                 x                    
x                   x                    

5555:
x x x x x x x x x x x x x x x x x x x x x
  x                 x                 x  
    x               x               x    
      x             x             x      
        x           x           x        
          x         x         x          
            x       x       x            
              x     x     x              
                x   x   x                
                  x x x                  
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                  x x x                  
                x   x   x                
              x     x     x              
            x       x       x            
          x         x         x          
        x           x           x        
      x             x             x      
    x               x               x    
  x                 x                 x  
x x x x x x x x x x x x x x x x x x x x x

6789:
x                   x x x x x x x x x x x
x                   x                   x
x                   x                   x
x                   x                   x
x                   x                   x
x                   x                   x
x                   x                   x
x                   x                   x
x                   x                   x
x x x x x x x x x x x x x x x x x x x x x
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
x                   x                   x
x                   x                   x
x                   x                   x
x                   x                   x
x                   x                   x
x                   x                   x
x                   x                   x
x                   x                   x
x                   x                   x
x                   x x x x x x x x x x x

9999:
x x x x x x x x x x x x x x x x x x x x x
x                   x                   x
x                   x                   x
x                   x                   x
x                   x                   x
x                   x                   x
x                   x                   x
x                   x                   x
x                   x                   x
x x x x x x x x x x x x x x x x x x x x x
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
                    x                    
x x x x x x x x x x x x x x x x x x x x x
x                   x                   x
x                   x                   x
x                   x                   x
x                   x                   x
x                   x                   x
x                   x                   x
x                   x                   x
x                   x                   x
x x x x x x x x x x x x x x x x x x x x x