BASIC (ZX Spectrum), score 244 (new score 247) [is this cheating?]
Snippet 1:
2356 PRINT PEEK (PEEK 23635+256*PEEK 23636+2)+256*PEEK (PEEK 23635+256*PEEK 23636+3)-56-66
Snippet 2: :
Snippet 3: REM
Snippets 4-244: Single-character snippets, using all characters not in snippets 1, 2 and 3.
Explanation
Characters
On Spectrum, PRINT
is a single character (code 245). The snippet 1 uses 11 different characters: 2
, 3
, 5
, 6
, +
, -
, *
, (
, )
, PRINT
and PEEK
What you see as spaces are a part of characters PRINT
and PEEK
, so the space itself hasn't been used. I decided to give the line number 2356 because these are the only digits present in the code.
Characters 13 and 14 are not allowed. That means there are 243 characters left for snippets 2-244, starting with :
and REM
to avoid the code that would produce error or do anything else.
How it works
This is why I'm not sure whether this answer is by the book.
23635 is the memory location for 16-bit system variable PROG, stored as LH. (The value is usually 23755. But apart from wrong result if it happens not to be the case, using this number directly, even though it would shorten the code, would cost me extra digit characters.) The value of PROG is the memory location where the program itself is stored. The first two bytes are the line number stored as HL, the following two bytes are the length of the line stored as LH. That's how the program looks up its own line's length, so something appropriate needs to be subtracted
Saving characters
Considering how numbers are stored, the line could have ended with -114 so that snippet 1 would produce 1. But I didn't want to use extra digits, so I instead took away two 2-digit numbers, which then had to add up to 122; 56 and 66 did nicely.
The code is a bit ugly with all nesting and calculating value of PROG (PEEK 23635+256*PEEK 23636
) twice. But if I stored it and then used the stored value, it would cost extra characters / snippets - the line could start like
2356 LET p=PEEK 23635+256*PEEK 23636: PRINT PEEK (s+2)...
which would use 4 additional characters: LET
, p
, =
and :
.
Maybe I'll engineer this so that all numbers are calculated from numbers that use only 1 digit and gain 3 snippets.
EDIT:
Here is the new snippet 1 (that's how a long single line gets wrap-displayed on the Spectrum, so if you want to test the code , that will help you see that you typed it correctly):
1111 PRINT +PEEK (PEEK (11111+11
111+1111+(1+1+1)*(111-11)+1+1)+(
111+111+11+11+11+1)*PEEK (11111+
11111+1111+(1+1+1)*(111+1-11))+1
+1)+(111+111+11+11+11+1)*PEEK (P
EEK (11111+11111+1111+(1+1+1)*(1
11-11)+1+1)+(111+111+11+11+11+1)
*PEEK (11111+11111+1111+(1+1+1)*
(111+1-11))+1+1+1)-111-111-111-1
11-111-111
I could gain another snippet by avoiding the +
and just make do with -
. I'm not going to try it, this was enough of an ordeal.