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] ++
[ad, op, show ayr, cb, leq, show ayc, cl, or, op, show bxr, cb] ++
[ [show n, ". ", show a, " = "]
, term axr axc " + "
[leq, show bxc, cl, ad, op, show byr, cb, leq, show byc, cl]
, term ayr ayc " or "
, term bxr bxc " + "
, term byr byc []
]
where
where
cb = "^3"
term r c l = ["(", show r, "^3=", show c, ")", l]
eq = " = "
leq = "="
ad = " + "
or = " or "
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 6 (drop 1999 xs))))
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>