Created
April 27, 2026 22:34
-
-
Save danhigham/dd0453fee8f21058e37ec253523e5657 to your computer and use it in GitHub Desktop.
Jason's plates problem
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env ruby | |
| LENGTH = 5 | |
| def extend_plates(plates) | |
| plates.flat_map do |p| | |
| last = p.last | |
| [last - 1, last + 1].select { |d| d.between?(0, 9) }.map { |d| p + [d] } | |
| end | |
| end | |
| plates = (1..9).map { |d| [d] } | |
| (LENGTH - 1).times { plates = extend_plates(plates) } | |
| puts "Total: #{plates.size}" | |
| puts "First 10: #{plates.first(10).map(&:join).join(', ')}" | |
| puts "Sample contains 43456? #{plates.any? { |p| p.join == '43456' }}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment