4 kyu

The observed PIN

498 of 38,910BattleRattle

Description:

Alright, detective, one of our colleagues successfully observed our target person, Robby the robber. We followed him to a secret warehouse, where we assume to find all the stolen stuff. The door to this warehouse is secured by an electronic combination lock. Unfortunately our spy isn't sure about the PIN he saw, when Robby entered it.

The keypad has the following layout:

┌───┬───┬───┐
│ 1 │ 2 │ 3 │
├───┼───┼───┤
│ 4 │ 5 │ 6 │
├───┼───┼───┤
│ 7 │ 8 │ 9 │
└───┼───┼───┘
    │ 0 │
    └───┘

He noted the PIN 1357, but he also said, it is possible that each of the digits he saw could actually be another adjacent digit (horizontally or vertically, but not diagonally). E.g. instead of the 1 it could also be the 2 or 4. And instead of the 5 it could also be the 2, 4, 6 or 8.

He also mentioned, he knows this kind of locks. You can enter an unlimited amount of wrong PINs, they never finally lock the system or sound the alarm. That's why we can try out all possible (*) variations.

* possible in sense of: the observed PIN itself and all variations considering the adjacent digits

Can you help us to find all those variations? It would be nice to have a function, that returns an array (or a list in Java/Kotlin and C#) of all variations for an observed PIN with a length of 1 to 8 digits. We could name the function getPINs (get_pins in python, GetPINs in C#). But please note that all PINs, the observed one and also the results, must be strings, because of potentially leading '0's. We already prepared some test cases for you.

Detective, we are counting on you!

Algorithms

Stats:

CreatedOct 20, 2013
PublishedOct 20, 2013
Warriors Trained110387
Total Skips23063
Total Code Submissions166795
Total Times Completed38910
JavaScript Completions10497
Python Completions18348
Ruby Completions1200
Haskell Completions747
Clojure Completions142
Java Completions2715
C# Completions2086
C++ Completions2033
C Completions479
PHP Completions498
Kotlin Completions254
Rust Completions478
Scala Completions22
Total Stars3841
% of votes with a positive feedback rating94% of 3990
Total "Very Satisfied" Votes3533
Total "Somewhat Satisfied" Votes410
Total "Not Satisfied" Votes47
Ad
Contributors
  • BattleRattle Avatar
  • jhoffner Avatar
  • Kagirohi Avatar
  • Azuaron Avatar
  • Unnamed Avatar
  • Osmosis Avatar
  • kazk Avatar
  • 00dev Avatar
  • Blind4Basics Avatar
  • Firefly2002 Avatar
  • Torkel Avatar
  • Voile Avatar
  • KataSideKick Avatar
  • FArekkusu Avatar
  • _mer_ Avatar
  • Awesome A.D. Avatar
  • hobovsky Avatar
  • user3029010 Avatar
  • cliffstamp Avatar
  • el-f Avatar
  • akar-0 Avatar
  • Kacarott Avatar
  • sid114 Avatar
  • LearningFTW Avatar
  • cwps Avatar
  • KayleighWasTaken Avatar
Ad