Jump to content

Magic squares of doubly even order: Difference between revisions

m
→‎JS ES6: (Adjusted the point at which the truth series starts – simplifies the indexing expressions)
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:
// truthSeries :: Int -> [Int]
const truthSeries = n => {
if (n <= 1) return [true, false];
const xs = truthSeries(n - 1);
return xs.concat(xs.map(x => !x));
Line 435:
scale = curry(replicate)(n / 4),
power = Math.log2(sqr),
sequence = isInt(power) ? truthSeries(power + 1) : (
flatten(scale(splitEvery(4, truthSeries(5))
.map(scale)))(
splitEvery(4, truthSeries(4))
.map(scale)
)
)
);
 
Line 532 ⟶ 536:
 
// TEST -----------------------------------------------------------------
 
return [4, 8, 12]
//return doubleEvenMagicSquare(8)
 
return [4, 8, 12]
.map(n => {
const lines = doubleEvenMagicSquare(n);
9,659

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.