Improve code

This commit is contained in:
2024-12-06 19:55:10 +01:00
parent a94312463b
commit 1b5a8ee458
3 changed files with 9 additions and 11 deletions

View File

@ -2,9 +2,9 @@ import Data.List (sort, inits, tails)
isSafe :: [Int] -> Bool
isSafe xs = (isAscending xs || isDescending xs) && maximum distances <= 3 && minimum distances >= 1
where isAscending xs = xs == sort xs
where isAscending xs = xs == sort xs
isDescending xs = xs == reverse (sort xs)
distances = map abs $ zipWith (-) xs (tail xs)
distances = map abs $ zipWith (-) xs (tail xs)
removeLevel :: [Int] -> [[Int]]
removeLevel xs = zipWith (++) ys zs