summaryrefslogtreecommitdiff
path: root/4-kyu/snail.hs
diff options
context:
space:
mode:
authorMistivia <i@mistivia.com>2025-04-24 17:58:50 +0800
committerMistivia <i@mistivia.com>2025-04-24 17:58:50 +0800
commitbe451eb174f33b93afa2d1685129033c55fc632f (patch)
tree36b568e17d39e7ca3594b002044cba03111e31e1 /4-kyu/snail.hs
parentda0b3584bc6dea9f02b9ddb949dbf8f404228a1a (diff)
refactor
Diffstat (limited to '4-kyu/snail.hs')
-rw-r--r--4-kyu/snail.hs17
1 files changed, 7 insertions, 10 deletions
diff --git a/4-kyu/snail.hs b/4-kyu/snail.hs
index 20512e0..d2bacdc 100644
--- a/4-kyu/snail.hs
+++ b/4-kyu/snail.hs
@@ -4,11 +4,8 @@ module Snail where
snail :: [[Int]] -> [Int]
snail [] = []
-snail arr = foldl1 (++) $ map (roundAt w h arr) [0..center]
- where
- w = length (arr !! 0)
- h = length arr
- center = min (w `div` 2) (h `div` 2)
+snail arr = foldl1 (++) $ map (roundAt n arr) [0..(n `div` 2)]
+ where n = length arr
rowRange col from to arr =
drop from $ take (to+1) $ arr !! col
@@ -16,8 +13,8 @@ rowRange col from to arr =
colRange row from to arr =
map (!!row) $ drop from $ take (to+1) arr
-roundAt w h arr x =
- (rowRange x x (w-x-1) arr) ++
- (colRange (w-x-1) (x+1) (h-x-1) arr) ++
- (reverse $ rowRange (h-x-1) x (w-x-2) arr) ++
- (reverse $ colRange x (x+1) (h-x-2) arr)
+roundAt n arr x =
+ (rowRange x x (n-x-1) arr) ++
+ (colRange (n-x-1) (x+1) (n-x-1) arr) ++
+ (reverse $ rowRange (n-x-1) x (n-x-2) arr) ++
+ (reverse $ colRange x (x+1) (n-x-2) arr)