The sieve of Sundaram: Difference between revisions

m
m (→‎{{header|AppleScript}}: Optimisation.)
Line 464:
);
};
 
 
// nSundaramsPrimes :: Int -> [Int]
Line 472 ⟶ 473:
)
.slice(0, n);
 
 
// ---------------------- TEST -----------------------
const main = () => ([
xs"First =>100 [Sundaram primes",
"First hundred(starting Sundaramat primes3):\n",
table(10)(" ")(starting at 3):",
`\n${xs}`nSundaramPrimes(100)
] .joinmap("\n" => `${n}`)
)(
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 ->
// (Int -> Char -> String -> String) ->
// [[String]] -> String
const table = gap =>
// A tabulation of rows of string values,
// with a specified gap between columns.
rows => {
const
lastRow = rows[rows.length - 1],
w = lastRow[lastRow.length - 1].length;
 
return rows.map(
row => row.map(
justifyRight(w)(" ")
).join(gap)
).join("\n");
};
 
 
Line 545 ⟶ 522:
s.padStart(n, c)
) : "";
 
 
// table :: Int -> String -> [[String]] -> String
const table = gapcolCount =>
// A tabulation of rows of string values,
// with a specified gap between columns.
rowsgap => xs => {
const lastRoww = rowsxs[rowsxs.length - 1],.length;
 
return chunksOf(10colCount)(xs)
.map(n => `${n}`)
return rows row => row.map(
justifyRight(w)(" ")
nSundaramPrimes ).join(100gap)
)
table .join(" \n")(;
const};
 
return main();
})();</lang>
{{Out}}
<pre>First hundred100 Sundaram primes
(starting at 3):
 
9,655

edits