Author Topic: Game of Three  (Read 4363 times)

Offline John

  • Forum Support / SB Dev
  • Posts: 3510
    • ScriptBasic Open Source Project
Game of Three
« on: November 03, 2015, 09:35:36 PM »
Here is the Script BASIC version. It's 167 bytes in size but executes in .005 seconds.

Code: ScriptBasic
  1. DECLARE COMMAND IFF ALIAS "iff" LIB "trial"
  2. x = 31337357
  3. WHILE x > 1
  4.   a = x % 3
  5.   IF a THEN a = IFF(a>1,1,-1)
  6.   PRINT x," ",a,"\n"
  7.   x = (x + a) / 3
  8. WEND
  9. PRINT x,"\n"
  10.  


jrs@laptop:~/sb/sb22/test$ time scriba got.sb
31337357 1
10445786 1
3481929 0
1160643 0
386881 -1
128960 1
42987 0
14329 -1
4776 0
1592 1
531 0
177 0
59 1
20 1
7 -1
2 1
1

real   0m0.005s
user   0m0.004s
sys   0m0.000s
jrs@laptop:~/sb/sb22/test$ ls -l got.sb
-rw-rw-r-- 1 jrs jrs 167 Nov  3 21:28 got.sb
jrs@laptop:~/sb/sb22/test$

Mike Lobanovsky

  • Guest
Re: Game of Three
« Reply #1 on: November 05, 2015, 09:35:30 AM »
IFF ain't BASIC. IIF is. :P

:D

Offline John

  • Forum Support / SB Dev
  • Posts: 3510
    • ScriptBasic Open Source Project
Re: Game of Three
« Reply #2 on: November 05, 2015, 10:24:54 AM »
Polish notation.  ;D

Code: ScriptBasic
  1. DECLARE COMMAND IIF ALIAS "iff" LIB "trial"
  2. x = 31337357
  3. WHILE x > 1
  4.   a = x % 3
  5.   IF a THEN a = IIF(a>1,1,-1)
  6.   PRINT x," ",a,"\n"
  7.   x = (x + a) / 3
  8. WEND
  9. PRINT x,"\n"
  10.