Scratch is a visual programming language, meant for teaching kids how to program.
It's completely absent from this site, which, I think, is worth fixing.
I have no specific challenge in mind.
A scratch program is not made of text, but of visual building blocks, that represent actions, control structures and expressions. Therefore, the code-golf metric isn't trivial - we should decide what to count.
Suggested counting:
- Each block is 1 point.
- Each constant is 1 point per character (or per digit).
- Each operator is 1 point.
- Each variable used in an expression is 1 point.
- If initialized lists are used, each value is counted as a constant.
Example program:
Calculated cost:
When flag clicked
- 1ask <n=> and wait
- 3 (block + 2-char constant)set n to <answer>
- 2 (block + variableanswer
).set i to 0
- 2 (block + constant).repeat until <n=1>
- 4 (block, operator=
, variable, constant).if <n mod 2 = 0>
- 6 (block, operators=
andmod
, variable, 2 constants).set n to n/2
- 4 (block, operator, variable, constant).set n to 3*n+1
- 6 (block, operators*
and+
, variable, 2 constants).change i by 1
- 2 (block, constant).say i
- 2 (block, variable).
Total score: 32 points.
Another way, which Peter Talyor suggested, is to find a textual program representation Scratch uses itself.
I found one thing, in the Scratch web interface, but I don't really like it. You need to save the project, rename the file to ZIP, and extract a JSON file. A part of it is the script, which looks like this:
["whenGreenFlag"],
["doAsk", "n="],
["setVar:to:", "i", 0],
["setVar:to:", "n", ["answer"]],
["doUntil",
["=", ["readVariable", "n"], "1"],
[["doIfElse",
["=", ["%", ["readVariable", "n"], 2], "0"],
[["setVar:to:", "n", ["\/", ["readVariable", "n"], 2]]],
[["setVar:to:", "n", ["+", ["*", 3, ["readVariable", "n"]], 1]]]],
["changeVar:by:", "i", 1]]],
["say:", ["readVariable", "i"]]]]
With this, we can simply count the length in characters (better ignore whitespace). However, the resulting length is strange. For example, variable access becomes very expensive. Also, the process of extracting this is annoying.
Also, we may want a more convenient format to post answers, instead of a screenshot.
malloc
bym
etc. I find the idea of Scratch very interesting, but I think it's just not applicable when the shortest code is expected. It's still valid in other contests. \$\endgroup\$show
block), we really have to fix measuring this characteristic of Scratch correctly but not unfairly. \$\endgroup\$