Jacobi symbol: Difference between revisions

Content added Content deleted
m (→‎{{header|Haskell}}: Disaggregated the tabulation functions a little)
Line 290: Line 290:


------------------------- DISPLAY -------------------------
------------------------- DISPLAY -------------------------

jacobiTable :: Int -> Int -> String
jacobiTable :: Int -> Int -> String
jacobiTable nCols nRows =
jacobiTable nCols nRows =
let rowLabels = [1,3 .. (2 * nRows)]
withColumnLabels ("" : fmap show [0 .. nCols]) $
colLabels = [0 .. pred nCols]
labelledRows (fmap show [1,3 .. (2 * nRows)]) $
in withColumnLabels ("" : fmap show colLabels) $
paddedCols $
labelledRows (fmap show rowLabels) $
chunksOf nRows $
paddedCols $
uncurry jacobi <$> ((,) <$> [0 .. pred nCols] <*> [1,3 .. (nRows * 2)])
chunksOf nRows $

uncurry jacobi <$> ((,) <$> colLabels <*> rowLabels)


-------------------------- TEST ---------------------------
-------------------------- TEST ---------------------------
main :: IO ()
main :: IO ()
main = putStrLn $ jacobiTable 11 9
main = putStrLn $ jacobiTable 11 9




------------------ TABULATION FUNCTIONS -------------------
------------------ TABULATION FUNCTIONS -------------------
paddedCols

paddedCols :: Show a => [[a]] -> [[String]]
:: Show a
=> [[a]] -> [[String]]
paddedCols cols =
paddedCols cols =
let scols = fmap show <$> cols
let scols = fmap show <$> cols