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.
Here's a puzzle game. I call it Reverse the List of Integers
151–160 of 188 posts
Re: Here's a puzzle game. I call it Reverse the List of Integers
#152Earlier 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].
Re: Here's a puzzle game. I call it Reverse the List of Integers
#153Re: Here's a puzzle game. I call it Reverse the List of Integers
#154I 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.
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
#155Re: Here's a puzzle game. I call it Reverse the List of Integers
#156Re: Here's a puzzle game. I call it Reverse the List of Integers
#157Re: Here's a puzzle game. I call it Reverse the List of Integers
#158I 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
Re: Here's a puzzle game. I call it Reverse the List of Integers
#159Here's a gist in Prolog that I believe solves this puzzle: https://gist.github.com/deosjr/7314659509333ee2ad67dbf276e8d...
:- 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.
Re: Here's a puzzle game. I call it Reverse the List of Integers
#160My 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.