I think that there are more key presses then you think. There are
(10**4)*3 different combinations which totals 30,000. But that takes
30,000*5 key presses which is 150,000 key presses. So if the code was 5
digits, it is 1,500,000 key presses to test them all by brute force.
Anyway, here is my first solution. It is unrefined, but I haven't
really had time to work on it much.

<code>

# Shane Emmons
#
# Quiz 72 B&E
#
# This code is very ugly and inefficient, but I wanted to get
# something out there to look at. Sorry I didn't have more
# time to work on this quiz.

all_possible = ""

10.times do |key1| 10.times do |key2| 10.times do |key3|
10.times do |key4|  3.times do |key5|
current_code = Array.new
current_code << key1 << key2 << key3 << key4 << key5 + 1
next if all_possible.include?( current_code.to_s )
left, left_over = Array.new( current_code ), Array.new
right, right_over = Array.new( current_code ), Array.new
while true do
left_over << left.shift
right_over << right.pop
if left.length == 0
all_possible += current_code.to_s
break
elsif all_possible =~ /^#{left.to_s}/
all_possible = left_over.to_s + all_possible
break
elsif all_possible =~ /#{right.to_s}\$/
all_possible += right_over.to_s
break
end
end
end end
end end end

print "string: ", all_possible, "\n"
print "string length: ", all_possible.length, "\n"

</code>

Shane