The sieve of Sundaram: Difference between revisions
m
→{{header|JavaScript}}
m (→{{header|AppleScript}}: Optimisation.) |
|||
Line 464:
);
};
// nSundaramsPrimes :: Int -> [Int]
Line 472 ⟶ 473:
)
.slice(0, n);
// ---------------------- TEST -----------------------
const main = () =>
table(" ")(▼
chunksOf(10)(▼
nSundaramPrimes(100)▼
.map(n => `${n}`)▼
)▼
)
].join("\n");
Line 504 ⟶ 500:
// xs split into sublists of length n.
// The last sublist will be short if n
// does not evenly divide the length of xs
const go = xs => {
const chunk = xs.slice(0, n);
Line 517 ⟶ 513:
return go;
};
// table :: String ->▼
const table = gap =>▼
// A tabulation of rows of string values,▼
// with a specified gap between columns.▼
rows => {▼
const▼
lastRow = rows[rows.length - 1],▼
return rows.map(▼
justifyRight(w)(" ")▼
Line 545 ⟶ 522:
s.padStart(n, c)
) : "";
▲ // table :: Int -> String -> [[String]] -> String
▲ // A tabulation of rows of string values,
▲ // with a specified gap between columns.
▲ justifyRight(w)(" ")
▲ )
return main();
})();</lang>
{{Out}}
<pre>First
(starting at 3):
|