Live data from Hacker News

Here's a puzzle game. I call it Reverse the List of Integers

mathstodon.xyz

151–160 of 188 posts

Re: Here's a puzzle game. I call it Reverse the List of Integers

#151
post #149
post #68

Earlier quoted context omitted.

Interesting, it appears I've encountered an impossible combination of numbers: [2, 5, 1, 3] The only possible move is to add 1 and 3. Can't ever split a 2 as that would result in [1, 1], can't split the 5 because that would be [4, 1] or [3, 2], can't split the 3, as that would be [2, 1] or [1, 2], can't add the 5 to anything as that would be larger than 5.

I was given [1,2] in the second run. Even easier to see it's impossible.

Yeah the generation is very simple, 2-4 random numbers between 1 and 9 inclusive. Definitely gives impossible puzzles sometimes (because I don't know a general algorithm for generating possible ones only).

Re: Here's a puzzle game. I call it Reverse the List of Integers

#152
post #47

Earlier quoted context omitted.

Fun implementation! There's currently a bug that allows the same number to appear twice after a combination step (I was able to perform 2,3,7,5->5,7,5)

Ran into this as well: I did [8, 1, 4] -> [5, 3, 1, 4] -> [5, 3, 5].

Should be fixed, thanks for the report.

Re: Here's a puzzle game. I call it Reverse the List of Integers

#153

I thought the game was cool so I built a little version of it here: https://blaise.gg/number_game/index.html

I think it would be more fun if you only displayed problems that are solvable.

Yeah, I would but finding such puzzles is kind of hard. Might look into it this weekend

Re: Here's a puzzle game. I call it Reverse the List of Integers

#154

I thought the game was cool so I built a little version of it here: https://blaise.gg/number_game/index.html

Would be nice if you allowed users to define their own puzzle. I had to set a break point at the right location and call startNew([..my array]) to do so.

Added, you can use ?numbers=1~2~3 to specify your puzzle.

Like this:

https://blaise.gg/number_game/index.html?numbers=1%7E4%7E6%7...

Re: Here's a puzzle game. I call it Reverse the List of Integers

#155

I thought the game was cool so I built a little version of it here: https://blaise.gg/number_game/index.html

This is neat, but your implementation does seem to allow duplicates sometimes

Should be fixed now, sorry for trouble.

Re: Here's a puzzle game. I call it Reverse the List of Integers

#156

I thought the game was cool so I built a little version of it here: https://blaise.gg/number_game/index.html

Nice. It does let me make the same integer twice though.

Should be fixed now, sorry for trouble.

Re: Here's a puzzle game. I call it Reverse the List of Integers

#157
post #120

Earlier quoted context omitted.

I think it's indirectly indicated by using the word "split".

When I split an atom, The pieces go pretty far apart

And when you split plasticine it doesn't. Do numbers have tightly bound huge amounts of energy inside them?

Re: Here's a puzzle game. I call it Reverse the List of Integers

#158

I thought the game was cool so I built a little version of it here: https://blaise.gg/number_game/index.html

Cool! Though I say the rule about repeated numbers is a bummer. I can see things might get easier (also it might be a more procedurally easy problem to solve) if this is allowed Basically I don't think it's a "productive" complication

Without that rule, you could decompose everything into 1's, and then recompose from there. Not the most efficient solution, but a boring one that always exists.

Re: Here's a puzzle game. I call it Reverse the List of Integers

#159
post #86

Here's a gist in Prolog that I believe solves this puzzle: https://gist.github.com/deosjr/7314659509333ee2ad67dbf276e8d...

Here's my Prolog code which solves (small inputs) of the puzzle, taking the core grammar of moves//3 from the Water Jug solution in Markus Triska's Power of Prolog video "Sparrows on Eagles: Delegate your work to Prolog!"[1] (I couldn't have written that style myself from scratch):

    :- use_module(library(dif)). % Sound inequality
    :- table split/2, merge/3, moves//3.
    
    % Replace one number H from a list with
    % two A and B which sum to that number.
    split([], []).
    split([H|T], [A,B|T]) :-
        between(1,H, A),
        between(1,H, B),
        dif(A,B),
        H is A+B.
    split([H|T], [H|T2]) :-
        split(T, T2).
    
    % Merge two adjacent numbers A and B from a list by
    % summing into H, unless that would exceed list Max.
    merge([], _, []).
    merge([H|T], Max, [H|T2]) :-
        merge(T, Max, T2).
    merge([A,B|T], Max, [H|T]) :-
        H is A + B,
        H = { member(Target, S0) }.
    moves(S0, Max, Target) --> [Ns],
        { select(Ns0, S0, S),
          (split(Ns0, Ns)
          ; merge(Ns0, Max, Ns)),
          sort(Ns, NsSet), same_length(Ns, NsSet) },
        moves([Ns|S], Max, Target).
    
    
    solve(S0, [S0|Moves]) :-
        max_list(S0, Max),
        reverse(S0, Target),
        phrase(moves([S0], Max, Target), Moves).
        
e.g. with the query:

    ?- between(1, 20, MoveCount),
       length(Moves, MoveCount),
       solve([5,1,20], Moves).
Answer:

    Moves = [[7, 5, 3], [7, 1, 4, 3], [2, 5, 1, 4, 3], [2, 6, 4, 3], [2, 1, 5, 4, 3], [2, 1, 5, 7], [3, 5, 7]],
    MoveCount = 7
It will run in https://swish.swi-prolog.org/ clicking the 'Empty' then 'Program' and pasting the code in, querying (without the ?- and trailing .) in the lower right.

Taking the technique from the video; the query uses length/2 to lengthen the list of answer moves one at a time before the answer is sought, this code does iterative deepening and will find the shortest sequence of moves first.

[1] https://www.youtube.com/watch?v=vdabv9EkYrY

Re: Here's a puzzle game. I call it Reverse the List of Integers

#160

My first reaction to this was, "neat coding question for interviews". I started to try to solve it for a few seconds, then thought of when I've asked coding questions. Invariably starting by saying "The goal is to see how you approach and work through the problem, and less so whether you come up with the optimal solution". Then I thought, what if the interviewer and interviewee tackled the problem together, both comi…

what if we just interviewed people.

Why is this not an interview? I had very similar problems even on an interview to get in a math-oriented high school.
Post reply on HN