Skip to content

Commit

Permalink
Improved kontrollsiffra/haskell
Browse files Browse the repository at this point in the history
  • Loading branch information
Sony? committed May 9, 2014
1 parent 6bfa656 commit 9f55993
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions kontrollsiffra/sawny.hs
@@ -1,17 +1,16 @@
import System.IO (getLine)

toInt :: [String] -> [Int]
toInt = map read

-- Get every nth element in a list
every :: Int -> [Int] -> [Int]
every _ [] = []
every n (x:xs) = x : every n (drop (n-1) xs)

main = do
stdin <- getLine
let numbers = toInt $ words stdin
let total = sum [foldl (\acc x -> acc + x*3) 0 (every 2 numbers),
foldl (\acc x -> acc + x*7) 0 (every 2 (tail numbers))]

let total = sum (every 2 numbers) * 3 + sum (every 2 $ tail numbers) * 7

print $ total `mod` 10

0 comments on commit 9f55993

Please sign in to comment.