Browse Source

Add number in parameter and the teacher inline version

DricomDragon 5 years ago
parent
commit
3c60684b3f
1 changed files with 9 additions and 3 deletions
  1. 9 3
      io_cesar.hs

+ 9 - 3
io_cesar.hs

@@ -2,9 +2,15 @@
 
 import Data.Char
 
-cechar c = chr ((mod ((ord c) + 13 - ord 'a') ((ord 'z') - ord 'a'  + 1)) + ord 'a')
+cechar n c = chr ((mod ((ord c) + n - ord 'a') ((ord 'z') - ord 'a'  + 1)) + ord 'a')
 
-cesar = map cechar
+cesar n = map (cechar n)
+
+inlinecesar n s = map (chr.(+ ord 'a').(flip mod 26).(+ n).(subtract (ord 'a')).ord) s
 
 main::IO ()
-main = getLine >>= putStrLn.cesar
+main = do
+	n <- getLine
+	s <- getLine
+	putStrLn (cesar (read n) s)
+	putStrLn (inlinecesar (read n) s)