osipyonok

Huiaskel additional 2-7

Feb 9th, 2019
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import Control.Monad
  2. import qualified Data.ByteString.Char8 as B
  3. import Data.Maybe
  4. import Data.List
  5. import Control.Arrow
  6.  
  7. readInt :: B.ByteString -> Int
  8. readInt = fst . fromJust . B.readInt
  9.  
  10. main :: IO ()
  11. main = do
  12.   [n] <- liftM (map readInt . B.words) B.getLine
  13.   putStrLn "Input: "
  14.   print n
  15.   putStrLn "Result: "
  16.   print (solve n)
  17.  
  18.  
  19.  
  20. solve n = solve_impl n 0 0
  21.     where solve_impl n a b | n == 0    = a
  22.                            | otherwise = solve_impl (div n 2) b (mod n 2)
  23.  
  24. --31
Advertisement
Add Comment
Please, Sign In to add comment