Created
December 27, 2025 00:00
-
-
Save kirkegaard/1f6e0695dd97c000a8e952728af8e774 to your computer and use it in GitHub Desktop.
cassidoo #436
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "fmt" | |
| ) | |
| var sequences = [][]int{ | |
| []int{}, | |
| []int{1}, | |
| []int{1, 1}, | |
| []int{1, 2, 1}, | |
| []int{10, 5, 10, 5, 10}, | |
| []int{2, 2, 3, 3}, | |
| []int{5, 4, 3, 5, 4, 3}, | |
| } | |
| func isAlternating(sequence []int) bool { | |
| if len(sequence) < 2 { | |
| return true | |
| } | |
| for i, value := range sequence { | |
| if value != sequence[i%2] { | |
| return false | |
| } | |
| } | |
| return true | |
| } | |
| func main() { | |
| for _, sequence := range sequences { | |
| fmt.Println(isAlternating(sequence)) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment