AllBASIC
Welcome,
Guest
. Please
login
or
register
.
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
News:
Registration
DISABLED
. Send
support@allbasic.info
a request to join.
Home
Help
Search
Login
Register
AllBASIC
»
BASIC Developer & Support Resources
»
Scripting Languages
»
Game of Three
« previous
next »
Print
Pages: [
1
]
Author
Topic: Game of Three (Read 4363 times)
John
Forum Support / SB Dev
Posts: 3510
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
DECLARE
COMMAND
IFF
ALIAS
"iff"
LIB
"trial"
x = 31337357
WHILE
x > 1
a = x % 3
IF
a
THEN
a = IFF(a>1,1,-1)
PRINT
x,
" "
,a,
"\n"
x = (x + a) / 3
WEND
PRINT
x,
"\n"
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$
Logged
Mike Lobanovsky
Guest
Re: Game of Three
«
Reply #1 on:
November 05, 2015, 09:35:30 AM »
IFF ain't BASIC. IIF is.
Logged
John
Forum Support / SB Dev
Posts: 3510
Re: Game of Three
«
Reply #2 on:
November 05, 2015, 10:24:54 AM »
Polish notation.
Code: ScriptBasic
DECLARE
COMMAND
IIF
ALIAS
"iff"
LIB
"trial"
x = 31337357
WHILE
x > 1
a = x % 3
IF
a
THEN
a = IIF(a>1,1,-1)
PRINT
x,
" "
,a,
"\n"
x = (x + a) / 3
WEND
PRINT
x,
"\n"
Logged
Print
Pages: [
1
]
« previous
next »
AllBASIC
»
BASIC Developer & Support Resources
»
Scripting Languages
»
Game of Three