Solved 2015/08 P1+P2
This commit is contained in:
parent
4274b0bb89
commit
99bb81be32
37
2015/08/8.md
37
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).
|
||||
|
||||
|
@ -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)
|
||||
|
12
2024/06/6.md
12
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).
|
||||
|
||||
|
@ -7,6 +7,7 @@
|
||||
.---': ~ '(~), ~| | >@>O< o-_/.()__------| 3 **
|
||||
|@..@'. ~ " ' ~ | |>O>o<@< \____ .'| 4 **
|
||||
|_.~._@'.. ~ ~ *| | _| |_ ..\_\_ ..'* | 5 **
|
||||
| ||| @@ '''...| |... .' '.'''../..| 6 **
|
||||
|
||||
## 2023
|
||||
|
||||
@ -102,6 +103,8 @@
|
||||
|
||||
## 2015
|
||||
|
||||
>>*<*<<<o<@>>o<*<<<*<<o>>O>>>*>*<<< 8 **
|
||||
|
||||
>@>o<O>>O<<<O>>>*>>*<*>>*<O<<o<<<O>>@<< 6 **
|
||||
>@<@<O>>>o<<O>>O<O>@>@>>>@>>o<*<<<*<<<@<< 5 **
|
||||
>*>>O>@>>>@>>@>>>o<<<*<<<@>>@<<O<<<@<<O<<<< 4 **
|
||||
|
Loading…
Reference in New Issue
Block a user