Jacobi symbol: Difference between revisions
m
→{{header|Haskell}}
Line 275:
import Data.List.Split (chunksOf)
import Data.Bool (bool)
jacobi :: Int -> Int -> Int
jacobi = go
Line 283:
go x y
| even r = plusMinus (rem y 8 `elem` [3, 5]) (go (div r 2) y)
| otherwise = plusMinus (
where
plusMinus = bool id negate
p = (3 ==) . flip rem 4
r = rem x y
-------------------------- TEST ---------------------------
main :: IO ()
main = putStrLn $ jacobiTable 11 9
------------------------- DISPLAY -------------------------
jacobiTable :: Int -> Int -> String
Line 311 ⟶ 312:
(justifyRight w ' ' [] ++ " " ++ unwords (rjust <$> cols)) :
replicate (length $ head rowLines) '-' : rowLines
justifyRight :: Int -> a -> [a] -> [a]
justifyRight n c = (drop . length) <*> (replicate n c ++)</lang>
|