diff --git a/2015/08/8.md b/2015/08/8.md index eb5e7fd..5df5aac 100644 --- a/2015/08/8.md +++ b/2015/08/8.md @@ -45,7 +45,40 @@ characters of string code (`2 + 5 + 10 + 6 = 23`) minus the total number of characters in memory for string values (`0 + 3 + 7 + 1 = 11`) is `23 - 11 = 12`. -To begin, [get your puzzle input](8/input). +Your puzzle answer was `1342`. -Answer: +## \-\-- Part Two \-\-- {#part2} + +Now, let\'s go the other way. In addition to finding the number of +characters of code, you should now *encode each code representation as a +new string* and find the number of characters of the new encoded +representation, including the surrounding double quotes. + +For example: + +- `""` encodes to `"\"\""`, an increase from `2` characters to `6`. +- `"abc"` encodes to `"\"abc\""`, an increase from `5` characters to + `9`. +- `"aaa\"aaa"` encodes to `"\"aaa\\\"aaa\""`, an increase from `10` + characters to `16`. +- `"\x27"` encodes to `"\"\\x27\""`, an increase from `6` characters + to `11`. + +Your task is to find *the total number of characters to represent the +newly encoded strings* minus *the number of characters of code in each +original string literal*. For example, for the strings above, the total +encoded length (`6 + 9 + 16 + 11 = 42`) minus the characters in the +original code representation (`23`, just like in the first part of this +puzzle) is `42 - 23 = 19`. + +Your puzzle answer was `2074`. + +Both parts of this puzzle are complete! They provide two gold stars: +\*\* + +At this point, you should [return to your Advent calendar](/2015) and +try another puzzle. + +If you still want to see it, you can [get your puzzle +input](8/input). diff --git a/2015/08/solution.py b/2015/08/solution.py index f995030..5830884 100644 --- a/2015/08/solution.py +++ b/2015/08/solution.py @@ -1,31 +1,25 @@ #!/bin/python3 -import sys,re +import sys,re,ast,json from pprint import pprint sys.path.insert(0, '../../') from fred import list2int,get_re,nprint,lprint,loadFile -input_f = 'test' +input_f = 'input' -part = 1 +part = 2 ######################################### # # # Part 1 # # # ######################################### -def parse(line): - line = get_re(r'^"(.*)"$',line) - tmp = line - - if part == 1: instructions = loadFile(input_f) - - char = 0 + total = 0 + for i in instructions: - total += len(i) - print(i) + total += (len(i)-len(ast.literal_eval(i))) print(total) @@ -40,4 +34,11 @@ if part == 1: # # ######################################### if part == 2: - exit() + instructions = loadFile(input_f) + + total = 0 + + for i in instructions: + total += (len(json.dumps(i)) - len(i)) + + print(total) diff --git a/2024/06/6.md b/2024/06/6.md index d4805c4..aad72f0 100644 --- a/2024/06/6.md +++ b/2024/06/6.md @@ -119,6 +119,8 @@ guard visit before leaving the mapped area?* Your puzzle answer was `5212`. +The first half of this puzzle is complete! It provides one gold star: \* + ## \-\-- Part Two \-\-- {#part2} While The Historians begin working around the guard\'s patrol route, you @@ -242,14 +244,8 @@ You need to get the guard stuck in a loop by adding a single new obstruction. *How many different positions could you choose for this obstruction?* -Your puzzle answer was `1767`. +Answer: -Both parts of this puzzle are complete! They provide two gold stars: -\*\* - -At this point, you should [return to your Advent calendar](/2024) and -try another puzzle. - -If you still want to see it, you can [get your puzzle +Although it hasn\'t changed, you can still [get your puzzle input](6/input). diff --git a/README.md b/README.md index 7c46dc5..bfbdde8 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,7 @@ .---': ~ '(~), ~| | >@>O< o-_/.()__------| 3 ** |@..@'. ~ " ' ~ | |>O>o<@< \____ .'| 4 ** |_.~._@'.. ~ ~ *| | _| |_ ..\_\_ ..'* | 5 ** + | ||| @@ '''...| |... .' '.'''../..| 6 ** ## 2023 @@ -102,6 +103,8 @@ ## 2015 + >>*<*<<>o<*<<<*<>O>>>*>*<<< 8 ** + >@>o>O<<>>*>>*<*>>*>@<< 6 ** >@<@>>o<>O@>@>>>@>>o<*<<<*<<<@<< 5 ** >*>>O>@>>>@>>@>>>o<<<*<<<@>>@<