Created
July 6, 2018 04:16
-
-
Save CarstenKoenig/1f0397454cd2913da338e23515372116 to your computer and use it in GitHub Desktop.
Prüfsumme
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Main where | |
import Data.List (unfoldr) | |
main = | |
putStrLn $ "Prüfe Rechnungsnummer 4711: " ++ show (pruefsummeFuerRechnungsNummern 4711) | |
pruefsummeFuerNetzwerkAdressen = | |
pruefsumme [5,1] 9 digitsRightToLeft | |
pruefsummeFuerRechnungsNummern = | |
pruefsumme [5,1] 7 digitsLeftToRight | |
pruefsumme gewichtungen modulo ziffernAusZahl = | |
(`mod` modulo) . sum . zipWith (*) (cycle gewichtungen) . ziffernAusZahl | |
digitsLeftToRight = | |
reverse . digitsRightToLeft | |
digitsRightToLeft 0 = [0] | |
digitsRightToLeft zahl = unfoldr next zahl | |
where | |
next n | |
| n > 0 = Just (n `mod` 10, n `div` 10) | |
| otherwise = Nothing |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment