4 kyu

The observed PIN

10,460 of 38,725BattleRattle

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 Trained109915
Total Skips23007
Total Code Submissions166189
Total Times Completed38725
JavaScript Completions10460
Python Completions18238
Ruby Completions1198
Haskell Completions743
Clojure Completions141
Java Completions2708
C# Completions2077
C++ Completions2016
C Completions477
PHP Completions496
Kotlin Completions252
Rust Completions475
Scala Completions20
Total Stars3833
% of votes with a positive feedback rating94% of 3979
Total "Very Satisfied" Votes3522
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