Skip to content

Instantly share code, notes, and snippets.

@DerWaldschrat
Created July 17, 2013 15:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DerWaldschrat/6021646 to your computer and use it in GitHub Desktop.
Save DerWaldschrat/6021646 to your computer and use it in GitHub Desktop.
var combinations = [
[1,2,3,4,5,6],
[7,8,9,10,11,12],
[13,14,15,16,17,18],
[10,14,27,32,39,43],
[13,23,31,33,46,49],
[7,15,17,28,31,36],
[17,22,25,35,36,42],
[4,6,12,18,36,48],
[17,25,28,29,40,42],
[5,21,29,31,37,49],
[14,21,22,30,32,49],
[12,16,29,33,34,45],
[9,16,20,30,36,47],
[2,12,29,30,38,47],
[1,8,17,22,25,46],
[7,19,25,30,47,48],
[5,19,26,29,34,46],
[5,9,12,23,27,43],
[7,12,16,26,39,49],
[3,18,24,40,41,44],
[1,6,8,21,33,37],
[7,9,22,24,31,35],
[10,14,29,37,44,49],
[3,5,35,41,44,48],
[5,36,38,39,44,47],
[5,22,41,44,48,49],
[2,12,22,27,40,47],
[10,13,18,40,43,44]]
var i1 = 0, i2 = 0, i3 = 0, i4 = 0, i5 = 0, i6 = 0, toPay = 0,
correctNumbers = 0, j = 0, c = 0, combinationCount = combinations.length, currentCombination = new Array(6), currentNumber = 0
bestTip = new Array(6), bestTipSum = Infinity;
outer: for (i1 = 1; i1 < 50; i1++) {
for (i2 = i1 + 1; i2 < 50; i2++) {
for (i3 = i2 + 1; i3 < 50; i3++) {
for (i4 = i3 + 1; i4 < 50; i4++) {
for (i5 = i4 + 1; i5 < 50; i5++) {
for (i6 = i5 + 1; i6 < 50; i6++) {
// Iterate over all combinations
for (c = 0; c < combinationCount; c++) {
currentCombination = combinations[c]
// Check how many tips are correct
for (j = 0; j < 6; j++) {
currentNumber = currentCombination[j]
if (i1 === currentNumber || i2 === currentNumber || i3 === currentNumber || i4 === currentNumber || i5 === currentNumber || i6 === currentNumber) {
++correctNumbers
}
}
if (correctNumbers > 2) {
toPay += correctNumbers === 3 ? 50 : (
correctNumbers === 4 ? 200 : (
correctNumbers === 5 ? 5000 : 300000
)
)
}
correctNumbers = 0
}
if (toPay < bestTipSum) {
bestTipSum = toPay
bestTip[0] = i1
bestTip[1] = i2
bestTip[2] = i3
bestTip[3] = i4
bestTip[4] = i5
bestTip[5] = i6
if (toPay === 0) {
// If we do not need to pay any money, just break since this is the best combination ;)
break outer;
}
}
toPay = 0
}
}
}
}
}
}
alert("Beste Zahlenkombination: " + bestTip + "\n" + "Nötige Ausschüttung: " + bestTipSum + " €")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment