Skip to content

Instantly share code, notes, and snippets.

@jdjkelly
Created February 6, 2014 05:12
Show Gist options
  • Save jdjkelly/8838705 to your computer and use it in GitHub Desktop.
Save jdjkelly/8838705 to your computer and use it in GitHub Desktop.
011314_challenge_148_easy_combination_lock
var input = [5, 1, 2, 3],
digit_count = input.shift()
digit_count * 4 + input[0] * 2 - input[1] * 2 + input[2]
@jdjkelly
Copy link
Author

jdjkelly commented Feb 6, 2014

var input = [5, 1, 2, 3], 
    digit_count = input.shift()


function rotateTwice(count) {
    count += digit_count * 2 + input[0];
    return count;
}

function spinCounterClockwise(count) {
    count += digit_count + input[0] + digit_count - input[1];
    return count;
}

function goToLastDigit(count) {
    count += input[2] - input[1];
    return count;
}

function openLock(count) {
    return goToLastDigit(spinCounterClockwise(rotateTwice(count)));
}

openLock(0);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment