Safe Puzzle
Puzzle to crack a safe.
Install
$ npm init
$ npm install --save safe-puzzle
Use
var SafePuzzle = ; var safe = length: 4 // number of digits in combination; Default: 4 maxTries: 0 // if maxTries > 0 safe will throw an // error if too many unsuccessfull attempts // Default: 0; safe; // Set combination to '1234' safe; // falsesafe; // synonym of safe.trysafe; // synonym of safe.try safe; // false safe; // true safe; // true try safe; // while safe.isUnlocked() === true catch err if err instanceof SafePuzzleUnlockedError // Already unlocked, Stop trying or reset // safe.randomize() or safe.set( newValue ) var safeMax = maxTries: 1;try safe; // acts as normal safe; // throws error catch err if err instanceof SafePuzzleMaxTriesError // Tried too many times safetries; // 5safeMaxtrie; // 1 safe; // produces new code at random safelast; // '1111'safe; // tries '1112' and returns safe.isUnlocked();safe; // tries '1123' and returns safe.isUnlocked();safe; // tries '9999' and returns safe.isUnlocked();safe; // tries '5555' (as length option === 4) and returns safe.isUnlocked(); safelast = '1234';safe; // compares using safe.last instead of input.safe; // tries '3412' and returns safe.isUnlocked();
Options
var safe = // Options;
- length :: Default: 4 :: length of combination on randomization. If safe.set( newValue ) is used and newValue.length !== options.length an error will be thrown.
- maxTries :: Default: 0 :: If greater than 0, an error will be thrown upon exceeding maximum tries.
Properties
safe.last
-- Defaults to '0000'. Records last attempted value;safe.tries
-- Defaults to 0. Auto-increments upon try;safe.options
-- List of options, post object creation.
Methods
safe.isUnlocked()
-- Returns Boolean indicating state of safe locksafe.set( newValue )
--newValue
: String of new combination. No return.safe.randomize()
-- Generates and sets a new random combination. No return.safe.try( [value] )
-- Testvalue
against combination. Ifvalue
is null, it will testsafe.last
against current combination.safe.test( [value] );
-- alias ofsafe.try
safe.check( [value] );
-- alias ofsafe.try
safe.push( value );
-- concatenatevalue
ontosafe.last
andsafe.try( value )
with the tailsafe,options.length
(default 4) characters against combination.
Puzzles
Simple Puzzle
Simply break the code. Nothing special about it, only four(4) digits. Just break the code using whatever means you prefer.
var SafePuzzle = ; var safe = length: 4; var unlocked = false;while !unlocked var tryCombo = // Generate the next combination unlocked = safe;
Running Code Puzzle
The safe has a four(4) digit password. The password is entered in a running fashion instead of an enter-reset fashion. ex:
var SafePuzzle = ; var safe = length: 4; var unlocked = false; unlocked = safe; // tries '1234'unlocked = safe; // tries '2345'unlocked = safe; // tries '3456'unlocked = safe; // tries '4567'unlocked = safe; // tries '5678'/* etc */
One Long String Puzzle
Produce a single string which contains every possible combination, includes no duplicate entries, and shorter is better.
var SafePuzzle = ; var safe = length: 4; var unlocked = false; var comboString = '1234567890...'; // figure out how to make this string. safelast = comboString;for var i = 3 l = comboStringlength; i < l; i ++ if safe console; break;