Skip to content

Commit

Permalink
Added data + haskell + python
Browse files Browse the repository at this point in the history
  • Loading branch information
Sony? committed May 9, 2014
1 parent bbe39f9 commit 6c0db90
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions kontrollsiffra/data/sample01.ans
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5
1 change: 1 addition & 0 deletions kontrollsiffra/data/sample01.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1 2 3 4 5 6 7 8 9
17 changes: 17 additions & 0 deletions kontrollsiffra/sawny.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
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))]

print $ total `mod` 10
13 changes: 13 additions & 0 deletions kontrollsiffra/sawny.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from sys import stdin

data = stdin.read().split();
data = map(int, data);
sum = 0;

for s in data[::2]:
sum = sum + 3*s;

for s in data[1::2]:
sum = sum + 7*s;

print sum % 10

0 comments on commit 6c0db90

Please sign in to comment.