News for hackers. Stuff that matters.
Re:"Here's a puzzle game. I call it Reverse the List of Inte... by OskarS on Friday April 12, 2024 @05:17PM (#40017762)
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 if you have target list that is X long and a current list that is Y long, then you need at least abs(Y - X) steps to get there (since each step either adds or removes a number). That's admissable and would probably speed up the search quite a bit compared to regular BFS, but you could probably do a lot better. I'm thinking a heuristic based on the number of inversions or something.

I would suspect if you found a really good heuristic for A-star, that's about as good as you're going to get. Though maybe there's something more clever I'm not spotting.

Re:"Here's a puzzle game. I call it Reverse the List of Inte... by hnfong on Saturday April 13, 2024 @02:25AM (#40020968)
Heuristic: Longest common subsequence of the current state vs the target?
Re:"Here's a puzzle game. I call it Reverse the List of Inte... by 61u on Tuesday April 16, 2024 @08:01AM (#40050919)
You could just run bfs from both starting and ending nodes until you find a node reachable from both the starting and ending nodes.
Re:"Here's a puzzle game. I call it Reverse the List of Inte... by 61u on Tuesday April 16, 2024 @10:46AM (#40052658)
https://ideone.com/MGFwdo

I am running BFS from only the starting node because the graph is symmetrical.