Can This Program Be Simplified Or Improved?

Anything Sinclair ZX Basic related; history, development, tips - differences between BASIC on the ZX80 and ZX81
Post Reply
MrVertigo
Posts: 105
Joined: Fri May 27, 2022 9:06 pm

Can This Program Be Simplified Or Improved?

Post by MrVertigo »

I wrote this short routine in ZX81 BASIC to convert a decimal number into a Factoradic number (base ...720,120,24,6,3,2,1,0)

Can it be shortened or improved?

I’ve separated the different functions with REM lines.

Code: Select all

   
    10 LET C=1
    20 LET X=1
    30 LET F=0
    40 PRINT "INPUT DECIMAL"
    50 INPUT A
    60  REM
    70  REM
   100 LET X=X+1
   110 LET C=C*X
   120 IF C<A THEN GOTO 100
   125  REM
   126  REM
   127 IF C=A THEN LET F=1
   130 IF C=A THEN GOTO 1000
   140 LET C=C/X
   150 IF A>=C THEN LET F=F+1
   160 IF A>=C THEN LET A=A-C
   170 IF A=0 THEN GOTO 1000
   180 IF A>=C THEN GOTO 150
   190  REM
   200  REM
   300 PRINT F
   310 LET F=0
   320 LET X=X-1
   330 GOTO 140
  1000 PRINT F
  1005 IF A<>C THEN LET X=X-1
  1010 FOR N=1 TO X
  1020 PRINT 0
  1030 NEXT N
Using division instead of looped subtraction resulted in floating point number problems, that’s why I’ve had to use the subtraction loop.
Post Reply