move askNumber to utils

This commit is contained in:
2025-10-17 15:50:59 +02:00
parent b4146cd8ce
commit 4fc1af5c88
3 changed files with 19 additions and 24 deletions

View File

@@ -1,6 +1,7 @@
import Text.Read (readMaybe)
import System.Exit (exitSuccess)
import Data.Bits
import Utils (askNumber)
main :: IO ()
main = do
@@ -16,16 +17,6 @@ main = do
Nothing -> do
putStrLn "Failed to find a factor using Pollard p-1 method. n could be prime or different parameters needed."
askNumber :: String -> IO Integer
askNumber s = do
putStrLn s
input <- getLine
case readMaybe input of
Just n | n > 1 -> return n
_ -> do
putStrLn "Not a valid integer"
exitSuccess
-- Pollard p-1 factorization algorithm
pollardP1 :: Integer -> Integer -> Maybe Integer
pollardP1 n b = tryBases [2..5]