DEV Community

dev.to staff
dev.to staff

Posted on

Daily Challenge #285 - Jewel Thief

Word on the street is that you claim to be a safe-cracking jewel thief. But are you?

Let's test your safe-cracking abilities. To prove you are a real thief, you need to crack the combination of the safe, then open it and tell me the value of the jewels inside!

The safe object has two methods:

unlock(combination) returns a string. click means the first part of the combination is correct, click click for the first two parts, click click click means all three are correct.

open() returns an integer containing the value of the safe's contents.

The safe combination format is made up of 3 dial spins:

  • Spin the dial left L or right R
  • Numbers on the dial 00 - 99
  • Each part of the combination is separated by -

Let's see how well you know how to crack safes. Good luck!


This challenge comes from dinglemouse on CodeWars. Thank you to CodeWars, who has licensed redistribution of this challenge under the 2-Clause BSD License!

Want to propose a challenge idea for a future post? Email yo+challenge@dev.to with your suggestions!

Top comments (3)

Collapse
 
256hz profile image
Abe Dolinger • Edited
const crackSafe = safe => {
  const combo = ['L0', 'L0', 'L0'];
  const directions = ['L', 'R'];

  const try = (stage, combo) => {
    const comboWorked = new Array(stage + 1).fill('click').join(' ');

    for (let i = 0; i < 100; i++) {
      directions.forEach(dir => {
        combo[stage] = `${dir}${i}`;
        if safe.unlock(combo.join('-')) === comboWorked {
          return true;
        }
      });
    }
    return false;
  };

  for (let stage = 0; stage < 3; stage++) {
    if (!try(stage, combo)) {
      return -1;
    }
  }

  return safe.open(combo);
};
Enter fullscreen mode Exit fullscreen mode

Not very dynamic but should solve for the problem as written!

Collapse
 
meave9786 profile image
meave9786

Nice to share the amazing blog here thanks for got it how to fix 0x800705b4 all update for seen the easily setting of issues

Collapse