Advertisement
Guest User

magic test

a guest
Dec 13th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const lines = [
  2.   [8, 3, 4],
  3.   [1, 5, 9],
  4.   [6, 7, 2]
  5. ]
  6. const columns = [
  7.   [8, 1, 6],
  8.   [3, 5, 7],
  9.   [4, 9, 2]
  10. ]
  11. // diagonal
  12. const cross = [
  13.   [8, 5, 2],
  14.   [6, 5, 4]
  15. ]
  16. // junta os 3 acima na mesma array
  17. const tests = lines.concat(columns).concat(cross)
  18. let fail = false
  19. const base = tests[0].reduce(sum)
  20. for (let test of tests) {
  21.   // some os numeros da array e verifica se é igual ao da base
  22.   if (test.reduce((part, number) => part + number) !== base) {
  23.     fail = true
  24.     break
  25.   }
  26. }
  27. if (!fail) {
  28.   console.log('A FUCKING MAGIC CUBE')
  29. }
  30.  
  31. function sum (part, number) {
  32.   return part + number
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement