diff --git a/2024/day-8/input b/2024/day-8/input new file mode 100644 index 0000000..bed6704 --- /dev/null +++ b/2024/day-8/input @@ -0,0 +1,50 @@ +..........K........................A.............. +.K................................A............... +......................................D.....A..... +....................................6............D +.................................................. +.............................d.................... +.........4.e.......................DT.B........... +....................d.....D......A...........B.... +.............K.................................... +...........................k...................... +...w..............4.....................y......... +........w......................................... +..............g..k..............d..........y...... +.....w.....Q..............................T....... +...............b..........k................6...... +.................................W...T............ +................w..............BW..T.............. +............g....4e.....................W......... +.......1.................g.......................W +........k..........................6.....0........ +.................a................................ +....................4.a........3.g..............7. +.............m........................I.0......... +..............K7..............V................... +....Q................................I............ +..9........b......................I............... +...................d.............................. +.......e.......................................... +....e...........t..E................3............. +......1..aQ........t....v.....3..........I..0..... +...........................v.t.....3.7............ +..........i.......m........M...................... +...Q..29..a...................m................... +...9......q..........mt........................... +....1...............Y.....M.........7............. +..........b..1...E.v..Y........................... +................v..........q...............0...... +..................E.................5............. +9...i..2b................................8........ +.....q..2............Y..M......................... +............q...............................V..... +...i.................................V............ +.i..............E............M.................... +.........................................G........ +............8................Y.................... +.........2................8..............5........ +......................................5....V...... +............................................G..... +.....................................5...........G +.................................8................ diff --git a/2024/day-8/solution-1.sh b/2024/day-8/solution-1.sh new file mode 100644 index 0000000..6ea2755 --- /dev/null +++ b/2024/day-8/solution-1.sh @@ -0,0 +1,60 @@ +#!/usr/bin/env bash + +FILE=input +LEN=$( head -1 "$FILE" | sed -E 's/(.)/\1\ /g' | awk '{printf NF}' ) + +read -r -a MAP_ARRAY <<< "$( < "$FILE" sed -E 's/(.)/\1\ /g' | paste -s -d ' ' )" +read -r -a SHADOW_ARRAY <<< "$( < "$FILE" sed -E 's/(.)/\1\ /g' | paste -s -d ' ' )" +#printf "MAP_LEN: %s, NF: %s\n" "${#MAP_ARRAY[@]}" "$LEN" >&2 + +for CHAR in $( < "$FILE" grep -Eo '[^\.]' | sort -u | paste -s -d' ' ) +do + # Get indices for antennae + LINE="$( + for (( i=0; i<${#MAP_ARRAY[@]}; i++ )) + do + if [[ ${MAP_ARRAY[i]} == "$CHAR" ]] + then + printf "%s " "$i" + fi + done + )" + printf "%s\n" "$LINE" >&2 + read -r -a IDX_ARRAY <<< "$LINE" + #printf "idx: %s " "${IDX_ARRAY[@]}" >&2 + #printf "\n" >&2 + + # Get all combinations + for (( i=0; i<${#IDX_ARRAY[@]}-1; i++ )) + do + A=${IDX_ARRAY[i]} + for (( j=i+1; j<${#IDX_ARRAY[@]}; j++ )) + do + B=${IDX_ARRAY[j]} + DIFF=$(( B - A )) + HEAD=$(( A - DIFF )) + TAIL=$(( B + DIFF )) + printf "char: %s, i: %s, j: %s, DIFF: %s, HEAD: %s, TAIL: %s\n" "$CHAR" "$A" "$B" "$DIFF" "$HEAD" "$TAIL" >&2 + for VALUE in $HEAD $TAIL + do + if [[ $VALUE -gt ${#MAP_ARRAY[@]} ]] || [[ $VALUE -lt 0 ]] + then + continue + fi + SHADOW_ARRAY[VALUE]=X # Mark on shadow map + done + done + done + unset IDX_ARRAY + +done +COUNT=0 +for (( i=0; i<${#SHADOW_ARRAY[@]}; i++ )) +do + if [[ ${SHADOW_ARRAY[i]} == "X" ]] + then + (( COUNT++ )) + fi +done +printf "%s\n" "$COUNT" +printf "%s" "${SHADOW_ARRAY[@]}" | fold -w "$LEN" | sed -E 's/(.)/\1\ /g' diff --git a/2024/day-8/test-input b/2024/day-8/test-input new file mode 100644 index 0000000..78a1e91 --- /dev/null +++ b/2024/day-8/test-input @@ -0,0 +1,12 @@ +............ +........0... +.....0...... +.......0.... +....0....... +......A..... +............ +............ +........A... +.........A.. +............ +............