Taxicab numbers: Difference between revisions

m
→‎{{header|Haskell}}: (Rearranged pretty-printing to occupy less vertical space on the code page)
(→‎{{header|Haskell}}: (added a bit of pretty-printing))
m (→‎{{header|Haskell}}: (Rearranged pretty-printing to occupy less vertical space on the code page))
Line 1,177:
import Data.Ord (comparing)
 
-- TAXICAB NUMBERS ----------------------------------------------------
taxis :: Int -> [[(Int, ((Int, Int), (Int, Int)))]]
taxis nCubes =
Line 1,187 ⟶ 1,188:
, y <- t ]
 
-- Taxicab numbers amongcomposed using first 1200 cubes
xs :: [(Int, [(Int, ((Int, Int), (Int, Int)))])]
xs = zip [1 ..] (taxis 1200)
 
-- PRETTY PRINTING ----------------------------------------------------
-- Pretty-printing
taxiRow :: (Int, [(Int, ((Int, Int), (Int, Int)))]) -> [String]
taxiRow (n, [(a, ((axc, axr), (ayc, ayr))), (b, ((bxc, bxr), (byc, byr)))]) =
[show n, ". ", show a, eq, op, show axr, cb, leq, show axc, cl] ++
[ show n
[ad, op, show ayr, cb, leq, show ayc, cl, or, op, show bxr, cb] ++
, ". "
[leq, show bxc, cl, ad, op, show byr, cb, leq, show byc, cl]
, 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
, leq
, show bxc
, cl
, ad
, op
, show byr
, cb
, leq
, show byc
, cl
]
where
cb = "^3"
Line 1,235 ⟶ 1,207:
cl = ")"
 
-- OUTPUT -------------------------------------------------------------
main :: IO ()
main =
Line 1,243 ⟶ 1,216:
let w = maximum (length <$> col)
in (justifyRight w ' ' <$> col)) <$>
transpose (taxiRow <$> (take 25 xs ++ take 76 (drop 1999 xs))))
where
justifyRight n c s = drop (length s) (replicate n c ++ s)</lang>
9,659

edits