Trello test

Trello тоже иногда ищет кодеров и задает им вот такие тестовые задания

Find a 9 letter string of characters that contains only letters from
acdegilmnoprstuw
such that the hash(the_string) is
914117715920704
if hash is defined by the following pseudo-code:

Int64 hash (String s) {
    Int64 h = 7
    String letters = "acdegilmnoprstuw"
    for(Int32 i = 0; i < s.length; i++) {
        h = (h * 37 + letters.indexOf(s[i]))
    }
    return h
}
For example, if we were trying to find the 7 letter string where hash(the_string) was 680131659347, the answer would be "leepadg".)

а вот решение


console.log((function (hash) {
    var letters = "acdegilmnoprstuw",
        index,
        result = "";
    while (hash > 7) {
        index = hash % 37;
        result = letters[index] + result;
        hash = (hash - index) / 37;
    }
    return result;
})(680131659347));

Комментарий “Trello test

Комментарии закрыты