Jacobi symbol: Difference between revisions

m
(→‎{{header|Haskell}}: Replaced a do with a (let ... in ...) (No monad used or needed here))
Line 275:
import Data.List.Split (chunksOf)
import Data.Bool (bool)
 
jacobi :: Int -> Int -> Int
jacobi = go
Line 282:
go 0 _ = 0
go x y
| even r = bool id negateplusMinus (rem y 8 `elem` [3, 5]) (go (div r 2) y)
| otherwise = bool id negateplusMinus (3 == rem r 4 && 3 == rem y 4) (go y r)
where
plusMinus = bool id negate
r = rem x y
 
-------------------------- TEST ---------------------------
main :: IO ()
main = putStrLn $ jacobiTable 11 9
 
------------------------- DISPLAY -------------------------
jacobiTable :: Int -> Int -> String
Line 310 ⟶ 311:
(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