Replies: 3 comments
-
Naive version. It doesn't create the shortest code because it just outputs one time at the end:
|
Beta Was this translation helpful? Give feedback.
-
My current version. It does the shortest Deadfish program. It also does some checks to reduce the number of iterations. I use
|
Beta Was this translation helpful? Give feedback.
-
Very interesting, thank you a lot for sharing this! One small thing I noticed regarding: restrict_code(Code, d) :- member(Op, "sod"), append(_, [Op], Code). With restrict_code(Code, d) :- append(_, [Op], Code), member(Op, "sod"). In this way, the last element As a small test, I get: ?- length(Ls, 1_000_000), time((restrict_code(Ls,d),false)). % CPU time: 1.503s false. vs.: ?- length(Ls, 1_000_000), time((restrict_code(Ls,d),false)). % CPU time: 0.504s false. So, indeed the expected speedup of roughly 3 times. Chances are it won't matter much in this use case, but it's maybe still worth considering. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I came across this challenge
I copy-paste:
Deadfish is one of the best known non Turing-complete programming languages.
It has only one accumulator (which starts at 0) to store data, and only four commands:
i - Increment the accumulator
s - Square the accumulator
d - Decrement the accumulator
o - Output the accumulator
Create a program that will input a number and output the shortest Deadfish
code to display the number. It must work for any integer from 0 to 255.
On the answers I'll post my answer, which I surely know some people would improve!
Beta Was this translation helpful? Give feedback.
All reactions