Author Topic: Advent of Code  (Read 116474 times)

Davef

Re: Advent of Code
« Reply #975 on: 13 December, 2020, 07:05:55 pm »
If anyone is interested in how my simple solution to 13 day 2 works ...

(click to show/hide)

(click to show/hide)

(click to show/hide)
I did actually a version that sorted first but I stripped it out to get my solution down to 80 characters.

tonycollinet

  • No Longer a western province of Númenor
Re: Advent of Code
« Reply #976 on: 13 December, 2020, 08:05:22 pm »
Realising (now) that lowest common multiplier wasn't actually needed in day 13 - still a question that came up:

Is it true that LCM (a,b,c,d...)

Is equal to

LCM(d,LCM(c,LCM(b,a)))

?? (Assuming I've got the brackets in the correct places  ;D )

Re: Advent of Code
« Reply #977 on: 13 December, 2020, 08:34:59 pm »
Yes.

Informally, because you can calculate LCM by finding the maximum prime factor exponent of each number and max more obviously satisfies the same property: max (a,b,c) = max (a, max(b,c))

Davef

Advent of Code
« Reply #978 on: 14 December, 2020, 08:29:43 am »
Or that the lcm of a set of numbers is their product divided by their gcd. I find it easier to visualise the gcd in a  mental venn diagram of prime factors. It is fundamental that set intersection works this way from the colouring in I did at school.

Davef

Re: Advent of Code
« Reply #979 on: 14 December, 2020, 09:42:16 am »

(click to show/hide)

(click to show/hide)

(click to show/hide)
Doesn’t your favourite theorem require the bus numbers to be relatively prime too ?

Re: Advent of Code
« Reply #980 on: 14 December, 2020, 12:43:53 pm »
Doesn’t your favourite theorem require the bus numbers to be relatively prime too ?

The basic one yes, but the more generalised version works on non-co-prime moduli too.
"Yes please" said Squirrel "biscuits are our favourite things."

Ben T

Re: Advent of Code
« Reply #981 on: 14 December, 2020, 02:15:42 pm »
I think day 14 part 2's badly explained, I don't even get what the program's meant to be doing.

Quote
After applying the mask, four bits are overwritten, three of which are different, and two of which are floating. Floating bits take on every possible combination of values; with two floating bits, four actual memory addresses are written:

000000000000000000000000000000011010  (decimal 26)
000000000000000000000000000000011011  (decimal 27)
000000000000000000000000000000111010  (decimal 58)
000000000000000000000000000000111011  (decimal 59)
Next, the program is about to write to memory address 26 with a different bitmask:

address: 000000000000000000000000000000011010  (decimal 26)
mask:    00000000000000000000000000000000X0XX
result:  00000000000000000000000000000001X0XX
This results in an address with three floating bits, causing writes to eight memory addresses:

000000000000000000000000000000010000  (decimal 16)
000000000000000000000000000000010001  (decimal 17)
000000000000000000000000000000010010  (decimal 18)
000000000000000000000000000000010011  (decimal 19)
000000000000000000000000000000011000  (decimal 24)
000000000000000000000000000000011001  (decimal 25)
000000000000000000000000000000011010  (decimal 26)
000000000000000000000000000000011011  (decimal 27)

The entire 36-bit address space still begins initialized to the value 0 at every address, and you still need the sum of all values left in memory at the end of the program. In this example, the sum is 208.

"four actual memory addresses are written"... written with what?
"In this example, the sum is 208".... which of the above values sum to 208?

They seem to sum to 342 to me. Even if you only count each one once (26 and 27 are twice), they sum to 289.

How does he get 208?

???

Re: Advent of Code
« Reply #982 on: 14 December, 2020, 02:28:18 pm »
Quote
mask = 000000000000000000000000000000X1001X
mem[42] = 100
mask = 00000000000000000000000000000000X0XX
mem[26] = 1

The first command writes "100" to 4 different addresses. The second command writes "1" to 8 addresses, 2 of which overwrite the 100s. Therefore what's left is 2*100+8*1.

I can't see a sensible way of implementing it with a spreadsheet yet.

Davef

Re: Advent of Code
« Reply #983 on: 14 December, 2020, 02:35:48 pm »
Quote
mask = 000000000000000000000000000000X1001X
mem[42] = 100
mask = 00000000000000000000000000000000X0XX
mem[26] = 1

The first command writes "100" to 4 different addresses. The second command writes "1" to 8 addresses, 2 of which overwrite the 100s. Therefore what's left is 2*100+8*1.

I can't see a sensible way of implementing it with a spreadsheet yet.
My first go splurged stuff all over the place but worked. I then redid it imagining I had a quantum processor using a superposition of quantum states. I then fell back through a wormhole to day 13 part 2.

Davef

Re: Advent of Code
« Reply #984 on: 14 December, 2020, 02:42:18 pm »
Day 13 part 2, only loops 38 times rather than 1000 now, but I feel sorry for the person taking over code maintenance

(click to show/hide)

Re: Advent of Code
« Reply #985 on: 14 December, 2020, 03:17:17 pm »
(click to show/hide)
"Yes please" said Squirrel "biscuits are our favourite things."

Davef

Re: Advent of Code
« Reply #986 on: 14 December, 2020, 03:52:08 pm »
(click to show/hide)
(click to show/hide)

Ben T

Re: Advent of Code
« Reply #987 on: 14 December, 2020, 04:40:51 pm »
Quote
mask = 000000000000000000000000000000X1001X
mem[42] = 100
mask = 00000000000000000000000000000000X0XX
mem[26] = 1

The first command writes "100" to 4 different addresses. The second command writes "1" to 8 addresses, 2 of which overwrite the 100s. Therefore what's left is 2*100+8*1.

I can't see a sensible way of implementing it with a spreadsheet yet.

Oh, I see...
yeah you might have to wheel a programming language out.

Re: Advent of Code
« Reply #988 on: 14 December, 2020, 05:56:09 pm »
Quote
mask = 000000000000000000000000000000X1001X
mem[42] = 100
mask = 00000000000000000000000000000000X0XX
mem[26] = 1

The first command writes "100" to 4 different addresses. The second command writes "1" to 8 addresses, 2 of which overwrite the 100s. Therefore what's left is 2*100+8*1.

I can't see a sensible way of implementing it with a spreadsheet yet.

Oh, I see...
yeah you might have to wheel a programming language out.

You can do bit operations in Google sheets.  Haven’t looked at what you need to do but bit manipulation via ORs ANDs, shifts etc should not stop you using sheets.

Re: Advent of Code
« Reply #989 on: 14 December, 2020, 06:12:12 pm »
You can do bit operations in Google sheets.  Haven’t looked at what you need to do but bit manipulation via ORs ANDs, shifts etc should not stop you using sheets.

That's not the problem. Part 1 was straightforward enough.

The problem is storing the intermediate results of each write, and combining the overwrites to get the final total. Without hashtables or nested loops or a 2^36 array.

There's probably some clever radical simplification of the problem.

Davef

Re: Advent of Code
« Reply #990 on: 14 December, 2020, 06:29:39 pm »
You can do bit operations in Google sheets.  Haven’t looked at what you need to do but bit manipulation via ORs ANDs, shifts etc should not stop you using sheets.

That's not the problem. Part 1 was straightforward enough.

The problem is storing the intermediate results of each write, and combining the overwrites to get the final total. Without hashtables or nested loops or a 2^36 array.

There's probably some clever radical simplification of the problem.
You could have one column with memory addresses in an the values in the next. They are are just labels.

tonycollinet

  • No Longer a western province of Númenor
Re: Advent of Code
« Reply #991 on: 14 December, 2020, 06:40:09 pm »
Day 14 complete - less tricky than 13, but...

(click to show/hide)

Re: Advent of Code
« Reply #992 on: 14 December, 2020, 11:59:36 pm »
Day 14 complete.
(click to show/hide)
Quote from: Kim
Paging Diver300.  Diver300 to the GSM Trimphone, please...

Re: Advent of Code
« Reply #993 on: 15 December, 2020, 01:27:11 am »
Day 14 part 1. Relatively trivial.
https://docs.google.com/spreadsheets/d/1uprQs9jfVjy9C7WC-q9_iVRd9lz6VEts1kPm-iAzPaA/edit?usp=sharing

Day 14 part 2.
https://docs.google.com/spreadsheets/d/1wTfCJDeHbetXmXDTj6ZkR7Z_KBjIpG2dLe91rwaOyNg/edit?usp=sharing

(click to show/hide)

tonycollinet

  • No Longer a western province of Númenor
Re: Advent of Code
« Reply #994 on: 15 December, 2020, 08:45:20 am »
Day 15 oddly trivial, even brute forcing part2. I assume there is a more intelligent method for that, but if there is, I haven't found it yet.

(click to show/hide)

Re: Advent of Code
« Reply #995 on: 15 December, 2020, 08:57:41 am »
Occasionally there are 'easy' days to give people a break and let them catch up.

(click to show/hide)
"Yes please" said Squirrel "biscuits are our favourite things."

tonycollinet

  • No Longer a western province of Númenor
Re: Advent of Code
« Reply #996 on: 15 December, 2020, 09:02:17 am »
Occasionally there are 'easy' days to give people a break and let them catch up.

(click to show/hide)

(click to show/hide)

Re: Advent of Code
« Reply #997 on: 15 December, 2020, 09:15:10 am »
(click to show/hide)

Yes, a hash is another name for a dictionary. Different languages use different names.

Dictionaries, hashes, hashmaps, maps, ...
"Yes please" said Squirrel "biscuits are our favourite things."

Re: Advent of Code
« Reply #998 on: 15 December, 2020, 09:52:02 am »
Rewrote it in C to see how quick I could get it:-

Code: [Select]
$ gcc -ansi -pedantic -Wall -O4 15.c -o 15
$ time ./15 2 3 1
2020: 78
30000000: 6895259

real    0m0.813s
user    0m0.761s
sys     0m0.052s

(click to show/hide)
"Yes please" said Squirrel "biscuits are our favourite things."

Re: Advent of Code
« Reply #999 on: 15 December, 2020, 10:08:54 am »
(click to show/hide)