Optimize day 5
This commit is contained in:
parent
e9b068912a
commit
08eaeb02e6
1 changed files with 5 additions and 6 deletions
|
@ -2,19 +2,18 @@
|
|||
-- stack --resolver lts-12.5 script
|
||||
|
||||
module Day5A where
|
||||
import Data.Bits (xor)
|
||||
import Data.Char
|
||||
import qualified Data.Foldable as F
|
||||
|
||||
invertCase :: Char -> Char
|
||||
invertCase c
|
||||
| isUpper c = toLower c
|
||||
| otherwise = toUpper c
|
||||
invertCase = chr . xor 0x20 . ord
|
||||
|
||||
calcLength :: String -> String -> Int
|
||||
calcLength ys (x:y:xs)
|
||||
| x == invertCase y = case length ys of
|
||||
0 -> calcLength ys xs
|
||||
_ -> calcLength (tail ys) (head ys:xs)
|
||||
| x == invertCase y = if null ys
|
||||
then calcLength ys xs
|
||||
else calcLength (tail ys) (head ys:xs)
|
||||
| otherwise = calcLength (x:ys) (y:xs)
|
||||
calcLength ys [x] = calcLength (x:ys) []
|
||||
calcLength ys [] = length ys
|
||||
|
|
Loading…
Reference in a new issue