Advertisement
Guest User

Untitled

a guest
Jun 2nd, 2017
657
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
REBOL 5.51 KB | None | 0 0
  1. REBOL[]
  2.  
  3. ;** R3 only
  4. ;** 264 chars, works with the unicorn example.
  5.  
  6. s: {
  7.                         64          
  8.                         63              
  9.  
  10.  
  11.  
  12.                     62 61                            
  13.                1  65                                  
  14.                  66    57 58                              
  15.                2      56  59               45                
  16.                    67  55                  46              
  17.              3                               44          
  18.                          54  60            47              
  19.                           53 52   49      48              
  20.              4                51 50       43            
  21.  
  22.            5                                42              
  23.                                             41              
  24.            6              23                                
  25.                           22 25  26       40              
  26.                       20 21 24            34                
  27.               7 13 12                    33                    
  28.                     19              27  32                    
  29.                 14                        35              
  30.            8   15                                          
  31.                 16                                        
  32.                                    39                        
  33.                 17  18         28  31 36                  
  34.                9                     38                      
  35.                 10 11          29  30 37              
  36. }
  37.  
  38. _:[skip]i: 1 r:[(z: n + 77 // 81)z _ _ then[v reject | r | _ p:(w/(index? p): pick"/|\-"n)end]|]
  39. parse s[any[79[and lf insert" "| _]_](w: copy s):w any[" "| lf | end | p:(p/1:"+" p/2:" ")_]
  40. 99[:s(v: load ajoin[{" }++ i{ "|" }i{ "}]n: 0)to v 0 4[(++ n)and r]]]print w
  41.  
  42. halt
  43.  
  44.                                                                                
  45.                         +                                                      
  46.                        /+                                                      
  47.                       //                                                      
  48.                      //                                                        
  49.                     //                                                        
  50.                    /+--+                                                      
  51.                +  +     \                                                      
  52.                | +     +-\+                                                    
  53.                +  \   +   \                +                                  
  54.               /    +   +   \               +\                                  
  55.              +          \   \              | +                                
  56.              |           +   +             +/                                  
  57.              |            +--+    +-------+/                                  
  58.              +                +--+        +                                    
  59.             /                              \                                  
  60.            +                                +                                  
  61.            |                                +                                  
  62.            +              +                /                                  
  63.             \             +\ +---+        +                                    
  64.              \        +--+  +     \      /+                                    
  65.               + +--+ /             \    /+|                                    
  66.              /  |  |+               +  /+ |                                    
  67.             /   +  ||              /  //  +                                    
  68.            +   +   ||             /  //  /                                    
  69.             \   +  ||            /  //  /                                      
  70.              \  |  ||           /  +/  /                                      
  71.               \ +---+          +   +\ +                                        
  72.                +   |           |   | +|                                        
  73.                 +--+           +---+  +                                        
  74.  
  75.  
  76.  
  77. ;******************************
  78. ;***  Decipher the code     ***
  79.  
  80. ;** shortcut for the 'skip rule
  81.  
  82. _:[skip]
  83.  
  84. ;** Counter, 1 to 99
  85.  
  86. i: 1
  87.  
  88. ;** Create the r rule to draw a line.
  89. ;** It's a recursive rule, where a failure means a success.
  90. ;** It traverses the path of a line (dot per dot) recursivly.
  91. ;** If the current dot matchs the expected end point, the whole rule is rejected.
  92. ;** During the fall back the path is traveled upside down and the line is drawed in the output.
  93.  
  94. r:[(z: n + 77 // 81)z _ _ then[v reject | r | _ p:(w/(index? p): pick"/|\-"n)end]|]
  95.  
  96. ;** Start to parse the s text
  97.  
  98. parse s[
  99.  
  100.     ;** Enlarge each line to 79 characters, plus a line feed (lf)
  101.    
  102.     any[79[and lf insert" "| _]_]
  103.    
  104.     ;** w = output text
  105.    
  106.     (w: copy s)
  107.    
  108.     ;** clean the output text (replace all numbers by string "+ ")
  109.    
  110.     :w any[" "| lf | end | p:(p/1:"+" p/2:" ")_]
  111.  
  112.  
  113.     ;** loop 99 times
  114.     99[
  115.         ;** Position to the beginning of the source text
  116.         :s
  117.        
  118.         ;** Create the v rule depending of i. (i = 1 --> v = [" 1 " | " 2 "])
  119.         (v: load ajoin[{" }++ i{ "|" }i{ "}]n: 0)
  120.        
  121.         ;** Position to the first matching number (" 1 " or " 2 ")
  122.         to v
  123.        
  124.         ;** 4 attempts to draw a line with n =(1, 2, 3, 4)
  125.         ;** left diagonal "/", vertical "|", right diagonal "\", horizontal "-"
  126.         0 4[(++ n)and r]
  127.    
  128.     ]
  129. ]
  130. print w
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement