4 kyu

The observed PIN

18,200 of 38,653BattleRattle

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 Trained109751
Total Skips22993
Total Code Submissions165957
Total Times Completed38653
JavaScript Completions10446
Python Completions18200
Ruby Completions1196
Haskell Completions742
Clojure Completions140
Java Completions2702
C# Completions2071
C++ Completions2011
C Completions475
PHP Completions495
Kotlin Completions248
Rust Completions472
Scala Completions19
Total Stars3829
% of votes with a positive feedback rating94% of 3971
Total "Very Satisfied" Votes3516
Total "Somewhat Satisfied" Votes408
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