Keypad Errors

August 2, 2016

[ Programming Praxis passed 2 million lifetime hits over the weekend. Gracious thanks to all my readers who have taken it so far. I can still remember being ecstatic when I got to a thousand hits. Thank you all. — Phil ]

Sometimes one key on a keyboard gets stuck, so some keys that are struck do not register. For instance, you may be trying to type 18684 on a numeric keypad, but if the 8 key is stuck, the keyboard registers you typing 164 instead. Assume the only input allowed is the digits 0 through 9.

Your task is to write a program that takes a target number, say a PIN, and a keyboard input, and determines if the keyboard input matches the target number assuming a single key is stuck. When you are finished, you are welcome to read or run a suggested solution, or to post your own solution or discuss the exercise in the comments below.

Pages: 1 2

One Response to “Keypad Errors”

  1. ($pin, $v) = @ARGV;
    my %x=map{eval"$pin=~y{$_}{}dr",1}0..9;
    print exists $x{$v} ? 'MATCH' : 'NO MATCH',"\n";
    

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: