day 4: alternate solution

Signed-off-by: Amneesh Singh <natto@weirdnatto.in>
This commit is contained in:
2024-12-04 15:15:02 +05:30
parent 1dc5135987
commit ca69182e55
3 changed files with 47 additions and 1 deletions

View File

@@ -1,6 +1,6 @@
module AoC where
import Data.List (transpose)
import Data.List (tails, transpose)
import Text.Parsec (ParseError)
-- extract Right value after parsing
@@ -27,3 +27,7 @@ findSubstrings sub str = findSubstrings' sub str 0
findSubstrings' sub str@(x : xs) idx
| take (length sub) str == sub = idx : findSubstrings' sub xs (idx + 1)
| otherwise = findSubstrings' sub xs (idx + 1)
-- get all subarrays of size n
subArrays :: Int -> [[a]] -> [[[a]]]
subArrays n xss = [[take n t | t <- tails xs] | xs <- xss]