Skip to content

Instantly share code, notes, and snippets.

@lschuermann
Last active December 28, 2015 11:02
Show Gist options
  • Save lschuermann/dbb80889eed954cd0d78 to your computer and use it in GitHub Desktop.
Save lschuermann/dbb80889eed954cd0d78 to your computer and use it in GitHub Desktop.
Script to search for a specific number. Useful on some Opta3 - / Testen.io employment tests.

Opta3 / Testen.io helper script

Search for a number with specified characteristics. Useful on some Opta3 / Testen.io employment-tests.

Disclaimer

The software is provided under the MIT-License. Therefore, I am not responsible for any errors in the software and their consequences relating your test-score and / or computer-system.

Software Requirements

Script is a Node.js-Application, so Node must be installed.

UNIX (Linux / Mac OS X) Usage guide:

Download Script in Raw-Format (Right-click => Save As).

Edit the script's upper part (Characteristics) to match the searched number in the Test.

Then, open your favorite Terminal-Emulator switch to the Scripts-Directory.

  • Make the script executable with chmod +x searchnum.js.
  • Run the script by either typing ./searchnum.

The output will be a few numbers, of which one might fit. Check all characteristics against that number.

// ---------- Characteristics
var length = 5;
var digit_sum = 20;
var highestNumPos = 1;
var operation1pos1 = 3;
var operation1pos2 = 4;
var operation1sumpos = 5;
var operation2pos1 = 2;
var operation2pos2 = 4;
var operation2sumpos = 3;
// ---------- CODE
Number.prototype.quersumme = function(forceOneDigit) {
var z = this.toString().split('');
for (var i=0, quer=0; i < z.length; quer+=z[i++]-0);
if( forceOneDigit && quer > 9) return quer.quersumme(forceOneDigit);
return quer;
}
Number.prototype.highestAtPos = function(pos) {
var strNumArr = this.toString().split('');
var highestPos;
var highest = -1;
for (var i = 0; i < strNumArr.length; i++) {
if (parseInt(strNumArr[i]) > highest) {
highest = parseInt(strNumArr[i]);
highestPos = i;
}
}
if (highestPos == pos - 1)
return true;
else
return false;
}
var current = 10^length;
var max = current * 10;
var found = false;
while (current < 100000) {
if (current > 100000) found = true;
else if (current.quersumme() != digit_sum) false;
else {
var arr = current.toString().split('');
if (parseInt(arr[operation1pos1-1]) + parseInt(arr[operation1pos2-1]) != parseInt(arr[operation1sumpos-1])) false;
else if (parseInt(arr[operation2pos1-1]) + parseInt(arr[operation2pos2-1]) != parseInt(arr[operation2sumpos-1])) false;
else {
if (current.highestAtPos(highestNumPos))
console.log(current);
}
}
current++;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment