Author Topic: Game of Three  (Read 2652 times)

Offline John

  • Forum Support / SB Dev
  • Posts: 2793
    • 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: Script BASIC
  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$

Offline Mike Lobanovsky

  • (re)TIRED
  • BASIC Developer
  • Posts: 281
Re: Game of Three
« Reply #1 on: November 05, 2015, 09:35:30 AM »
IFF ain't BASIC. IIF is. :P

:D
Mike
____________________________________________________________________
(3.6GHz Intel Core i5, 16GB RAM / nVidia GTX 1060Ti , 6GB VRAM / x64 Win7 Ult.)

Offline John

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

Code: Script BASIC
  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.