-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
60 lines (50 loc) · 1.72 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
project(day06)
cmake_minimum_required(VERSION 3.17)
file(READ resources/input.txt raw_input)
string(STRIP "${raw_input}" input)
string(LENGTH "${input}" length)
function(find_position_past_window)
set(options "")
set(one_value_args OUTPUT WINDOW_LENGTH)
set(multi_value_args "")
cmake_parse_arguments(ARG "${options}" "${one_value_args}" "${multi_value_args}" ${ARGN})
set(window_length "${ARG_WINDOW_LENGTH}")
math(EXPR window_preend "${window_length} - 2")
math(EXPR window_end "${window_length} - 1")
math(EXPR end "${length} - 1")
foreach(i RANGE "${end}")
string(SUBSTRING "${input}" "${i}" "1" char)
# Update window of last ${WINDOW_LENGTH} chars
foreach(j RANGE "${window_preend}")
math(EXPR next "${j} + 1")
set("last_${j}" "${last_${next}}")
endforeach()
set("last_${window_end}" "${char}")
# Check if window is distinct
if("${i}" GREATER_EQUAL "${window_end}")
set(found_window ON)
foreach(j1 RANGE "${window_preend}")
math(EXPR next "${j1} + 1")
foreach(j2 RANGE "${next}" "${window_end}")
if("${last_${j1}}" STREQUAL "${last_${j2}}")
set(found_window OFF)
break()
endif()
endforeach()
if(NOT "${found_window}")
break()
endif()
endforeach()
# Print position past end of window if a distinct window was found
if("${found_window}")
math(EXPR result "${i} + 1")
set("${ARG_OUTPUT}" "${result}" PARENT_SCOPE)
break()
endif()
endif()
endforeach()
endfunction()
find_position_past_window(OUTPUT part1 WINDOW_LENGTH 4)
find_position_past_window(OUTPUT part2 WINDOW_LENGTH 14)
message("Part 1: ${part1}")
message("Part 2: ${part2}")