Live data from Hacker News

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

mathstodon.xyz

161–170 of 188 posts

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

#161

Earlier quoted context omitted.

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.

Ok so how about allowing only non contiguous repeated numbers

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

#162
post #149

Earlier quoted context omitted.

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).

If you only have numbers up to 9 an exhaustive search shouldn't be too bad (should be ~9! states if you memoize), you could implement a solver in Javascript and see whether a solution can be found before you give it to the user.

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

#163
post #146

Neat little problem! You could do SAT-solvers and stuff, but it's also obviously a graph search problem: each state is a vertex, each edge is an operation that leads to another vertex. So, obviously: Dijkstra works (or really just BFS, since the edges are unweighted), but not the fastest in the world. The fun one to play with would be A-star, but you'd have to find a suitable heuristic. One obvious candidate is that…

Heuristic: Longest common subsequence of the current state vs the target?

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

#164

Hi. I'm the post's author. This was something I dashed off quickly, so I was a bit imprecise in the language. Clarifications: Only positive integers are meant to be allowed. (Zero excluded.) Combining is meant to work on adjacent pairs of integers. If this is used in coding interviews, I deny any responsibility. Unless it's used in interviewing me, in which case I will totally take credit.

For whatever it's worth, zero gets you absolutely nowhere; there's no harm in allowing it.

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

#165

Earlier quoted context omitted.

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

I'm sure we could write a brute force tester, and then you would only have to include a list in your webapp. Or harvest people's results

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

#166
post #116

Earlier quoted context omitted.

Should we assume the numbers are initially positive and distinct, too?

They must be, because otherwise you'd never be allowed to split or combine to create the final list.

Technically there are cases in which you can. The repeated values will act like separators that you cannot act on (because once you act on one, as you said one cannot create the final list again), but then it becomes multiple instances of the puzzle which seems pointless

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

#167
post #144
post #124

Earlier quoted context omitted.

Indeed, [n, n-1] [n-3, 3, n-1] [n-3, 2, 1, n-1] [n-3, 2, n] [n-1, n] Works for all n greater than... 6?

Optimizing self-response! That fails for six because n-3 and 3 co-occur. With a slight modification we can make it work for all n>5 [n, n-1] [2, n-2, n-1] [2, n-3, 1, n-1] [2, n-3, n] [n-1, n] edit: and it's not hard to show that n<6 are impossible, so the solution above is optimal in that sense.

[deleted]

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

#168
post #103

Earlier quoted context omitted.

> In reality, it is nothing more than memoization of function calls into an array. No, it's the next step after memoization. Recursion is the slowest approach of implementing many algorithms, as it will duplicate a lot of computation of subproblems. It solves a lot of subproblems many times. Memoization is a cheap fix, it will not solve subproblems multiple times. It stores subproblems it has already solved, along wi…

Keeping the intermediate results of computations is just called programming. They go into a variable or a data structure like a vector or a hash map.

That tends to blow up your memory. And even if you have huge amounts of memory available, using a big cache will slow down your program enormously.

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

#169

Hi. I'm the post's author. This was something I dashed off quickly, so I was a bit imprecise in the language. Clarifications: Only positive integers are meant to be allowed. (Zero excluded.) Combining is meant to work on adjacent pairs of integers. If this is used in coding interviews, I deny any responsibility. Unless it's used in interviewing me, in which case I will totally take credit.

I got nerd sniped :) and created https://github.com/unrealwill/ReverseListPuzzle to explore all the solutions, with graph algorithms.

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

#170
post #4

It's not possible in general, e.g. [3, 2, 1] can't be reversed.

Any combination where all consecutive numbers are present is unsolvable. That is [1..n], in any order.

That's because it is impossible to split any number, because it will create a duplicate, it is also impossible to merge, because it will either create a duplicate or a number >n

[2..n] (in any order) is also unsolvable for the same reason. And certainly many others ex:[1,2,4], finding if a problem is solvable is interesting in itself. A good solver should nor only find the shortest solution(s) if there is one but also determine if it is solvable. An interesting problem in itself.

Post reply on HN