Jump to content
BrainDen.com - Brain Teasers


  • Posts

  • Joined

  • Last visited

Everything posted by Quantum.Mechanic

  1. I've previously written a nice word puzzle script, which takes in a huge list of words, and creates a list of anagram "siblings". One of the special functions is to find, for each word length, the largest anagram set of siblings.
  2. Yes, thanks very much. I got lost trying to do this myself, but "it's obvious in hindsight", as they say.
  3. I must be thick today, I can't follow the given solution. Can someone paste a little bit more hand holding? Like the first 5 values in the sequence?
  4. Since the integer requirement, there haven't been any replies, so I'll go with an obvious, and not-likely-to-be-optimal one.
  5. OK, I thought that would be a good little puzzle program to write. I'm sure there's an easier way to figure this on paper though, waiting for y'all to clue me in. The first few elements led me to the following:
  6. Are we assuming a mammalian birth process? Then splitting is in utero, and age origin is time of birth. When in Thailand...
  7. Just for fun, I programmed up a little script. Using a suitable underlying GMP library for Euler's totient function, it checked up to 10 million in 13 seconds, with a result of 60.793% distinct pairs relatively prime.
  8. Maximum sum, or highest numbered side?
  9. I saw this puzzle in the same Peter Winkler book I mentioned elsewhere.
  10. Are you sure? Because starting at line 193, it has: # This result might already exist. Keep the new one if the path is shorter. if (not exists($m->{$result}) or (scalar keys %$new_path < scalar keys %{$m->{$result}})) { # print STDERR "\tAdded $expression = $result\n"; $m->{$result} = $new_path; ++$results_added; }
  11. I just read an equivalent puzzle in a puzzle book, so I'll sit this one out...
  12. Yes, that was possible for earlier versions. The current version gives me this: four_banger.pl 30 11 3 [...snip...] Steps for 11 => 3 (not in order): 11 / 11 = 1 1 + 1 = 2 2 + 1 = 3 [...snip...] because it compares multiple paths to the same goal, and keeps the shortest. (In case of ties, it takes the path with the smallest max operand.)
  13. Checking for paths that go above the limit (last number): Not allowing any intermediate results above 25: Steps for 14 => 25 (not in order): 13 - 2 = 11 14 + 11 = 25 14 - 1 = 13 1 + 1 = 2 14 / 14 = 1 Allowing intermediate results above 25: Steps for 14 => 25 (not in order): 14 - 1 = 13 13 + 13 = 26 14 / 14 = 1 26 - 1 = 25 So this is 1 shorter. On a whim, I ran it with the max intermediate step = last**2, or 625 in this case, and found this path with 4 steps: Path above 25 for (15,10): 15 + 15 = 30 450 / 45 = 10 30 + 15 = 45 30 * 15 = 450 Limiting search to 25*2 = 50, found this path with 5 steps: Steps for 15 => 10 (not in order): 1 + 1 = 2 14 - 4 = 10 15 - 1 = 14 2 + 2 = 4 15 / 15 = 1 I wonder how big the search range needs to be in relation to the last number to guarantee the optimal path?
  14. I think you've left something out here, or perhaps meant something else. For pedantic clarity, I'll say this anyway: You didn't say how many moves it was from B to D, or C to D. If it's the same for both, let's say 1, then A->B->D = 4+1 = 5, and A->C->D = 5+1 = 6. So the optimal is A->B->D = 5. Paths don't simply add together -- any duplicate steps only count once. The rest of your statement is worth consideration. The algorithm I use is greedy -- it only keeps the shortest path to any result. But I think it is provable that if there are 2 paths A->B->D = 5 and A->C->D = 4, it will pick the latter. While it might find A->B->D first, it still checks any other paths to D, and keeps generating paths to all results until no new results are added, and no shorter paths are found. # This result might already exist. Keep the new one if the path is shorter. if (not exists($m->{$result}) or (scalar keys %$new_path < scalar keys %{$m->{$result}})) { # print STDERR "\tAdded $expression = $result\n"; $m->{$result} = $new_path; ++$results_added; What you are proposing is that there's some way to get to a result E through a non-optimal path to D, that's shorter than the optimal path to D, plus D->E. I'm a little rusty on my proofs, but I think this falls into the "proof by contradiction" class. Earlier versions of my program didn't do this, but instead stopped when the first path to a result was found. This depended on the generation order, which wasn't necessarily generating shortest path first, instead of the path order. So if a non-optimal path to D was found, it was kept, and no further paths to D were even checked for length. On the other hand, I don't think it was ever stated explicitly if all paths could only go through numbers less than or equal to the limit value. There might be some edge cases where, say, an abundant number >> limit provides a path to a goal with fewer steps than any path <= limit.
  15. If you give us a link, we might be able to visit the site and suggest other sites. I have always liked http://www.ferryhalim.com/orisinal/.
  16. After further study, I realized that the first path to a goal generated may not be the shortest path. It needs to keep generating goals until no new or shorter paths are found. It seems this doesn't happen all that often, so it hardly affects the runtime. Eliminating some of the low level structure, the full matrix including paths can be saved, at least as high as 256. Judging by the memory usage, it could probably go a bit higher. Here's the results I have for 256. Hopefully they pass all of plasmid's tests this time. Here's the latest code.
  • Create New...