Jacobi symbol: Difference between revisions

m
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 (3 == remp r 4 && 3 == remp y 4) (go y r)
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>
9,655

edits