More Code Golf

Anything Sinclair ZX Basic related; history, development, tips - differences between BASIC on the ZX80 and ZX81
Post Reply
Shaun_B
Posts: 451
Joined: Wed Apr 22, 2009 10:22 am

More Code Golf

Post by Shaun_B » Fri Feb 17, 2017 10:46 pm

Okay, it's not exactly code, here's another submission I made to Stack Exchange:

Code: Select all

 1 LET A$=""
 2 LET A=38
 3 LET A$=A$+CHR$ A
 4 LET A=A+1
 5 GOTO 3+((A=64)*3)
 6 PRINT A$
 7 LET A$=A$(2 TO)+A$(1)
 8 LET A=(A$(1)="V")
 9 IF A=1 THEN SCROLL
10 GOTO 6

User avatar
XavSnap
Posts: 757
Joined: Sat May 10, 2008 4:23 pm

Re: More Code Golf

Post by XavSnap » Fri Feb 17, 2017 11:44 pm

Code: Select all

1 LET A$=""
2 LET A=38
3 LET A$=A$+CHR$ A
4 LET A=A+1
5 GOTO 3+((A=64)*3)
6 PRINT A$
7 LET A$=A$(2 TO)+A$(1)
8 IF (A$(1)>"V")=1 THEN SCROLL
10 GOTO 6
Faster...
... Sorry!
:oops:
Less lines, more faster! :mrgreen:

User avatar
XavSnap
Posts: 757
Joined: Sat May 10, 2008 4:23 pm

Re: More Code Golf

Post by XavSnap » Sat Feb 18, 2017 12:21 am

Code: Select all

2 LET A=38
3 LET A$=A$+CHR$ A
4 LET A=A+1
5 GOTO 3+((A=64)*3)
> 27 seconds
3 line repeated (2-4-5)

Code: Select all

3 FOR A=38 TO 64
4 LET A$=A$+CHR$ A
5 NEXT A
> 23 seconds
Only 2 redundant lines (4&5)
Is better...
Less memory used too.
Last edited by XavSnap on Sat Feb 18, 2017 7:51 pm, edited 1 time in total.

Shaun_B
Posts: 451
Joined: Wed Apr 22, 2009 10:22 am

Re: More Code Golf

Post by Shaun_B » Sat Feb 18, 2017 8:51 am

Thanks, I've amended my entry to include your codes.

Code Golf is good fun especially on technologies with limited languages like the ZX81.

Regards,

Shaun.

Post Reply