Advertisement
imk0tter

Triangle Base Generator

Jul 9th, 2021
1,940
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
mIRC 4.36 KB | None | 0 0
  1. ;INPUT: TRIANGLE_DEPTH, TRIANGLE_BASE, UNKNOWN
  2. alias GenerateTriangleBaseNumbers {
  3.   var %depth $1
  4.   var %base $2
  5.   var %base2 $3
  6.  
  7.   var %maxNumber $calc($TriangleNumber(%base,%base) ^ %depth * (%base2 - 1))
  8.  
  9.   var %x 0
  10.   ++ Generating Hybrid Triangle Base Numbers [Triangle Base %base $+ $chr(93) and [Base %base2 $+ $chr(93) in [Base 1] numbers 0 to %maxNumber
  11.   ; ++ GENERATING NUMBERS 0 TO %maxNumber BASE %base SUB-BASE %base2
  12.   -- $PrintToken($GenerateTriangleBaseHeader(%base,$calc(%depth + 1)),$asc(:))
  13.   while %x <= %maxNumber {
  14.     var %y $TranslateToTriangleBase(%x,%base,%base2,$calc(%depth + 1))
  15.     ++ %y
  16.     inc %x
  17.   }
  18.   ++ FINISHED GENERATING NUMBERS
  19. }
  20. alias -l -- {
  21.   noop $1-
  22. }
  23. alias PrintToken {
  24.   var %string $1
  25.   var %token $2
  26.  
  27.   var %numTok $numtok(%string,%token)
  28.  
  29.   while %numtok {
  30.     ++ $token(%string,- $+ %numtok,%token)
  31.     dec %numTok
  32.   }
  33. }
  34. alias -l ++ {
  35.   echo @DEBUG $1-
  36.   clipboard -an $1-
  37. }
  38. alias GenerateTriangleBaseHeader {
  39.   var %x $chr(9)
  40.   var %base $1
  41.   var %depth $2
  42.   var %header $+(NUMBER,%x,%x,REPLACE,%x,%x,%x,%x,TRIANGLE BASE NUMBER)
  43.   var %body,%body2
  44.   while %depth {
  45.     var %y %base
  46.     var %body %body $chr(91)
  47.     var %body2 %body2 $chr(91)
  48.     while %y {
  49.       var %body $iif(%y == %base,%body $+ %y,%body %y)
  50.       var %body2 $iif(%y == %base,%body2 $+ 1,%body2 1)
  51.       dec %y
  52.     }
  53.     var %body %body $+ $chr(93)
  54.     var %body2 %body2 $+ $chr(93)
  55.     dec %depth
  56.   }
  57.   return $replace(%header,REPLACE,%body) $+ : $+ %x $+ %x $+ %body2
  58. }
  59.  
  60. ;INPUT: TRIANGLE_BASE, TRIANGLE_POWER
  61. alias TriangleNumber {
  62.   return $calc($1 * $$2 - ($$2 * ($$2 - 1) / 2))
  63.   ;return $calc($1 * $$2 - ($$2 * ($$2 - 1) / 2) + 1)
  64. }
  65.  
  66. ;INPUT: INTEGER, TRIANGLE_BASE
  67. alias IntegerToTriangleNumber {
  68.   var %number $1
  69.   var %base $2
  70.   var %return
  71.   while %base {
  72.     if %number >= %base {
  73.       var %return %return + %base
  74.       dec %number %base
  75.     }
  76.     dec %base
  77.   }
  78.   return $right(%return,-1)
  79. }
  80.  
  81. ;INPUT: INTEGER, TRIANGLE_BASE, UNKNOWN, DEPTH
  82. alias TriangleBaseTransformer {
  83.   var %number $1
  84.   var %base $2
  85.   var %base2 $3
  86.  
  87.   var %depth $4
  88.  
  89.   var %numbers %depth
  90.  
  91.   var %x 1
  92.  
  93.   while %x <= %numbers {
  94.     var %currentNumber $iif($token(%number,- $+ %x,124),$v1,0:0)
  95.  
  96.     var %num1 $token(%currentNumber,1,58)
  97.     var %num2 $token(%currentNumber,2,58)
  98.  
  99.     var %return $chr(91) $+ $TriangleBaseDigitTransformer(%num1,%num2,%base,%base2,%depth) $+ $chr(93) %return
  100.     inc %x
  101.   }
  102.   return %return
  103. }
  104.  
  105. ;INPUT: TRIANGLE_DIGIT, BASE1_DIGIT(POSSIBLY A TRIANGLE_DIGIT)
  106. ;       TRIANGLE_BASE, UNKNOWN
  107. alias TriangleBaseDigitTransformer {
  108.   var %number1 $1
  109.   var %number2 $2
  110.  
  111.   var %base $3
  112.   var %base2 $4
  113.  
  114.   var %x %base
  115.  
  116.   var %return
  117.  
  118.   while %x {
  119.     var %current1 $min($calc(%base2 - 1),$calc(%number1 / %x))
  120.     dec %number1 $calc(%current1 * %x)
  121.  
  122.     hadd -m RETURNUBSET %x %current1
  123.     dec %x
  124.   }
  125.   var %x 1
  126.   while %x <= %base {
  127.     var %current2 $min($calc(%base2 - 1),%number2)
  128.     dec %number2 %current2
  129.  
  130.     hinc -m RETURNUBSET %x %current2
  131.     inc %x
  132.   }
  133.  
  134.   var %x 1
  135.  
  136.   while %x <= %base {
  137.     var %return $hget(RETURNUBSET,%x) %return
  138.     inc %x
  139.   }
  140.   hfree RETURNUBSET
  141.   return %return
  142. }
  143. ;INPUT: INTEGER, TRIANGLE_POWER, UNKNOWN, DEPTH
  144. alias TranslateToTriangleBase {
  145.   var %number $1
  146.  
  147.   var %base $2
  148.   var %base2 $3
  149.  
  150.   var %depth $4
  151.  
  152.   var %number1 $TriangleBase(%number,%base,%base2)
  153.  
  154.   var %x $chr(9)
  155.  
  156.   return $+(%number,%x,%x,$TriangleBaseTransformer(%number1,%base,%base2,%depth),%x,%x,%x,%x,%number1)
  157. }
  158.  
  159. ;INPUT: INTEGER, TRIANGLE_POWER, UNKNOWN
  160. alias TriangleBase {
  161.   var %number $1
  162.  
  163.   var %base $iif($2,$2,3)
  164.   var %base2 $iif($3,$3,2)
  165.  
  166.   var %return
  167.  
  168.   var %baseIterator %base - 1
  169.  
  170.   var %carry $floor($calc(%number / ($TriangleNumber(%base,%base) * (%base2 - 1))))
  171.   var %number $calc(%number % ($TriangleNumber(%base,%base) * (%base2 - 1)))
  172.  
  173.   while %baseIterator {
  174.     var %baseModulator $TriangleNumber(%base,%baseIterator) * $calc(%base2 - 1)
  175.     if $floor($calc(%number / %baseModulator) > 0) {
  176.       return $iif(%carry,$TriangleBaseMediator(%carry,%base,%base2) $+ $chr(124)) $+ %baseModulator $+ : $+ $calc(%number % %baseModulator)
  177.     }
  178.     dec %baseIterator
  179.   }
  180.   return $iif(%carry,$TriangleBaseMediator(%carry,%base,%base2) $+ $chr(124)) $+ 0: $+ %number
  181. }
  182.  
  183. alias TriangleBaseMediator {
  184.   return $TriangleBase($1,$2,$3)
  185. }
  186.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement