Jacobi symbol: Difference between revisions

m
→‎{{header|Haskell}}: Disaggregated the tabulation functions a little
m (→‎{{header|Haskell}}: Disaggregated the tabulation functions a little)
Line 288:
p = (3 ==) . flip rem 4
r = rem x y
 
------------------------- DISPLAY -------------------------
 
jacobiTable :: Int -> Int -> String
jacobiTable nCols nRows =
withColumnLabels ("" : fmap show [0 .. nCols]) $
labelledRows (fmap show [1,3 .. (2 * nRows)]) $
paddedCols $
chunksOf nRows $
(uncurry jacobi <$> ((,) <*$>) [0 .. fmappred (,))nCols] cols<*> [1,3 .. (nRows * 2)]))
 
 
-------------------------- TEST ---------------------------
Line 293 ⟶ 304:
main = putStrLn $ jacobiTable 11 9
 
 
------------------------- DISPLAY -------------------------
 
jacobiTable :: Int -> Int -> String
------------------ TABULATION FUNCTIONS -------------------
jacobiTable nCols nRows =
 
let nth = (nRows * 2)
paddedCols :: Show ysa => [1,3[a]] ..-> nth[[String]]
paddedCols cols =
w = length (show nth)
let scols = fmap show <$> cols
rjust = justifyRight w ' ' . show
showRow (x:xs)w = unwordsmaximum $ rjustlength x : "-<$>" : map rjustconcat xsscols
in map rjust = (justifyRight w ' ') .<$> showscols
cols = [0 .. pred nCols]
 
rowLines =
labelledRows :: [String] -> [[String]] -> [[String]]
showRow <$>
labelledRows labels cols =
transpose
let w = maximum $ map length (ys :labels
in zipWith (:) ((++ " ->") . justifyRight w ' ' <$> labels) (transpose cols)
chunksOf
 
nRows
withColumnLabels :: [String] -> [[String]] -> String
(uncurry jacobi <$> ((<*>) . fmap (,)) cols [1,3 .. (nRows * 2)]))
withColumnLabels labels rows@(x:_) =
in unlines $
let labelRow = (justifyRightunwords (4$ +zipWith w)(`justifyRight` ' ' [] ++ unwords) (rjustlength <$> cols)x) :labels
in unlines $ labelRow : replicate (length $ head rowLineslabelRow) '-' : rowLinesfmap unwords rows
 
justifyRight :: Int -> a -> [a] -> [a]
9,659

edits