Magic squares of doubly even order: Difference between revisions
Content added Content deleted
m (→{{header|Haskell}}: (Tweaked the point at which the 'magic series' starts, for more natural indexing) |
m (→JS ES6: (Adjusted the point at which the truth series starts – simplifies the indexing expressions)) |
||
Line 427: | Line 427: | ||
// truthSeries :: Int -> [Int] |
// truthSeries :: Int -> [Int] |
||
const truthSeries = n => { |
const truthSeries = n => { |
||
if (n <= 1) return [true]; |
if (n <= 1) return [true, false]; |
||
const xs = truthSeries(n - 1); |
const xs = truthSeries(n - 1); |
||
return xs.concat(xs.map(x => !x)); |
return xs.concat(xs.map(x => !x)); |
||
Line 435: | Line 435: | ||
scale = curry(replicate)(n / 4), |
scale = curry(replicate)(n / 4), |
||
power = Math.log2(sqr), |
power = Math.log2(sqr), |
||
sequence = isInt(power) ? truthSeries(power |
sequence = isInt(power) ? truthSeries(power) : ( |
||
flatten( |
flatten( |
||
scale( |
|||
splitEvery(4, truthSeries(4)) |
|||
.map(scale) |
|||
) |
|||
) |
|||
); |
); |
||
Line 532: | Line 536: | ||
// TEST ----------------------------------------------------------------- |
// TEST ----------------------------------------------------------------- |
||
⚫ | |||
//return doubleEvenMagicSquare(8) |
|||
⚫ | |||
.map(n => { |
.map(n => { |
||
const lines = doubleEvenMagicSquare(n); |
const lines = doubleEvenMagicSquare(n); |