Taxicab numbers: Difference between revisions
Content added Content deleted
(→{{header|Haskell}}: pp^2 (more legible pretty-printing code)) |
|||
Line 1,195: | Line 1,195: | ||
taxiRow :: (Int, [(Int, ((Int, Int), (Int, Int)))]) -> [String] |
taxiRow :: (Int, [(Int, ((Int, Int), (Int, Int)))]) -> [String] |
||
taxiRow (n, [(a, ((axc, axr), (ayc, ayr))), (b, ((bxc, bxr), (byc, byr)))]) = |
taxiRow (n, [(a, ((axc, axr), (ayc, ayr))), (b, ((bxc, bxr), (byc, byr)))]) = |
||
concat |
|||
[show n, ". ", show a, eq, op, show axr, cb, leq, show axc, cl] ++ |
|||
[ |
[ [show n, ". ", show a, " = "] |
||
⚫ | |||
[leq, show bxc, cl, ad, op, show byr, cb, leq, show byc, cl] |
|||
⚫ | |||
, term bxr bxc " + " |
|||
, term byr byc [] |
|||
] |
|||
where |
where |
||
term r c l = ["(", show r, "^3=", show c, ")", l] |
|||
eq = " = " |
|||
leq = "=" |
|||
⚫ | |||
⚫ | |||
op = "(" |
|||
cl = ")" |
|||
-- OUTPUT ------------------------------------------------------------- |
-- OUTPUT ------------------------------------------------------------- |
||
Line 1,216: | Line 1,214: | ||
let w = maximum (length <$> col) |
let w = maximum (length <$> col) |
||
in (justifyRight w ' ' <$> col)) <$> |
in (justifyRight w ' ' <$> col)) <$> |
||
transpose (taxiRow <$> (take 25 xs ++ take |
transpose (taxiRow <$> (take 25 xs ++ take 7 (drop 1999 xs)))) |
||
where |
where |
||
justifyRight n c s = drop (length s) (replicate n c ++ s)</lang> |
justifyRight n c s = drop (length s) (replicate n c ++ s)</lang> |