-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
24 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module Kyu6.InsideOut where | ||
|
||
insideOut :: String -> String | ||
insideOut xs = unwords $ map turnWord $ words xs | ||
|
||
turnWord :: String -> String | ||
turnWord xs | ||
| even l = reverse (take m xs) ++ reverse (drop m xs) | ||
| otherwise = reverse (take m xs) ++ [xs !! m] ++ reverse (drop (m + 1) xs) | ||
where | ||
l = length xs | ||
m = l `div` 2 |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module Kyu6.InsideOutSpec where | ||
|
||
import Kyu6.InsideOut | ||
import Test.Hspec | ||
|
||
spec :: Spec | ||
spec = do | ||
describe "Inside Out Strings" $ do | ||
it "Basic tests" $ do | ||
insideOut "man i need a taxi up to ubud" `shouldBe` "man i ende a atix up to budu" | ||
insideOut "what time are we climbing up the volcano" `shouldBe` "hwta item are we milcgnib up the lovcona" | ||
insideOut "take me to semynak" `shouldBe` "atek me to mesykan" |