diff options
| author | Camil Staps | 2016-02-12 14:50:35 +0100 |
|---|---|---|
| committer | Camil Staps | 2016-02-12 14:50:35 +0100 |
| commit | a9af9b24b7fbfb31110123b125fb7fc916cff24f (patch) | |
| tree | e8a49c9bedbcf43a912dfd37348da79123bf814a /Assignment 1/CamilStaps-assignment1-shift.hs | |
Put everything on git
Diffstat (limited to 'Assignment 1/CamilStaps-assignment1-shift.hs')
| -rw-r--r-- | Assignment 1/CamilStaps-assignment1-shift.hs | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/Assignment 1/CamilStaps-assignment1-shift.hs b/Assignment 1/CamilStaps-assignment1-shift.hs new file mode 100644 index 0000000..35a34e7 --- /dev/null +++ b/Assignment 1/CamilStaps-assignment1-shift.hs @@ -0,0 +1,14 @@ +import System.Environment +import Data.String.Utils + +main = do + args <- getArgs + let input = replace " " "" (head args) + print $ map (`shiftN` (read $ args!!1)) input + +-- shiftN c i: shift c i times forward (i.e. shiftN 'A' 1 == 'B') +-- Only for uppercase letters +shiftN :: Char -> Int -> Char +shiftN c 0 = c +shiftN 'Z' i = shiftN 'A' (i-1) +shiftN c i = shiftN (toEnum ((fromEnum c) + 1)) (i-1)
\ No newline at end of file |
