• Autum Challenge: Short Deadfish Numbers

    From Mild Shock@bursejan@gmail.com to comp.lang.prolog on Wed Oct 4 12:22:21 2023
    From Newsgroup: comp.lang.prolog

    Solve this problem:

    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 Deadfish
    code to display the number. It must work for any integer from 0 to 255.

    https://codegolf.stackexchange.com/questions/40124/short-deadfish-numbers/

    Twist, don't write the solution in Prolog. But in your favorite Prolog
    with your favorite state extension. For example Mecury states via
    (!)/1 or some other Prolog language extension that helps

    dealing with state.
    --- Synchronet 3.20a-Linux NewsLink 1.114
  • From Mild Shock@bursejan@gmail.com to comp.lang.prolog on Mon Oct 9 15:52:21 2023
    From Newsgroup: comp.lang.prolog

    Naive solution with CLP(FD), and without "o" operator.
    Why would one use CLP(FD) ? Well you can easily experiment
    with forward search and backward search:

    /* forward search, first the op/3 and then recursive */
    deadfish_(X0, X) -->
    { ops(Op, X0, X1) },
    [Op],
    deadfish_(X1, X).

    /* backward search, first recursive and then op/3 */
    deadfish2_(X0, X) -->
    [Op],
    deadfish2_(X1, X),
    { ops(Op, X0, X1) }.

    Which one is faster? Try yourself:

    /* GNU Prolog, 1.5.0 */
    ?- between(1,90,N), once(deadfish(N,_)), fail; true.
    (11703 ms) yes

    ?- between(1,90,N), once(deadfish2(N,_)), fail; true.
    (219 ms) yes

    But still waiting for more solutions that use tabling!

    Mild Shock schrieb am Mittwoch, 4. Oktober 2023 um 21:22:23 UTC+2:
    Solve this problem:

    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 Deadfish
    code to display the number. It must work for any integer from 0 to 255.

    https://codegolf.stackexchange.com/questions/40124/short-deadfish-numbers/

    Twist, don't write the solution in Prolog. But in your favorite Prolog
    with your favorite state extension. For example Mecury states via
    (!)/1 or some other Prolog language extension that helps

    dealing with state.
    --- Synchronet 3.20a-Linux NewsLink 1.114