summaryrefslogtreecommitdiff
path: root/Assignment1/CamilStaps-assignment1-shift.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Assignment1/CamilStaps-assignment1-shift.hs')
-rw-r--r--Assignment1/CamilStaps-assignment1-shift.hs14
1 files changed, 14 insertions, 0 deletions
diff --git a/Assignment1/CamilStaps-assignment1-shift.hs b/Assignment1/CamilStaps-assignment1-shift.hs
new file mode 100644
index 0000000..35a34e7
--- /dev/null
+++ b/Assignment1/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