Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const lines = [
- [8, 3, 4],
- [1, 5, 9],
- [6, 7, 2]
- ]
- const columns = [
- [8, 1, 6],
- [3, 5, 7],
- [4, 9, 2]
- ]
- // diagonal
- const cross = [
- [8, 5, 2],
- [6, 5, 4]
- ]
- // junta os 3 acima na mesma array
- const tests = lines.concat(columns).concat(cross)
- let fail = false
- const base = tests[0].reduce(sum)
- for (let test of tests) {
- // some os numeros da array e verifica se é igual ao da base
- if (test.reduce((part, number) => part + number) !== base) {
- fail = true
- break
- }
- }
- if (!fail) {
- console.log('A FUCKING MAGIC CUBE')
- }
- function sum (part, number) {
- return part + number
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement