3 Komitmen 5347f18e3e ... fff9981a4f

Pembuat SHA1 Pesan Tanggal
  metya fff9981a4f day9 go)) 1 tahun lalu
  metya bc4214a101 day 8 go)) 1 tahun lalu
  metya b10cc8f301 day 7 go)) 1 tahun lalu

+ 1 - 1
aoc2024/aocutils.py

@@ -86,7 +86,7 @@ def bench(part):
 
 
 if __name__ == "__main__":
-    day = 6
+    day = 9
     root = os.path.dirname(__file__)
     task_dir = os.path.join(root, f"day{day}")
     generate_readme(task_dir, day)

+ 1 - 1
aoc2024/day1/day1.go

@@ -1,4 +1,4 @@
-package day1
+package main
 
 import (
 	"bufio"

+ 5 - 0
aoc2024/day6/day6.go

@@ -35,6 +35,7 @@ func main() {
 
 	startX, startY, direction := findStart(grid)
 
+	// part 1
 	start := time.Now()
 	_, visited := simulate(grid, startX, startY, direction)
 	lenv := make(map[[2]int]bool)
@@ -42,9 +43,12 @@ func main() {
 		lenv[[2]int{x[0], x[1]}] = true
 	}
 	part1_time := time.Since(start)
+
+	// part 2
 	start = time.Now()
 	loopPositions := findLoopObstacles(grid, [3]int{startX, startY, directionIndex(direction)}, visited)
 	part2_time := time.Since(start)
+
 	fmt.Println("Visited Distinct Positions:", len(lenv), "in time:", part1_time)
 	fmt.Println("Loop Positions:", len(loopPositions), "in time:", part2_time)
 }
@@ -95,6 +99,7 @@ func simulate(grid []string, startX, startY int, direction string) (bool, map[[3
 
 		if grid[nextY][nextX] == '#' {
 			direction = turnRight[direction]
+			continue
 		} else {
 			x, y = nextX, nextY
 		}

+ 72 - 0
aoc2024/day7/README.md

@@ -0,0 +1,72 @@
+--- Day 7: Bridge Repair ---
+----------------------------
+
+The Historians take you to a familiar [rope bridge](/2022/day/9) over a river in the middle of a jungle. The Chief isn't on this side of the bridge, though; maybe he's on the other side?
+
+
+When you go to cross the bridge, you notice a group of engineers trying to repair it. (Apparently, it breaks pretty frequently.) You won't be able to cross until it's fixed.
+
+
+You ask how long it'll take; the engineers tell you that it only needs final calibrations, but some young elephants were playing nearby and *stole all the operators* from their calibration equations! They could finish the calibrations if only someone could determine which test values could possibly be produced by placing any combination of operators into their calibration equations (your puzzle input).
+
+
+For example:
+
+
+
+```
+190: 10 19
+3267: 81 40 27
+83: 17 5
+156: 15 6
+7290: 6 8 6 15
+161011: 16 10 13
+192: 17 8 14
+21037: 9 7 18 13
+292: 11 6 16 20
+
+```
+
+Each line represents a single equation. The test value appears before the colon on each line; it is your job to determine whether the remaining numbers can be combined with operators to produce the test value.
+
+
+Operators are *always evaluated left-to-right*, *not* according to precedence rules. Furthermore, numbers in the equations cannot be rearranged. Glancing into the jungle, you can see elephants holding two different types of operators: *add* (`+`) and *multiply* (`*`).
+
+
+Only three of the above equations can be made true by inserting operators:
+
+
+* `190: 10 19` has only one position that accepts an operator: between `10` and `19`. Choosing `+` would give `29`, but choosing `*` would give the test value (`10 * 19 = 190`).
+* `3267: 81 40 27` has two positions for operators. Of the four possible configurations of the operators, *two* cause the right side to match the test value: `81 + 40 * 27` and `81 * 40 + 27` both equal `3267` (when evaluated left-to-right)!
+* `292: 11 6 16 20` can be solved in exactly one way: `11 + 6 * 16 + 20`.
+
+
+The engineers just need the *total calibration result*, which is the sum of the test values from just the equations that could possibly be true. In the above example, the sum of the test values for the three equations listed above is `*3749*`.
+
+
+Determine which equations could possibly be true. *What is their total calibration result?*
+
+
+--- Part Two ---
+----------------
+
+The engineers seem concerned; the total calibration result you gave them is nowhere close to being within safety tolerances. Just then, you spot your mistake: some well-hidden elephants are holding a *third type of operator*.
+
+
+The [concatenation](https://en.wikipedia.org/wiki/Concatenation) operator (`||`) combines the digits from its left and right inputs into a single number. For example, `12 || 345` would become `12345`. All operators are still evaluated left-to-right.
+
+
+Now, apart from the three equations that could be made true using only addition and multiplication, the above example has three more equations that can be made true by inserting operators:
+
+
+* `156: 15 6` can be made true through a single concatenation: `15 || 6 = 156`.
+* `7290: 6 8 6 15` can be made true using `6 * 8 || 6 * 15`.
+* `192: 17 8 14` can be made true using `17 || 8 + 14`.
+
+
+Adding up all six test values (the three that could be made before using only `+` and `*` plus the new three that can now be made by also using `||`) produces the new *total calibration result* of `*11387*`.
+
+
+Using your new knowledge of elephant hiding spots, determine which equations could possibly be true. *What is their total calibration result?*
+
+

+ 105 - 0
aoc2024/day7/day7.go

@@ -0,0 +1,105 @@
+package main
+
+import (
+	"bufio"
+	"flag"
+	"fmt"
+	"os"
+	"strconv"
+	"strings"
+	"time"
+)
+
+func main() {
+	args := flag.Bool("example", false, "example or input")
+	flag.Parse()
+	filename := "input.txt"
+	if *args {
+		filename = "example.txt"
+	}
+	file, err := os.Open(filename)
+	if err != nil {
+		fmt.Println(err)
+		return
+	}
+	defer file.Close()
+	scanner := bufio.NewScanner(file)
+	var equations []Equation
+	for scanner.Scan() {
+		line := strings.TrimSpace(scanner.Text())
+		equations = append(equations, parseEquation(line))
+	}
+
+	if err := scanner.Err(); err != nil {
+		fmt.Println(err)
+		return
+	}
+
+	// part 1
+	start := time.Now()
+	totalSum := 0
+	for _, eq := range equations {
+		if checkOperators(eq.numbers, eq.testValue, 0, eq.numbers[0], false) {
+			totalSum += eq.testValue
+		}
+	}
+	end1 := time.Since(start)
+
+	// part2
+	start = time.Now()
+	totalSumWithMerged := 0
+	for _, eq := range equations {
+		if checkOperators(eq.numbers, eq.testValue, 0, eq.numbers[0], true) {
+			totalSumWithMerged += eq.testValue
+		}
+	}
+	end2 := time.Since(start)
+
+	fmt.Println("Total Sum:", totalSum, "with time:", end1)
+	fmt.Println("Total Sum With Merged:", totalSumWithMerged, "with time:", end2)
+}
+
+type Equation struct {
+	testValue int
+	numbers   []int
+}
+
+func parseEquation(line string) Equation {
+	parts := strings.Split(line, ":")
+	testValue, _ := strconv.Atoi(strings.TrimSpace(parts[0]))
+	numberStrings := strings.Fields(parts[1])
+	var numbers []int
+	for _, num := range numberStrings {
+		n, _ := strconv.Atoi(num)
+		numbers = append(numbers, n)
+	}
+	return Equation{testValue: testValue, numbers: numbers}
+}
+
+func checkOperators(numbers []int, target int, index int, currentValue int, merge bool) bool {
+	if index == len(numbers)-1 {
+		return currentValue == target
+	}
+
+	nextNumber := numbers[index+1]
+
+	// +
+	if checkOperators(numbers, target, index+1, currentValue+nextNumber, merge) {
+		return true
+	}
+
+	//  *
+	if checkOperators(numbers, target, index+1, currentValue*nextNumber, merge) {
+		return true
+	}
+
+	// ||
+	if merge {
+		merged, _ := strconv.Atoi(fmt.Sprintf("%v%v", currentValue, nextNumber))
+		if checkOperators(numbers, target, index+1, merged, merge) {
+			return true
+		}
+	}
+
+	return false
+}

+ 0 - 0
aoc2024/day7/day7.py


+ 9 - 0
aoc2024/day7/example.txt

@@ -0,0 +1,9 @@
+190: 10 19
+3267: 81 40 27
+83: 17 5
+156: 15 6
+7290: 6 8 6 15
+161011: 16 10 13
+192: 17 8 14
+21037: 9 7 18 13
+292: 11 6 16 20

+ 850 - 0
aoc2024/day7/input.txt

@@ -0,0 +1,850 @@
+432832280199: 3 286 4 3 17 682 7 7 9 2
+6606690226623: 605 42 3 47 26 6 622
+4920367: 8 8 896 6 4 955 9 44 6 9
+221825533: 124 5 714 905 66 5 33
+1454747930: 632 499 1 23 3
+702832: 69 7 4 927 908
+2378257360: 35 802 27 897 74
+36705240: 8 8 92 9 1 230 22 62
+30034422624: 8 7 8 96 9 99 2 310 314
+21776455040: 1 530 181 9 6 16 4 227
+17354: 3 4 49 63 6 5
+735393206: 2 44 647 39 3 204
+1093907608: 6 54 66 45 18 709 4 4
+11174: 15 8 9 79 74
+7621599: 18 679 374 78 4 87
+883869: 755 226 1 9 69
+887022: 69 812 6 10 22
+47579515: 988 9 8 891 6 9 7 85 8 6
+16995: 2 4 24 88 94 5
+135322472248: 6 89 4 5 69 631 9 566 5
+254597011: 751 9 356 941 41 10
+4515529: 29 2 21 1 926 4 291 62
+97745351289: 8 6 1 479 2 54 5 3 536 9
+1775421281: 9 494 27 3 493 5 6 42
+56481955: 35 2 6 341 1 81 945 9
+27440: 836 454 82 2 10
+3752: 16 1 723 4 5 4 8 5 1 9 6
+440254803958: 536 1 976 8 61 7 6 2 60
+496630: 1 85 2 32 94 7 44 2
+3755: 8 5 627 84 5
+8640: 57 677 7 339 8
+926112: 3 7 7 5 7 5 1 6 4 3 96 11
+1767658122089: 2 6 37 9 814 6 915 92
+34703414070: 33 7 5 4 4 6 341 3 9 1 7 1
+1975962: 5 30 19 38 2 962 14
+3087257: 344 4 92 191 846 7
+523063: 602 867 476 32 621
+477001448: 887 97 924 6 645 587
+37524240957: 1 9 5 2 5 312 844 1 94 8
+408480981: 3 694 876 2 138 98 1
+111455358: 3 2 1 4 4 4 1 750 803 58
+12208: 7 2 872
+18118: 6 6 1 848 21 53 5
+1923921133205: 22 6 9 9 3 8 899 2 6 2 5 4
+7316806: 6 47 366 74 1 9 6 802 6
+88262640: 9 3 1 7 338 32 8 5 4 6 5 8
+3436366: 5 5 843 7 163
+808033608: 9 48 886 100 2 1 8
+6090016667019: 600 145 23 76 5 70 19
+1312964: 2 2 5 2 90 9 9 9 2 7 2 23
+709338840840: 848 683 14 7 20 729 6
+63693345: 40 1 2 3 9 8 5 46 2 682
+1569184217: 156 918 4 216 4
+670379: 4 748 14 5 5 8 1 2 1 9 1
+15343813: 852 34 18 2 105 62 6
+98348: 7 12 3 1 46 9 3 6 2 5 8 4
+222952654: 1 636 35 26 52
+11582: 3 8 108 87 97
+432735: 2 40 55 99 2 7 5 261 85
+10026: 23 9 313 10
+100398210: 75 3 5 3 2 1 9 7 2 4 921 5
+71205: 83 43 12 47 56 78 7
+15251108: 79 27 4 82 66 1 87 6
+26498477535: 943 281 1 7 718 28 7 5
+301625289: 4 4 1 2 2 4 4 50 9 909 69
+382453972: 3 2 460 2 7 4 6 6 1 7 97 3
+372227: 6 1 664 16 59 5 92
+4803730: 17 463 358 6 143
+886: 3 295 46 99 2
+883866816720: 9 120 92 4 5 7 706 8 90
+10138: 122 75 78 813 97
+114252: 27 1 56 3 4
+136239649003: 650 930 299 350 2
+848541256: 8 485 412 57
+42556158: 1 6 5 9 1 8 2 7 802 6 20 1
+8742867: 9 37 84 7 43 8 39
+33930067: 33 9 2 92 99 685 84
+5488712358: 767 976 67 114 47
+105178767: 4 6 234 2 661 612 447
+1637496039: 2 133 5 180 76 4 9
+17387600: 8 8 330 59 42 850
+1666608: 33 6 3 5 8 4 62 2 4 31 9
+58568068: 5 9 3 7 270 8 4 5 2 5 604
+292643: 57 4 8 47 547
+197450: 4 853 15 37 57
+179947246: 4 1 5 97 2 267 2 7 247
+4048683: 7 4 4 92 685
+884: 49 81 85 19 61 73 516
+1461525800: 2 1 9 558 2 978 13 5 4 2
+103608237: 719 16 8 9 240
+177642816: 139 7 2 9 6 9 9 3 97 5 14
+2032: 78 254 7 6 1
+2606: 64 49 7 872 595
+13150264803: 460 1 763 1 93 1 6 9 67
+3216407038: 71 3 63 28 80 308
+491918366: 680 574 8 7 1 5 7 7 6 5 7
+6666003: 50 4 66 5 101
+3643643828708: 7 8 781 1 1 46 5 93 6 5 7
+5616: 8 50 39 8 19 12 24
+1160101302304: 7 16 7 4 5 90 651 2 304
+69358342: 228 78 19 39 1
+2243865: 66 382 89
+13885270: 20 740 261 1 2 7 5
+1964: 76 571 2 320 906 89
+1201365316: 4 547 65 18 8 502 59
+11183474: 7 6 3 2 1 2 5 861 5 37 9 2
+9805064356: 59 7 9 23 9 981 6 43 56
+5379004: 6 3 9 48 5 70 44 5 3
+6780200: 699 6 9 7 17 7 52 4 35 5
+644944896: 93 2 692 844 49
+1126: 196 20 91 332 480 7
+58697192: 5 1 11 22 8 386 9 54 2
+2662543: 261 8 44 2 2 32 3
+1237124456: 26 30 71 1 387 12 67 8
+118982845659: 894 6 7 55 5 38 6 59
+414521: 8 9 806 475 680 7 212
+793530: 3 70 6 35 30
+5482277663235: 99 3 826 723 2 582 9
+298419548: 70 609 1 1 22 7 800 2 4
+1093820: 546 84 2 68 2
+5528901894428: 42 53 650 94 7 2 428
+46926668: 69 68 6 6 70
+18167353: 9 3 58 31 4 3 91 2 7 96 5
+64812892992: 9 251 7 98 471 3 7
+893878: 6 6 3 865 2 30 573
+663008: 74 5 83 45 31 8
+8656256818: 6 8 3 3 2 7 719 450 9 13
+52533: 74 8 79 91 2 205 463
+123918: 295 877 66 91 18 7 1
+7409: 3 8 2 5 8 4 9 3 4 7 15 384
+3780854221: 4 50 70 854 218
+532715: 24 739 30 7 628
+2393277: 1 3 6 19 225 47 2 19
+22845915: 4 299 5 3 3 53 465
+1800929500: 281 58 2 221 2 250
+86801765409: 504 8 1 53 2 573 3 30 6
+1158536: 5 23 8 42 8 5 21 7
+1903048: 87 2 211 251 49
+8946: 1 717 3 86 4
+2945: 6 50 27 9
+297145857377: 84 7 38 797 7 8 510 18
+334655: 4 65 990 316 2 9
+14667151140616: 90 5 3 797 81 5 4 617
+29948: 50 33 3 9 97 2
+138683011680: 354 577 5 8 943 2 9
+27571975550: 5 8 694 6 763 37 4 8 8
+9361: 7 2 661 92 15
+69168942: 8 1 7 6 2 14 708 54 921
+51333995121324: 6 4 166 6 8 939 8 1 322
+266693441: 89 23 367 355 46
+296253094: 46 2 895 4 32 18 2
+315638681336: 76 23 46 51 641 4 93 9
+28548444: 4 7 5 484 44
+3280661850375: 129 2 39 6 19 125 651
+35166: 17 197 935 8 894
+85957393564: 5 8 9 3 20 6 89 206 7 9 3
+31684500: 86 26 9 8 7 4 1 9 7 450 4
+6623374: 65 48 8 67 371
+19268534: 84 28 555 3 715
+222: 38 9 80 58 34
+78948746425: 823 7 571 3 28 2 3 8
+269131: 7 47 816 667
+4894: 7 940 65 34 4 708 1
+107978313: 7 84 7 66 9 647 198
+1464427: 21 2 315 71 9 61
+170: 7 96 67
+43236: 3 603 3 7 796
+894: 5 6 3 4 848 9
+9946270231369: 8 6 6 7 678 7 3 23 13 72
+5200: 1 9 520
+3398946: 854 796 5 5
+30631535240: 859 38 112 7 935 240
+143158780992: 1 85 21 356 24 1 21 6 7
+2710503: 55 66 3 746 285
+72913514: 728 383 750 4 8 9 2
+1062919217: 4 36 9 310 3 7 8 838 1 8
+4105307258: 873 1 1 95 5 495 7
+4958819785716: 495 881 978 1 4 718
+150073: 5 95 6 312 1
+3041636: 703 115 4 754 7 1 754
+102821262: 962 66 2 12 62
+6557: 43 293 16 949 232
+4320016095: 3 8 5 7 9 52 2 2 81 3 21 3
+6455: 1 1 58 12 7 9
+319102: 3 31 964 14 7
+10428: 25 93 1 4 53
+106990505: 2 1 1 483 4 726 1 3 37 8
+130510: 16 80 135 90 7
+37568316247: 12 546 7 56 640 819 5
+12974091: 11 91 8 7 162
+296259769479: 6 85 786 5 3 2 4 8 2 6 3 1
+9841: 87 89 32 47 2 32 31
+66579240: 3 4 8 775 84 910
+506160: 79 157 4 57 37
+301415161: 39 61 8 34 2 5 88 76 71
+38884404169: 9 7 2 4 440 396 7 4 9 92
+339908: 1 8 6 345 678 2 45 3 7 2
+44162: 3 9 3 2 2 5 7 577 254 56
+79745325: 3 59 2 6 7 1 74 21 46 5
+170532: 981 1 715 7 70 59
+906279: 7 5 9 903 957
+894: 100 1 2 4 5 81
+1251475866101: 899 16 78 87 6 101
+123282: 8 40 55 7 82
+889: 99 15 1 772 2
+63758769: 89 85 5 59 9 842
+197163805: 4 4 71 58 90 3 3 11 7 5 5
+5486251526: 54 862 50 616 910
+2181492: 4 134 62 45 9 3 1 3 7 9 9
+2220: 87 51 201 31 6
+1741009043: 95 7 7 83 9 36 8 6 9 1 4 3
+365355: 1 976 709 19 57 4 207
+1646817134: 4 3 878 39 8 67 9 2 1
+2963977: 6 94 6 99 413 7 5 694 8
+444262: 15 90 875 2 5 6 6 9 4
+25782433: 431 4 1 644 2 3 260 53
+22149558288: 337 65 6 754 87
+245330: 929 4 66 2 69
+1740876747120: 2 757 560 5 7 388 84 9
+528155: 528 151 1
+94211456: 61 98 152 9 9 57
+729: 6 6 7 37 650
+2141237035: 16 6 35 214 67 1 114
+11021: 894 6 512 947 618
+19448400: 5 5 8 6 123 909 4 5 853
+43421964715: 74 5 9 2 273 5 9 9 3 2 13
+10516: 105 12 2
+468364: 5 3 635 600 3 55 36 1 4
+2540126162: 64 4 5 2 23 550 11 990
+135498636: 1 32 72 7 6 897 884 9
+427119: 5 7 21 77 3 7 33
+1375547: 2 24 7 10 54 51 3 7 47
+75126: 268 5 381 97 26
+259534: 471 46 502
+14751899: 88 603 278 96 3 4 4
+71821: 2 897 5 8 2 9 7 4 8 2 26 3
+2420180: 9 87 84 1 3 3 15 62
+19366073422: 727 104 876 6 97 3 6 4
+208: 175 4 29
+19699187203: 2 7 3 7 4 920 869 2 1 8 1
+299381540: 892 4 839 263 43
+5905: 94 6 9 17 5
+40980: 5 2 85 712 31 9 2 38 15
+763521536: 7 53 6 5 1 2 985 7 1 536
+90148425: 3 60 29 685 5
+1042650727: 18 5 9 16 3 68 7 90 725
+687149613: 8 1 748 1 8 9 1 126 4 9 9
+610288140226: 3 8 42 339 1 5 22 6 22 3
+22219924867: 3 9 5 2 1 31 43 9 1 378 5
+411774419: 11 392 8 75 3 21 417
+1243870: 3 871 6 153 4 4 5 27 2 1
+462: 61 43 8 295 58
+33704322: 7 114 95 9 1 91 74 47 6
+77185690: 3 2 3 3 8 9 1 5 1 568 9 3
+13513860: 20 57 329 2 323 4 9
+9854895592: 6 448 964 575 8 191
+33025307: 3 5 5 5 7 4 5 1 25 30 3 1
+3074116: 306 3 33 50 75 4 2 2
+1571679: 876 896 730 214 2
+26026894310083: 9 7 36 96 33 284 9 4 9 4
+1007443822: 79 6 6 365 902 6 24
+921502367508: 337 513 8 750 1 533 5
+431623411: 4 27 27 70 4 138 259
+383212: 2 3 5 59 1 1 299 9 6 3 4 4
+7085596237: 15 8 1 6 8 4 88 471 9 1
+307411248: 96 593 54 44 4
+80556139: 85 77 34 362 7 272
+79307589: 943 6 83 540 590
+6862467: 46 363 5 148 2
+11721: 6 38 5 9 5 308
+11303: 4 36 25 145 125 136
+565675358: 9 18 303 616 710
+1787: 1 35 44 47 8 185 5 2
+62655: 8 89 6 7 3 4
+10351: 40 257 72
+769438725: 213 6 7 55 19 573
+7734600: 6 4 2 4 6 341 1 42 6 5 3 1
+49563394: 32 396 67 63 391
+7759584: 137 899 5 9 7
+47816: 2 9 868 5 76
+2433: 988 616 504 13 314
+1664184: 7 28 676 791 8 3 83
+52310: 67 2 758 1 6 1
+14592532882: 29 592 23 2 7 95 3 389
+20696505527: 3 757 6 550 55 2 5
+226929066199: 49 5 59 8 777 200 1
+257629316264: 652 419 13 82 943 4
+13341918: 3 171 3 41 8 6 3 6 1 83 6
+5160685056: 4 43 1 428 31 6 89 256
+277973946: 336 938 25 3 33
+133578712: 98 3 73 203 8 9 5 7 12
+980922: 1 4 968 4 9 3 1 6 7 909 2
+2530432: 9 2 3 5 508 641 848
+250334206638949: 6 9 907 551 65 97 37 4
+432123: 1 720 2 6 3
+283210364: 4 39 337 7 1 99 66 668
+43774: 12 9 71 330 86
+98806776: 96 2 80 6 773
+156551: 3 965 54 6 213
+12405992: 9 368 99 967 81 8 4
+81584: 92 723 87
+15240: 64 93 97 2 9
+621828109: 713 969 9 208 11
+954205531: 5 949 20 5 534
+483073296: 4 12 30 728 4 95
+775228139: 775 189 4 2 8 323 39
+558: 2 7 3 44 467 5
+12816672723: 1 931 8 458 241 3
+2814754: 9 77 8 7 405 7
+16136760710: 9 6 7 11 3 76 508 8 2 69
+193583: 469 1 4 1 58 8 1
+143886023540: 9 4 7 3 2 3 77 696 6 3 9 9
+1219284712: 5 1 203 978 306 1 713
+269792: 26 872 8 98 9
+132838286090: 7 55 614 997 35 81 4 5
+975: 3 3 143 6 817
+4858518647: 81 8 960 93 4 3 8 71 8
+83595: 11 6 86 302 931 4 78 6
+507102: 5 5 25 3 9 489 8
+203894: 6 58 583 38 910 1 1 61
+31129188: 48 823 197 9 4
+298371: 291 7 3 74 1
+2030146944: 1 51 2 1 120 6 24 7 8 1
+278668: 7 717 6 9 8 2 1 3 2 8 6 4
+44972: 5 1 9 77 42 226 4 705
+709809: 266 7 65 1 2 3 2
+4860: 8 29 27 216 4
+619235: 22 28 3 23 2
+48897: 138 5 61 65 2 80
+331971162: 6 98 5 9 60 9 1 3 454 9 6
+11006876545: 57 583 6 937 35 2 34
+2735160: 11 1 4 46 991 4
+2702721060413: 7 65 8 1 246 6 32 26 38
+9741725: 147 21 86 2 307
+9225: 69 130 195 60
+53051282: 96 788 188 6 2
+622908: 95 749 82 4 3 3
+2288: 20 54 611 8 586 3
+119917504: 358 70 7 9 6 4 2 1 75 4 7
+16996: 2 9 4 3 75 8 6 4 2 7 145 7
+1527322: 28 735 6 61 2
+6126887: 359 30 45 4 35
+483111169: 4 83 110 421 77 7 662
+135691584: 17 584 1 244 1 632 8 7
+1243839: 3 8 81 663 7 2 2 3 2 28 2
+72217579: 8 3 87 75 81
+7873976: 7 101 64 174 42 782
+304140: 64 6 54 6 685
+254951258727239: 983 6 4 330 8 40 4 9 90
+3615: 925 814 6 46 1 2 1 31
+50535441007: 5 87 220 8 88 50 66 7
+46460429: 993 4 466 48 56 125
+763: 46 13 40 6 119
+18661544: 561 4 88 656 326
+96508: 48 2 5 1 10
+8118: 9 77 46 2 206
+243610: 7 49 87 2 5
+416721: 5 160 49 8 3
+76813467287: 95 61 6 749 6 82 88
+33088893: 40 827 8 8 95
+1704: 5 278 1 6
+34: 12 5 2
+152811855: 2 5 2 8 8 2 95 908 9 6 9
+31949018: 7 57 80 61 999
+30941722: 439 34 263 5 46 7
+606107040: 9 72 9 5 4 3 2 9 77 8 3 4
+4169300: 217 22 1 44 865 868
+27510141654513: 59 518 4 824 9 545 1 1
+245431: 35 70 5 2 378
+64504682: 776 51 7 75 5 31 22
+69526563258: 507 1 271 7 445 44
+9554853033: 9 4 9 75 10 933 30
+21739562: 615 736 266 48 74
+545640: 76 5 34 8 678 3 8 1 600
+516200: 3 5 182 34 9
+70845097: 3 40 655 9 6 8 4 4 6 1 98
+3699: 39 38 48 3 1
+45868029276: 359 86 215 8 8 9 6 691
+68048640: 4 5 239 2 9 8 2 720 8 22
+7168648542: 2 487 736 85 44
+52926388: 822 5 4 110 579
+20265450: 803 33 126 5 761 20
+163993250712: 379 2 4 14 6 4 3 452 1 6
+1856: 1 827 8 6 15
+28056: 3 498 14 4
+370678714: 4 5 2 2 669 8 5 4 3 5 1 1
+1297451859813: 1 46 30 199 8 680 9 68
+32983: 6 7 3 49 4
+2773567: 69 3 638 5 21 76
+26677: 6 6 22 47 164 1 62
+3030999: 39 16 774 9 3
+2067742: 4 99 2 4 2 9 4 53 4 9 5 5
+7567223: 29 7 7 8 477 4 3 6 9 25
+113047726: 240 2 636 1 74
+11114607600: 61 2 28 217 6 40 7 20 9
+29370: 72 7 6 8 5 4
+297018840: 73 5 6 2 44 26 3 8 9 34 8
+75762: 757 55 8
+808599190: 2 438 1 2 8 9 94 33 189
+160401777: 2 992 5 326 99
+24082953789: 47 4 5 14 1 3 2 52 1 61 6
+61351314: 56 6 55 98 33 52
+257626: 947 7 8 6 1 943 6 3 8 2 6
+58471611: 3 2 763 1 80 798 5 937
+267063853056: 1 735 4 8 413 858 32
+4021952: 80 2 774 44 2 29
+54301100: 1 72 6 3 7 2 86 5 7 2 77 7
+1903578: 874 242 9 2 4
+32068326: 6 7 60 571 4 6 56 3 4 1 6
+133125630: 3 92 70 5 3 855 5 66 6 5
+80059878: 1 800 53 6 881
+44864825: 21 726 91 66 5
+2255488: 6 3 41 3 9 2 9 6 2 113 6 2
+715257: 77 9 9 4 231 81
+71610765059: 1 716 10 764 853 204
+289322592: 9 928 99 513 375 8 68
+1443308384: 50 6 93 8 739 7
+388667955229: 758 7 1 4 69 77 634 95
+40236: 2 67 1 1 1 2 4 3 4 3 7 352
+51236736: 7 381 72 91 34 36 96
+5922: 4 5 73 45 30 8 49 17
+3991555993: 9 877 89 2 1 6 75 5 9 96
+2408805: 1 1 668 8 45 1 9
+41990160: 763 3 55 1 79 7 60
+98141265: 480 501 412 66
+23695819: 4 283 23 69 823
+1036: 8 11 3 1 9 443 8 7
+39787353069: 73 7 89 482 887 1 77
+1423008774445: 60 72 366 8 6 9 4 42
+1125098203: 112 509 727 93 5
+6881929513: 849 6 1 97 81 967 27 3
+18224: 1 7 8 7 32 83
+4077493: 2 458 31 6 41 285
+2330268: 35 9 616 149 12
+1341655: 72 3 8 776 234 1 493
+489831862671: 882 2 5 5 6 347 4 32 2 8
+318912393: 232 9 60 20 4 66 75 54
+107123: 15 7 9 6 1 5 6 1 1 6 3 182
+500647: 8 8 2 6 8 930 4 6 5 516 3
+1669978: 2 7 7 3 2 31 2 1 22 16 79
+107045: 626 729 79
+12008059348586: 90 57 1 6 49 3 882 8 78
+154801: 6 57 6 3 136 514 63
+21128736368: 88 724 486 2 7 29 5 14
+694986792: 7 553 4 84 1 6 496 9 24
+159642480: 43 3 3 4 862 79
+11856: 78 1 8 19
+13751: 129 8 47 1 1
+540423255: 6 5 7 54 6 544 21 7 15 1
+685860700: 7 8 10 2 688 70 890
+4256432460: 5 304 4 8 4 4 7 7 1 8 4 57
+1588: 6 5 46 3 6 7 5 9 7 8 8 4
+247146718286: 2 8 95 5 473 888 5 3 95
+164263503: 4 211 865 225 3
+7772592: 17 4 9 72 589
+301928: 803 2 188
+938385: 6 626 58 7 125 2 8 7 3 9
+2084022: 2 52 2 3 1 994 27
+107487934: 8 4 26 27 686 603 36
+406830: 1 6 9 3 191 80 2 8 5 1 6 5
+236967: 4 4 1 7 5 5 8 76 368 1 4
+467593488: 4 5 8 9 5 1 8 33 2 3 7 5
+639691: 2 7 7 383 40 17 1 6 927
+107031600: 321 3 2 5 2 7 2 6 6 9 650
+2144004: 207 4 3 400 4
+279778: 9 5 6 8 3 184 2 47 1 59
+607778218: 6 4 128 6 2 95 451 767
+4822129660: 61 7 8 8 7 52 6 7 399 7
+154555: 768 20 79 7 9 3
+342969286: 83 2 349 592 3
+493882342: 4 159 779 823 40
+1911: 648 31 8 2 537
+170421792: 67 9 932 802 3
+669122: 66 9 11 6 8
+23973225: 898 47 980 9 555
+11383749: 4 211 6 2 11 48 5 72
+618219: 37 25 544 17 6 2 7 6
+44445074487: 4 86 7 832 9 3 16 4 489
+65800800: 2 10 4 78 185 57
+1063150: 8 9 5 725 2 6 840 550
+842592: 1 5 1 141 726 536
+3974639974: 4 7 3 227 6 5 1 5 7 1 7 7
+178645534: 8 5 3 9 4 2 454 50 12 72
+274111809664: 92 61 11 8 922 7 86
+19406046: 3 45 8 267 1 3 3 1 1 3 6 6
+605648255: 64 257 19 646 3
+11247: 500 908 777 56 9 5
+644839: 85 7 7 8 39
+929374628578: 603 490 7 1 224 75 22
+14856751530: 27 360 5 543 1 29
+7177970802: 1 3 65 98 44 394 5
+7266924: 78 4 303 990 755 7 7
+1993695638: 1 55 356 956 40
+171671750923: 9 19 670 8 2 2 5 50 920
+794: 44 6 15 7 6 32
+13461: 2 35 1 7 4 1 47 3
+8423: 83 3 5 3 87
+6532569: 652 979 273 9 40
+1458739: 90 3 6 76 9 58
+38209514257: 252 4 8 6 98 763 5 5 1 4
+51816: 53 3 28 9 2 308 8 6 51 2
+816158068: 431 709 6 66 658 315
+17216796: 57 3 297 339
+1011033123: 6 22 8 1 8 956 1 9 1 4 4
+1161: 23 7 84 3 195
+2040808547773: 5 6 436 7 8 721 38 6 59
+5244643188: 9 5 58 36 2 117 39 7 3
+80733: 139 2 58
+5718345570: 2 2 5 3 7 6 1 733 6 87 7 5
+1255331: 4 580 9 77 7
+3470160: 2 29 86 233 81 97 7 10
+81903482467: 682 529 20 3 95 6 99
+23726869: 1 3 2 4 3 9 41 1 1 5 4 5
+35786016: 358 1 6 1 2 8 873 7
+903150000: 4 660 5 15 500 3 6 10
+15945758245: 7 5 368 612 69 1 937
+8695050210: 8 1 652 72 4 294 3 5 14
+141784: 32 173 61 533 6
+16353: 54 3 5 9 93
+1494962061: 9 8 52 781 834 59 2
+2344: 1 986 843 3 505 6
+124204551300: 6 75 8 8 3 2 7 1 64 1 820
+66433812649: 2 73 2 9 4 4 536 9 8 4 2 7
+12197: 53 23 7
+6666802405: 2 6 9 6 25 6 5 1 80 2 402
+909770: 1 255 653 76 7
+28303: 7 2 8 49 78
+169467: 19 27 1 330 177
+1357: 630 70 594 4 59
+8883: 9 42 4 23 97
+10711161: 90 505 750 9 39 24 9
+169794240: 657 51 948 7 704
+282: 4 35 2 2
+2654: 1 1 8 1 55 699
+1175: 702 8 226 95 142
+3989879441: 2 60 422 5 1 3 3 7 39 40
+6515016: 72 9 3 501 6
+68690572019: 842 439 522 9 356
+194517092: 974 4 90 488 2 90
+453981029160: 8 67 5 49 801 69 2 534
+5806: 11 1 560 8 8
+30276400: 979 4 50 77 8
+3338538: 1 24 20 3 12 288 7 2 28
+10686374: 597 179 71
+207907: 4 28 539 91 4 1 65
+21686422897: 5 597 3 99 5 7 7 4 8 9 8
+10722: 5 53 4 3 2 5 52 7 8 470 6
+9157: 96 3 22 860 3 11 4 7 21
+10798555: 4 5 61 7 32 71 6 829
+3498293: 35 136 92 721
+78433460: 99 4 99 786 247 2 85 8
+21: 8 1 2 1 3
+2196812286: 99 4 785 6 49 5 6 62 7 8
+17045931603: 37 87 7 2 832 8 8 9 5 1 2
+309474: 23 724 69 8 5 4 8 11 6
+11552654592: 4 731 379 18 1 3 32 72
+1315800722: 73 100 3 6 714 8
+7853298662425: 9 211 98 87 624 26
+873710: 7 43 9 995 42 5
+154896164: 5 2 2 464 8 25 6 7 87 4 2
+14773610142: 6 585 69 329 61 2 4 70
+3124270781: 60 6 4 34 1 4 1 6 7 59 3 9
+36674498: 6 2 8 86 2 414 26 410
+18039060: 5 8 5 2 593 845
+4095212: 39 280 375 35 177
+325346868: 55 8 4 891 161 9
+36632598089: 469 142 6 72 29 9 55
+4921388: 9 78 995 7 425
+13314319: 133 1 4 237 84
+11183301: 7 567 4 2 1 7 107 7 699
+421368654133: 917 9 545 429 107
+251202420: 59 96 7 7 855
+217109239: 28 196 77 3 1 6
+4668175: 4 667 90 3 273
+86870: 8 66 7 270 76
+1159106725: 5 1 6 2 5 9 3 74 3 6 9 892
+770369: 1 1 5 588 1 7 74 5 3 36 3
+307: 17 283 7
+1411741: 919 8 3 759 2 1
+1519: 2 9 8 7 206
+1267021: 18 87 4 670 53
+13879239: 387 9 4 4 6 9 994 4 2 9
+1402593: 70 5 648 4 1
+78891701332: 8 7 45 4 5 5 5 6 2 1 2 626
+63626892: 984 1 646 604 92
+1851: 5 6 5 4 12
+1075974521: 330 56 651 34 4 5
+117936991521: 390 36 28 3 30 50 8 3
+65257: 51 665 5 94 80 8 49
+15424133761: 7 413 49 1 296 844 3 4
+80415: 254 4 20 8 647 9
+142851424: 4 98 5 3 3 1 68 534 2 9 7
+547593564: 7 841 2 9 49 447 8 68 1
+1571046365: 6 6 54 70 6 6 3 6 1 2 13 3
+7427410: 91 28 62 54 47
+641920: 80 4 12 848 680
+1501683577: 2 885 634 821 688
+1113215999: 3 618 40 8 88 150 40
+50035: 7 8 4 3 6 8 1 9 7 1 5 888
+19931149: 75 857 19 31 6
+2196: 41 9 9 171 4
+5426718738: 3 9 3 9 6 63 4 922 46 4 4
+65599: 3 304 71 137 616 92 2
+176: 1 25 80 6 62
+215406574235: 651 25 6 676 7 4 3 21 3
+3278698508: 47 44 691 594 498 8
+88336024598: 8 7 7 2 6 565 74 3 460 1
+198319: 4 291 98 448 41
+7257389: 72 5 365 731 7 8
+8833: 58 28 2 3 3
+4331: 530 5 8 9 42
+98590140: 120 7 5 87 935
+205: 61 1 60 1 84
+3359182342372: 775 5 93 681 329 68
+1770: 60 4 9 7 27
+64853634878: 2 40 684 6 751 5 501 5
+3274725: 95 9 74 47 75
+4312: 3 9 2 44 7 1
+1180436500: 908 13 32 4 422 9 70
+36597654132: 416 45 169 5 4 1 52
+589165747800: 9 7 7 867 2 90 26 9 29
+696: 429 4 10 163 90
+4628408098: 9 252 2 5 2 2 55 3 2 2 85
+21266146: 49 124 7 29 5
+185239: 649 8 8 278 369
+1190293403: 421 4 8 5 3 2 9 35 325 2
+9756: 451 24 29 9 2 675 9
+347814: 5 7 7 87 9 72 339
+115806620: 90 11 546 6 35 2 18
+100446045: 108 20 1 3 465
+270222028: 498 2 3 7 1 1 4 3 2 70 9
+12877: 6 5 1 878
+685: 34 2 4
+2818399918: 704 51 8 9 9 8 8 5
+40278613: 5 7 19 430 527
+31164267156: 94 415 22 1 732 33
+533534403: 1 39 32 4 5 2 7 8 670 1
+3388311: 5 5 3 85 60 491 7 8 396
+2643509: 429 79 78 2 9
+2481: 99 106 993 2 85
+8530329: 4 2 65 2 326
+66218: 182 5 9 2 36 50
+15853745: 7 4 50 119 104 4 7 3 5
+640628523: 6 936 1 68 521
+393944: 781 4 2 21 6 5 1 9 38 6 9
+8366761: 8 42 83 300 51 310
+561332: 81 5 198 7
+453341344: 8 50 30 9 4 3 8 8 3 157 3
+12993827: 69 221 6 86 847
+20258: 45 3 918 470 11 8
+1075200: 56 100 48 4
+2339: 3 164 1 14 1
+256822108: 47 7 651 83 651 4 22 4
+88685757451: 385 59 23 574 52
+161003: 9 8 5 920
+5053787294: 50 3 6 17 787 296
+345653: 39 4 65 782 2 9
+692729: 21 97 12 562 729
+235005408: 42 44 969 96 869
+3564088981345: 4 330 9 3 889 813 46
+8469729: 7 7 8 50 9 8 1 354 65 6 9
+1314: 93 4 905 31 6
+14682: 27 20 283 513 868
+2428: 5 20 6 7 4
+589050: 55 14 765
+89261942429: 4 6 1 3 9 253 79 77 4 3 1
+124771: 1 2 24 5 9 5 6 4 4 809 6 1
+29609630: 493 6 2 9 633
+660706934: 8 4 67 2 1 6 714 6 3 6 3 6
+22032: 27 7 9 9 8
+8190: 117 67 50 35
+3702: 6 73 4 9 198 199 1 33 3
+243382113004: 90 443 468 575 3
+4942989734: 4 1 7 2 390 5 36 687
+1838026626: 134 514 2 427 32
+394630133760: 9 6 81 57 8 85 6 6 6 491
+587: 51 5 33 6 2
+396078485: 8 6 16 25 9 8 783 1 8 4
+453262: 8 576 458 7 8 54 93 1 1
+93752805: 9 37 52 80 8
+6696955: 82 2 9 17 1 5 50 173 9 4
+1382: 4 219 7 427 73
+1127: 7 35 4 23 2 3 9 7 1 70 6
+736278118: 8 92 278 118
+142680170: 4 7 2 59 128 800 9 8 75
+99438: 6 21 5 1 16
+999662116: 4 3 9 255 8 9 2 8 7 8 36 4
+105193: 7 20 288 5 405 5 23 5 9
+712997700918: 9 211 8 5 6 6 1 86 1 7 9 4
+17516: 9 77 7 25 8 7
+79141837: 90 82 460 4 214 28 9
+997869994: 7 615 24 182 13 30 7
+50374502: 50 360 4 10 499
+37088123342405: 8 255 6 8 634 4 3 780 5
+92254773: 15 4 9 7 617 21 8 5 933
+36031053770: 9 40 310 537 70
+1464045: 5 1 4 53 11 70 27 3 19 5
+8330279120298: 771 3 13 9 1 4 6 461 18
+12455430: 85 5 91 8 9 3 5 7 9 1 879
+369341850: 6 8 168 916 9 204 50
+125379: 819 9 17 1 75
+20306099: 80 923 275 8 91
+2749894: 1 5 450 9 6 4 342 2 3 6 4
+37165358: 48 211 9 548 77
+7996838614: 9 90 93 3 8 3 8 617
+9523750: 951 5 5 82 53
+217008: 171 70 6 80 9 2
+153425: 9 663 860 74 150
+1538: 7 85 31 906 1 5
+590093: 1 99 98 9 6 283 6 303
+8553679901: 4 16 9 6 88 8 8 7 8 9
+6797455: 75 597 7 7 455
+1575: 754 3 4 807 7
+11280676845: 12 8 188 937 5 94 6 6 8
+7745959: 71 19 198 29
+29250142: 44 318 66 6 1 19 2
+253277: 60 422 3 66 6
+136636805: 5 32 993 86 6
+12997841: 7 22 9 920 2
+9146663230: 914 6 6 1 6 3 217 3 1 7
+4421270: 39 7 6 27 28 3 531 7 4 5
+2562620926813: 80 91 156 17 8 7 44 14
+506510220721: 69 2 8 295 597 7 3 70 8
+103746: 60 6 2 7 1 4 341 82
+622421: 288 8 36 21 66
+492676716755: 23 425 33 7 72 84 753
+49937529: 93 490 25 534 8 512
+201927: 27 978 864 7 4 30
+12299184916812: 7 488 440 2 5 46 7 36
+322221: 126 28 9 470 1
+190491080: 35 31 522 94 5 80
+29174053010: 711 9 9 35 4 5 289 12 1
+68669803: 8 2 825 410 5 619 803
+136455084976: 85 2 5 61 2 128 5 4 41 9
+602498: 1 13 4 8 250 1
+60022: 931 4 383 3 15 703 9
+4963: 6 6 7 261 4
+104453968: 117 893 7 27 5 39 65
+94752: 9 4 1 72 94
+120757777: 543 353 3 21 7
+20272312170: 50 82 862 689 6 5 99
+102421450: 772 1 92 8 74 6 30 6 3 7
+1080: 794 2 284
+1239771: 16 65 82 634 3 52 3 88
+39299847: 5 8 568 73 967
+22029: 2 2 169 1 970 7 794 9 6
+19969564: 563 61 8 391 4
+255640334: 51 5 6 403 3 6
+2209315: 5 49 478 9 13
+6939312: 8 7 54 3 3 5 66 9 18 625
+12476250525: 148 526 7 92 84
+5629726690: 15 990 307 55 8 630 7
+15214: 1 229 66 7 27
+217415681669808: 64 9 67 5 681 669 810
+67616125202: 6 2 7 4 674 3 8 13 1 8 5 2
+4074: 439 8 78 87 396
+1238757: 815 183 529 8 807 6 6
+374206: 73 1 671 19 91 14
+1382: 4 56 1 6 32
+19304153748: 21 3 9 905 5 2 228 33
+4987: 4 10 7 90 8 6
+1894113: 7 8 929 8 5 2 2 158 6 9
+28935997: 4 5 93 63 94
+69148510: 4 9 829 70 2 5
+156126997: 90 588 776 37 230 7
+1589400: 52 980 30
+599613: 8 656 4 8 887
+339317: 780 29 15 12 5
+2588582921: 61 13 8 58 73 2
+3727052: 370 2 643 9 616
+3747594: 75 49 1 51 20 593
+3111: 2 59 12
+1079620: 33 53 87 7 1 8 3 4 3 9 4 4
+3621672: 3 529 3 469 4 8 5 4 5 8 9
+11328288: 32 354 179 11 98
+584271: 292 2 270
+46634: 3 85 177 973 523
+12164: 5 66 9 69 4 8
+8490217: 8 75 28 97 1 2
+409921726: 6 506 6 81 9 7 3 821
+904029: 3 74 2 68 24
+44627700: 7 4 2 311 2 4 4 2 6 3 5 35
+5832: 3 1 6 9 27
+220521682: 214 26 626 1 684
+5496192704: 1 74 844 735 88 22
+1440773326: 561 696 9 27 95
+198108950: 66 9 2 87 296
+2509: 9 6 3 9 98 51 642 255 5
+8597381452: 8 851 3 3 617 764 455
+154038986: 3 5 401 2 78 3 8 1 7 1 9
+56533414: 7 3 40 4 3 27 50 92 367
+972587: 8 410 319 7 35 5 2 187
+363005: 231 633 3 6 7
+407379: 943 9 8 6
+920002: 5 165 42 2 4 182 32 2
+2507728825: 930 57 44 331 25 43
+5392015: 2 4 64 652 930 6 8 5 9 3
+21068876502: 3 858 70 631 1 92 554
+18624343694: 6 970 10 74 8 3 4
+7488: 52 36 4
+2214667: 316 3 8 7 6
+501256061: 1 7 40 3 8 9 288 68 2 1
+945436: 9 4 543 8 1
+11868043048: 2 138 793 69 3 7 6
+38705: 38 65 3 2 23
+900721: 5 278 3 9 24
+83041262: 1 3 3 5 8 2 13 198 5 6 2
+13813966805: 2 767 844 41 9 1 80 1 4
+235: 36 7 6 22 164
+44864: 738 4 5 7 6
+5670310: 45 9 7 2 312
+293463: 33 3 8 5 3 1 1 4 5 1 8
+43198: 52 2 75 53 29 4 970
+94308: 192 5 582 4 61
+1400333: 2 786 6 782 1 1 8 41 3
+1846880313160: 420 2 842 891 522 57
+153320681: 7 181 1 9 671 4 5 3 4 8
+23232: 31 4 3 4 678 738 8
+4796064073297: 65 244 9 7 40 61 12 9 7
+1626: 721 30 862 6 6 4
+803135200: 608 3 9 85 79 865 7 1 8
+58139: 2 152 24 3 59 83
+2512577950: 2 2 33 234 2 83 973 5 1
+2674260092: 9 6 6 6 851 9 39 7 40 92
+9048: 7 55 69 7 98 271 7 7
+94476591617: 1 9 1 2 8 8 7 6 591 611 6
+31058293: 570 9 1 462 6 54 1 441
+61255700: 4 637 81 932 25
+5544458624: 416 4 1 333 8 623
+1132152: 9 8 58 2 7 3 8 123 9 3 56
+4486: 9 9 2 4 51 23 3
+1154549680: 66 88 67 143 522
+28: 2 5 5 9 7 1
+1604: 547 52 983 6 8 1 8
+8021681: 8 58 8 1 29 8 5 6 9 4 665
+270066420: 77 58 3 59 59
+9380689961: 9 435 5 262 6 7 384 41
+419835292800: 2 96 14 519 268 4 550
+7634396: 762 1 43 94
+183903: 162 3 883 5 7 82 17 5 8
+177047583845: 79 257 622 872 5
+528257457: 4 794 7 481 1 5 1 745 8
+31147295878: 79 54 745 5 8 385 2 73
+6738: 5 8 31 4 5 7 9 2 5 604 3 6
+171865: 62 89 31 807
+281: 54 7 2 2 79 78
+327655: 32 75 33 118 7
+72384: 28 114 32 8 52
+991771: 8 2 670 2 3 1 9 27 6 1 82
+28441672: 120 8 4 38 3 7 5 9 6 952

+ 168 - 0
aoc2024/day8/README.md

@@ -0,0 +1,168 @@
+--- Day 8: Resonant Collinearity ---
+------------------------------------
+
+You find yourselves on the [roof](/2016/day/25) of a top-secret Easter Bunny installation.
+
+
+While The Historians do their thing, you take a look at the familiar *huge antenna*. Much to your surprise, it seems to have been reconfigured to emit a signal that makes people 0.1% more likely to buy Easter Bunny brand Imitation Mediocre Chocolate as a Christmas gift! Unthinkable!
+
+
+Scanning across the city, you find that there are actually many such antennas. Each antenna is tuned to a specific *frequency* indicated by a single lowercase letter, uppercase letter, or digit. You create a map (your puzzle input) of these antennas. For example:
+
+
+
+```
+............
+........0...
+.....0......
+.......0....
+....0.......
+......A.....
+............
+............
+........A...
+.........A..
+............
+............
+
+```
+
+The signal only applies its nefarious effect at specific *antinodes* based on the resonant frequencies of the antennas. In particular, an antinode occurs at any point that is perfectly in line with two antennas of the same frequency - but only when one of the antennas is twice as far away as the other. This means that for any pair of antennas with the same frequency, there are two antinodes, one on either side of them.
+
+
+So, for these two antennas with frequency `a`, they create the two antinodes marked with `#`:
+
+
+
+```
+..........
+...#......
+..........
+....a.....
+..........
+.....a....
+..........
+......#...
+..........
+..........
+
+```
+
+Adding a third antenna with the same frequency creates several more antinodes. It would ideally add four antinodes, but two are off the right side of the map, so instead it adds only two:
+
+
+
+```
+..........
+...#......
+#.........
+....a.....
+........a.
+.....a....
+..#.......
+......#...
+..........
+..........
+
+```
+
+Antennas with different frequencies don't create antinodes; `A` and `a` count as different frequencies. However, antinodes *can* occur at locations that contain antennas. In this diagram, the lone antenna with frequency capital `A` creates no antinodes but has a lowercase-`a`-frequency antinode at its location:
+
+
+
+```
+..........
+...#......
+#.........
+....a.....
+........a.
+.....a....
+..#.......
+......A...
+..........
+..........
+
+```
+
+The first example has antennas with two different frequencies, so the antinodes they create look like this, plus an antinode overlapping the topmost `A`-frequency antenna:
+
+
+
+```
+......#....#
+...#....0...
+....#0....#.
+..#....0....
+....0....#..
+.#....A.....
+...#........
+#......#....
+........A...
+.........A..
+..........#.
+..........#.
+
+```
+
+Because the topmost `A`-frequency antenna overlaps with a `0`-frequency antinode, there are `*14*` total unique locations that contain an antinode within the bounds of the map.
+
+
+Calculate the impact of the signal. *How many unique locations within the bounds of the map contain an antinode?*
+
+
+--- Part Two ---
+----------------
+
+Watching over your shoulder as you work, one of The Historians asks if you took the effects of resonant harmonics into your calculations.
+
+
+Whoops!
+
+
+After updating your model, it turns out that an antinode occurs at *any grid position* exactly in line with at least two antennas of the same frequency, regardless of distance. This means that some of the new antinodes will occur at the position of each antenna (unless that antenna is the only one of its frequency).
+
+
+So, these three `T`-frequency antennas now create many antinodes:
+
+
+
+```
+T....#....
+...T......
+.T....#...
+.........#
+..#.......
+..........
+...#......
+..........
+....#.....
+..........
+
+```
+
+In fact, the three `T`-frequency antennas are all exactly in line with two antennas, so they are all also antinodes! This brings the total number of antinodes in the above example to `*9*`.
+
+
+The original example now has `*34*` antinodes, including the antinodes that appear on every antenna:
+
+
+
+```
+##....#....#
+.#.#....0...
+..#.#0....#.
+..##...0....
+....0....#..
+.#...#A....#
+...#..#.....
+#....#.#....
+..#.....A...
+....#....A..
+.#........#.
+...#......##
+
+```
+
+Calculate the impact of the signal using this updated model. *How many unique locations within the bounds of the map contain an antinode?*
+
+

+ 128 - 0
aoc2024/day8/day8.go

@@ -0,0 +1,128 @@
+package main
+
+import (
+	"bufio"
+	"flag"
+	"fmt"
+	"os"
+	"time"
+)
+
+var grid []string
+
+func main() {
+	example := flag.Bool("example", false, "example or input")
+	print := flag.Bool("print", false, "verbose")
+	flag.Parse()
+	filename := "input.txt"
+	if *example {
+		filename = "example.txt"
+	}
+	file, err := os.Open(filename)
+	if err != nil {
+		fmt.Println(err)
+		return
+	}
+	defer file.Close()
+
+	scanner := bufio.NewScanner(file)
+	for scanner.Scan() {
+		grid = append(grid, scanner.Text())
+	}
+
+	if err := scanner.Err(); err != nil {
+		fmt.Println(err)
+		return
+	}
+
+	antennas := findAntennas(grid)
+
+	// part 1
+	start := time.Now()
+	antinodes := generateAntinodes(grid, antennas, true)
+	end1 := time.Since(start)
+	if *print {
+		for p := range antinodes {
+			grid[p[1]] = replaceCharAt(grid[p[1]], p[0], '#')
+		}
+		for _, line := range grid {
+			fmt.Println(line)
+		}
+	}
+	fmt.Println("Total antinodes:", len(antinodes), "with time:", end1)
+
+	// part 2
+	start = time.Now()
+	antinodes2 := generateAntinodes(grid, antennas, false)
+	end2 := time.Since(start)
+	if *print {
+		for p := range antinodes2 {
+			grid[p[1]] = replaceCharAt(grid[p[1]], p[0], '#')
+		}
+		for _, line := range grid {
+			fmt.Println(line)
+		}
+	}
+	for _, anantenna := range antennas {
+		for _, point := range anantenna {
+			antinodes2[point] = true
+		}
+	}
+	fmt.Println("Total antinodes inline:", len(antinodes2), "with time:", end2)
+
+}
+
+func findAntennas(grid []string) map[rune][][2]int {
+	antennas := make(map[rune][][2]int)
+	for y, row := range grid {
+		for x, cell := range row {
+			if cell != '.' {
+				antennas[rune(cell)] = append(antennas[rune(cell)], [2]int{x, y})
+			}
+		}
+	}
+	return antennas
+}
+
+func generateAntinodes(grid []string, antennas map[rune][][2]int, ones bool) map[[2]int]bool {
+	antinodes := make(map[[2]int]bool)
+	height := len(grid)
+	width := len(grid[0])
+
+	for _, positions := range antennas {
+		for i := 0; i < len(positions); i++ {
+			for j := i + 1; j < len(positions); j++ {
+				x1, y1 := positions[i][0], positions[i][1]
+				x2, y2 := positions[j][0], positions[j][1]
+
+				dx, dy := x2-x1, y2-y1
+
+				addAntinodes(antinodes, x2, dx, y2, dy, width, height, ones)
+				addAntinodes(antinodes, x1, -dx, y1, -dy, width, height, ones)
+			}
+		}
+	}
+
+	return antinodes
+}
+
+func addAntinodes(antinodes map[[2]int]bool, x, dx, y, dy, width, height int, ones bool) {
+	ax, ay := x+dx, y+dy
+	for {
+		if ax >= 0 && ax < width && ay >= 0 && ay < height {
+			antinodes[[2]int{ax, ay}] = true
+			ax, ay = ax+dx, ay+dy
+			if ones {
+				break
+			}
+		} else {
+			break
+		}
+	}
+}
+
+func replaceCharAt(s string, index int, newChar rune) string {
+	runes := []rune(s)
+	runes[index] = newChar
+	return string(runes)
+}

+ 0 - 0
aoc2024/day8/day8.py


+ 12 - 0
aoc2024/day8/example.txt

@@ -0,0 +1,12 @@
+............
+........0...
+.....0......
+.......0....
+....0.......
+......A.....
+............
+............
+........A...
+.........A..
+............
+............

+ 50 - 0
aoc2024/day8/input.txt

@@ -0,0 +1,50 @@
+....................8.D.........Y...........c.....
+....f.............D......O...........Y............
+.......z..........7.N..........g..................
+..........h...........9g.7....................Y...
+.............8...............................c....
+...9..8...............L........D....O.....l.......
+..........f.9.......h.........................l...
+...z...B..........................................
+.................M.....C.....OR7.Y..g..........l..
+........................M.......N.................
+...............h..................TD....H.........
+......z......M........C8.......N.......m.T........
+......O.......................................A...
+...........a...........h..........................
+................B..................j..............
+..............v..f..........g.....................
+.......N..........s.M.........n..............Q....
+...............s.........j.......................A
+......................a......................T...b
+........s....v......H..c..............j..i....m...
+.......................a........2H.......m..V.....
+................n.B..........o.....H......2.......
+.....3.......s.B..............x......S..K.........
+.3.G..................J................V...l.x..T.
+....3.......................E..................V..
+3..........................E..........V...i.......
+...............v.......n.E...................2.i..
+..F.........r.e......n....E...........A..Q.....K..
+..z................................A....Q.........
+.................................b..Q...d.Sw......
+..G...0..e............v.......Z...j.....m...b.....
+..y.............0.a.............................K.
+.............Gp....Z.................4......S.....
+....oJ....G........e.........Z............b.X.....
+C........o.r........WL..1.......X........K.....d..
+..................Z1.....r...............F........
+............L.4................1.6..............tF
+...y...............L......1............26.t.......
+......e.k......y........I......x......d........t.R
+.......0.........k...............d.........tWR..x.
+..........q.....r......J..................F..P..w.
+..........................5..........XwW..........
+...........0....y.............J.............6p....
+..q...k.......................I.....4........SR...
+.........q..o.......P................W............
+.............q.IP..............................p..
+.....k...................w.............X.......f..
+.............P...............4..................p.
+.................I..........5.....................
+.C.................................5...6..........

+ 112 - 0
aoc2024/day9/README.md

@@ -0,0 +1,112 @@
+--- Day 9: Disk Fragmenter ---
+------------------------------
+
+Another push of the button leaves you in the familiar hallways of some friendly [amphipods](/2021/day/23)! Good thing you each somehow got your own personal mini submarine. The Historians jet away in search of the Chief, mostly by driving directly into walls.
+
+
+While The Historians quickly figure out how to pilot these things, you notice an amphipod in the corner struggling with his computer. He's trying to make more contiguous free space by compacting all of the files, but his program isn't working; you offer to help.
+
+
+He shows you the *disk map* (your puzzle input) he's already generated. For example:
+
+
+
+```
+2333133121414131402
+```
+
+The disk map uses a dense format to represent the layout of *files* and *free space* on the disk. The digits alternate between indicating the length of a file and the length of free space.
+
+
+So, a disk map like `12345` would represent a one-block file, two blocks of free space, a three-block file, four blocks of free space, and then a five-block file. A disk map like `90909` would represent three nine-block files in a row (with no free space between them).
+
+
+Each file on disk also has an *ID number* based on the order of the files as they appear *before* they are rearranged, starting with ID `0`. So, the disk map `12345` has three files: a one-block file with ID `0`, a three-block file with ID `1`, and a five-block file with ID `2`. Using one character for each block where digits are the file ID and `.` is free space, the disk map `12345` represents these individual blocks:
+
+
+
+```
+0..111....22222
+```
+
+The first example above, `2333133121414131402`, represents these individual blocks:
+
+
+
+```
+00...111...2...333.44.5555.6666.777.888899
+```
+
+The amphipod would like to *move file blocks one at a time* from the end of the disk to the leftmost free space block (until there are no gaps remaining between file blocks). For the disk map `12345`, the process looks like this:
+
+
+
+```
+0..111....22222
+02.111....2222.
+022111....222..
+0221112...22...
+02211122..2....
+022111222......
+
+```
+
+The first example requires a few more steps:
+
+
+
+```
+00...111...2...333.44.5555.6666.777.888899
+009..111...2...333.44.5555.6666.777.88889.
+0099.111...2...333.44.5555.6666.777.8888..
+00998111...2...333.44.5555.6666.777.888...
+009981118..2...333.44.5555.6666.777.88....
+0099811188.2...333.44.5555.6666.777.8.....
+009981118882...333.44.5555.6666.777.......
+0099811188827..333.44.5555.6666.77........
+00998111888277.333.44.5555.6666.7.........
+009981118882777333.44.5555.6666...........
+009981118882777333644.5555.666............
+00998111888277733364465555.66.............
+0099811188827773336446555566..............
+
+```
+
+The final step of this file-compacting process is to update the *filesystem checksum*. To calculate the checksum, add up the result of multiplying each of these blocks' position with the file ID number it contains. The leftmost block is in position `0`. If a block contains free space, skip it instead.
+
+
+Continuing the first example, the first few blocks' position multiplied by its file ID number are `0 * 0 = 0`, `1 * 0 = 0`, `2 * 9 = 18`, `3 * 9 = 27`, `4 * 8 = 32`, and so on. In this example, the checksum is the sum of these, `*1928*`.
+
+
+Compact the amphipod's hard drive using the process he requested. *What is the resulting filesystem checksum?* (Be careful copy/pasting the input for this puzzle; it is a single, very long line.)
+
+
+--- Part Two ---
+----------------
+
+Upon completion, two things immediately become clear. First, the disk definitely has a lot more contiguous free space, just like the amphipod hoped. Second, the computer is running much more slowly! Maybe introducing all of that [file system fragmentation](https://en.wikipedia.org/wiki/File_system_fragmentation) was a bad idea?
+
+
+The eager amphipod already has a new plan: rather than move individual blocks, he'd like to try compacting the files on his disk by moving *whole files* instead.
+
+
+This time, attempt to move whole files to the leftmost span of free space blocks that could fit the file. Attempt to move each file exactly once in order of *decreasing file ID number* starting with the file with the highest file ID number. If there is no span of free space to the left of a file that is large enough to fit the file, the file does not move.
+
+
+The first example from above now proceeds differently:
+
+
+
+```
+00...111...2...333.44.5555.6666.777.888899
+0099.111...2...333.44.5555.6666.777.8888..
+0099.1117772...333.44.5555.6666.....8888..
+0099.111777244.333....5555.6666.....8888..
+00992111777.44.333....5555.6666.....8888..
+
+```
+
+The process of updating the filesystem checksum is the same; now, this example's checksum would be `*2858*`.
+
+
+Start over, now compacting the amphipod's hard drive using this new method instead. *What is the resulting filesystem checksum?*

+ 151 - 0
aoc2024/day9/day9.go

@@ -0,0 +1,151 @@
+package main
+
+import (
+	"bufio"
+	"flag"
+	"fmt"
+	"os"
+	"strconv"
+	"time"
+)
+
+func main() {
+	example := flag.Bool("example", false, "example or input")
+	flag.Parse()
+	filename := "input.txt"
+	if *example {
+		filename = "example.txt"
+	}
+	file, err := os.Open(filename)
+	if err != nil {
+		fmt.Println(err)
+		return
+	}
+	defer file.Close()
+
+	scanner := bufio.NewScanner(file)
+	scanner.Scan()
+	diskMap := scanner.Text()
+
+	// part 1
+	blocks := parseDiskMap(diskMap)
+	start := time.Now()
+	compactDisk(blocks)
+	checksum := calculateChecksum(blocks)
+	end1 := time.Since(start)
+
+	// part 2
+	blocks = parseDiskMap(diskMap)
+	start = time.Now()
+	compactDiskWholeFiles(blocks)
+	checksum2 := calculateChecksum(blocks)
+	end2 := time.Since(start)
+
+	fmt.Println("Part 1 CheckSum:", checksum, "with time:", end1)
+	fmt.Println("Part 2 CheckSum:", checksum2, "with time:", end2)
+
+}
+
+func parseDiskMap(diskMap string) []rune {
+	var blocks []rune
+	id := 0
+
+	for i, c := range diskMap {
+		length, _ := strconv.Atoi(string(c))
+
+		isFile := i%2 == 0
+		for j := 0; j < length; j++ {
+			if isFile {
+				blocks = append(blocks, rune('0'+id))
+			} else {
+				blocks = append(blocks, '.')
+			}
+		}
+		if isFile {
+			id++
+		}
+	}
+
+	return blocks
+}
+
+func compactDisk(blocks []rune) {
+	n := len(blocks)
+	j := 1
+	for i := n - 1; i >= 0; i-- {
+		if blocks[i] != '.' {
+			for j < i {
+				if blocks[j] == '.' {
+					blocks[j] = blocks[i]
+					blocks[i] = '.'
+					break
+				}
+				j++
+			}
+		}
+	}
+}
+
+func compactDiskWholeFiles(blocks []rune) {
+	whereFiles := make(map[int][2]int)
+	maxID := 0
+	ind := 0
+	for ind < len(blocks)-1 {
+		if blocks[ind] != '.' {
+			id := int(blocks[ind] - '0')
+			start := ind
+			for ind < len(blocks) && int(blocks[ind]-'0') == id {
+				ind++
+				// if ind == len(blocks)-1 {
+				// break
+				// }
+			}
+			end := ind
+			whereFiles[id] = [2]int{start, end}
+
+			if id > maxID {
+				maxID = id
+			}
+			continue
+		}
+		ind++
+	}
+
+	for id := maxID; id >= 0; id-- {
+		size, _ := whereFiles[id]
+		start, end := size[0], size[1]
+
+		fileSize := end - start
+
+		freeStart, freeSize := -1, 0
+		for i := 0; i < start; i++ {
+			if blocks[i] == '.' {
+				if freeStart == -1 {
+					freeStart = i
+				}
+				freeSize++
+				if freeSize >= fileSize {
+					for j := 0; j < fileSize; j++ {
+						blocks[freeStart+j] = rune('0' + id)
+						blocks[start+j] = '.'
+					}
+					maxID--
+					break
+				}
+			} else {
+				freeStart, freeSize = -1, 0
+			}
+		}
+	}
+}
+
+func calculateChecksum(blocks []rune) int {
+	checksum := 0
+	for i, block := range blocks {
+		if block != '.' {
+			id := int(block - '0')
+			checksum += i * id
+		}
+	}
+	return checksum
+}

+ 0 - 0
aoc2024/day9/day9.py


+ 1 - 0
aoc2024/day9/example.txt

@@ -0,0 +1 @@
+2333133121414131402

File diff ditekan karena terlalu besar
+ 0 - 0
aoc2024/day9/input.txt


+ 0 - 2
aoc2024/go.mod

@@ -1,5 +1,3 @@
 module aoc2024
 
 go 1.23.3
-
-require github.com/elliotchance/orderedmap/v3 v3.0.0

+ 0 - 10
aoc2024/go.sum

@@ -1,10 +0,0 @@
-github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
-github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
-github.com/elliotchance/orderedmap/v3 v3.0.0 h1:Yay/tDjX+vzza+Drcoo8VEbuBnOYGpgenCXWcpQSFDg=
-github.com/elliotchance/orderedmap/v3 v3.0.0/go.mod h1:G+Hc2RwaZvJMcS4JpGCOyViCnGeKf0bTYCGTO4uhjSo=
-github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
-github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
-github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY=
-github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
-gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
-gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

Beberapa file tidak ditampilkan karena terlalu banyak file yang berubah dalam diff ini