2021-10-14

Logic and lists practice: isEverywhere.

The isEverywhere function takes in a list of integers (xs) and a single integer (n) and returns true if the number n appears at least once in every pair of adjacent numbers in xs.

Examples:

isEverywhere :: [Int] -> Int -> Bool
isEverywhere [1,3,4] 3 == True
isEverywhere [3,1,4] 3 == False
isEverywhere [3,1,1,3] 3 == False
isEverywhere [7] 3 == True 

The last one is kind of weird - “logically”, if there are no adjacent pairs then “every one” has a 3. If the answer were False then you would have to be able to show a pair of adjacent numbers without a three… but you can’t, there aren’t any.

Advice: if you are writing by hand, isE is a good abbreviation.

Last modified August 18, 2023: 2022-2023 End State (7352e87)