diff options
author | William Carroll <wpcarro@gmail.com> | 2020-08-12T11·03+0100 |
---|---|---|
committer | William Carroll <wpcarro@gmail.com> | 2020-08-12T11·03+0100 |
commit | bba3f16c43d9cad6ec92cbdfbfe69703701319bc (patch) | |
tree | df1a9be753c67ae46763bc57b95ab838100a9cd6 /scratch/brilliant/App.hs | |
parent | f11b91c985f95b585820200d0bca5b043fb9f887 (diff) |
Prefer snake-shift instead of a row-by-row shift
Per the assignment's instructions, the `Shift n` operation should treat the *entire keyboard* like a cycle and shift that. I was erroneously treating *each row* like a cycle and shifting those one-by-one. This change fixes that. In addition, it also: - Updates README.md with expected inputs and outputs - Updates test suite - Adds `split` dependency to {default,shell}.nix
Diffstat (limited to 'scratch/brilliant/App.hs')
-rw-r--r-- | scratch/brilliant/App.hs | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/scratch/brilliant/App.hs b/scratch/brilliant/App.hs index bf39de4997ad..0272988f371c 100644 --- a/scratch/brilliant/App.hs +++ b/scratch/brilliant/App.hs @@ -7,14 +7,31 @@ import Utils ((|>)) import qualified Data.Char as Char import qualified Utils +import qualified Data.List.Split as Split import qualified Keyboard import qualified Data.HashMap.Strict as HM -------------------------------------------------------------------------------- transform :: Keyboard -> Transform -> Keyboard -transform (Keyboard xs) HorizontalFlip = xs |> fmap reverse |> Keyboard -transform (Keyboard xs) VerticalFlip = xs |> reverse |> Keyboard -transform (Keyboard xs) (Shift n) = xs |> fmap (Utils.rotate n) |> Keyboard + +transform (Keyboard xs) xform = + case xform of + HorizontalFlip -> + xs + |> fmap reverse + |> Keyboard + + VerticalFlip -> + xs + |> reverse + |> Keyboard + + Shift n -> + xs + |> concat + |> Utils.rotate n + |> Split.chunksOf 10 + |> Keyboard retypePassage :: String -> Keyboard -> Maybe String retypePassage passage newKeyboard = |