Jacobi symbol: Difference between revisions
Content added Content deleted
m (→{{header|Haskell}}: Disaggregated the tabulation functions a little) |
|||
Line 288: | Line 288: | ||
p = (3 ==) . flip rem 4 |
p = (3 ==) . flip rem 4 |
||
r = rem x y |
r = rem x y |
||
⚫ | |||
⚫ | |||
⚫ | |||
withColumnLabels ("" : fmap show [0 .. nCols]) $ |
|||
labelledRows (fmap show [1,3 .. (2 * nRows)]) $ |
|||
paddedCols $ |
|||
chunksOf nRows $ |
|||
⚫ | |||
-------------------------- TEST --------------------------- |
-------------------------- TEST --------------------------- |
||
Line 293: | Line 304: | ||
main = putStrLn $ jacobiTable 11 9 |
main = putStrLn $ jacobiTable 11 9 |
||
⚫ | |||
⚫ | |||
------------------ TABULATION FUNCTIONS ------------------- |
|||
⚫ | |||
let nth = (nRows * 2) |
|||
paddedCols :: Show a => [[a]] -> [[String]] |
|||
paddedCols cols = |
|||
w = length (show nth) |
|||
let scols = fmap show <$> cols |
|||
⚫ | |||
w = maximum $ length <$> concat scols |
|||
⚫ | |||
cols = [0 .. pred nCols] |
|||
rowLines = |
|||
labelledRows :: [String] -> [[String]] -> [[String]] |
|||
showRow <$> |
|||
labelledRows labels cols = |
|||
transpose |
|||
let w = maximum $ map length labels |
|||
in zipWith (:) ((++ " ->") . justifyRight w ' ' <$> labels) (transpose cols) |
|||
chunksOf |
|||
nRows |
|||
withColumnLabels :: [String] -> [[String]] -> String |
|||
⚫ | |||
withColumnLabels labels rows@(x:_) = |
|||
in unlines $ |
|||
let labelRow = unwords $ zipWith (`justifyRight` ' ') (length <$> x) labels |
|||
replicate (length |
in unlines $ labelRow : replicate (length labelRow) '-' : fmap unwords rows |
||
justifyRight :: Int -> a -> [a] -> [a] |
justifyRight :: Int -> a -> [a] -> [a] |