4 kyu

The observed PIN

18,581 of 39,354BattleRattle

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 Trained111331
Total Skips23192
Total Code Submissions168002
Total Times Completed39354
JavaScript Completions10583
Python Completions18581
Ruby Completions1204
Haskell Completions753
Clojure Completions142
Java Completions2739
C# Completions2111
C++ Completions2065
C Completions484
PHP Completions511
Kotlin Completions260
Rust Completions499
Scala Completions26
Total Stars3880
% of votes with a positive feedback rating94% of 4024
Total "Very Satisfied" Votes3562
Total "Somewhat Satisfied" Votes415
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