Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;INPUT: TRIANGLE_DEPTH, TRIANGLE_BASE, UNKNOWN
- alias GenerateTriangleBaseNumbers {
- var %depth $1
- var %base $2
- var %base2 $3
- var %maxNumber $calc($TriangleNumber(%base,%base) ^ %depth * (%base2 - 1))
- var %x 0
- ++ Generating Hybrid Triangle Base Numbers [Triangle Base %base $+ $chr(93) and [Base %base2 $+ $chr(93) in [Base 1] numbers 0 to %maxNumber
- ; ++ GENERATING NUMBERS 0 TO %maxNumber BASE %base SUB-BASE %base2
- -- $PrintToken($GenerateTriangleBaseHeader(%base,$calc(%depth + 1)),$asc(:))
- while %x <= %maxNumber {
- var %y $TranslateToTriangleBase(%x,%base,%base2,$calc(%depth + 1))
- ++ %y
- inc %x
- }
- ++ FINISHED GENERATING NUMBERS
- }
- alias -l -- {
- noop $1-
- }
- alias PrintToken {
- var %string $1
- var %token $2
- var %numTok $numtok(%string,%token)
- while %numtok {
- ++ $token(%string,- $+ %numtok,%token)
- dec %numTok
- }
- }
- alias -l ++ {
- echo @DEBUG $1-
- clipboard -an $1-
- }
- alias GenerateTriangleBaseHeader {
- var %x $chr(9)
- var %base $1
- var %depth $2
- var %header $+(NUMBER,%x,%x,REPLACE,%x,%x,%x,%x,TRIANGLE BASE NUMBER)
- var %body,%body2
- while %depth {
- var %y %base
- var %body %body $chr(91)
- var %body2 %body2 $chr(91)
- while %y {
- var %body $iif(%y == %base,%body $+ %y,%body %y)
- var %body2 $iif(%y == %base,%body2 $+ 1,%body2 1)
- dec %y
- }
- var %body %body $+ $chr(93)
- var %body2 %body2 $+ $chr(93)
- dec %depth
- }
- return $replace(%header,REPLACE,%body) $+ : $+ %x $+ %x $+ %body2
- }
- ;INPUT: TRIANGLE_BASE, TRIANGLE_POWER
- alias TriangleNumber {
- return $calc($1 * $$2 - ($$2 * ($$2 - 1) / 2))
- ;return $calc($1 * $$2 - ($$2 * ($$2 - 1) / 2) + 1)
- }
- ;INPUT: INTEGER, TRIANGLE_BASE
- alias IntegerToTriangleNumber {
- var %number $1
- var %base $2
- var %return
- while %base {
- if %number >= %base {
- var %return %return + %base
- dec %number %base
- }
- dec %base
- }
- return $right(%return,-1)
- }
- ;INPUT: INTEGER, TRIANGLE_BASE, UNKNOWN, DEPTH
- alias TriangleBaseTransformer {
- var %number $1
- var %base $2
- var %base2 $3
- var %depth $4
- var %numbers %depth
- var %x 1
- while %x <= %numbers {
- var %currentNumber $iif($token(%number,- $+ %x,124),$v1,0:0)
- var %num1 $token(%currentNumber,1,58)
- var %num2 $token(%currentNumber,2,58)
- var %return $chr(91) $+ $TriangleBaseDigitTransformer(%num1,%num2,%base,%base2,%depth) $+ $chr(93) %return
- inc %x
- }
- return %return
- }
- ;INPUT: TRIANGLE_DIGIT, BASE1_DIGIT(POSSIBLY A TRIANGLE_DIGIT)
- ; TRIANGLE_BASE, UNKNOWN
- alias TriangleBaseDigitTransformer {
- var %number1 $1
- var %number2 $2
- var %base $3
- var %base2 $4
- var %x %base
- var %return
- while %x {
- var %current1 $min($calc(%base2 - 1),$calc(%number1 / %x))
- dec %number1 $calc(%current1 * %x)
- hadd -m RETURNUBSET %x %current1
- dec %x
- }
- var %x 1
- while %x <= %base {
- var %current2 $min($calc(%base2 - 1),%number2)
- dec %number2 %current2
- hinc -m RETURNUBSET %x %current2
- inc %x
- }
- var %x 1
- while %x <= %base {
- var %return $hget(RETURNUBSET,%x) %return
- inc %x
- }
- hfree RETURNUBSET
- return %return
- }
- ;INPUT: INTEGER, TRIANGLE_POWER, UNKNOWN, DEPTH
- alias TranslateToTriangleBase {
- var %number $1
- var %base $2
- var %base2 $3
- var %depth $4
- var %number1 $TriangleBase(%number,%base,%base2)
- var %x $chr(9)
- return $+(%number,%x,%x,$TriangleBaseTransformer(%number1,%base,%base2,%depth),%x,%x,%x,%x,%number1)
- }
- ;INPUT: INTEGER, TRIANGLE_POWER, UNKNOWN
- alias TriangleBase {
- var %number $1
- var %base $iif($2,$2,3)
- var %base2 $iif($3,$3,2)
- var %return
- var %baseIterator %base - 1
- var %carry $floor($calc(%number / ($TriangleNumber(%base,%base) * (%base2 - 1))))
- var %number $calc(%number % ($TriangleNumber(%base,%base) * (%base2 - 1)))
- while %baseIterator {
- var %baseModulator $TriangleNumber(%base,%baseIterator) * $calc(%base2 - 1)
- if $floor($calc(%number / %baseModulator) > 0) {
- return $iif(%carry,$TriangleBaseMediator(%carry,%base,%base2) $+ $chr(124)) $+ %baseModulator $+ : $+ $calc(%number % %baseModulator)
- }
- dec %baseIterator
- }
- return $iif(%carry,$TriangleBaseMediator(%carry,%base,%base2) $+ $chr(124)) $+ 0: $+ %number
- }
- alias TriangleBaseMediator {
- return $TriangleBase($1,$2,$3)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement