Author Topic: AOC++  (Read 3563 times)

David Martin

  • Thats Dr Oi You thankyouverymuch
AOC++
« on: 22 December, 2017, 01:11:15 pm »
OK, here is a thread for some similar puzzles to AOC - mostly thought experiments as I haven't got proper data to work with (yet)
Quote
Santas elves have been busy in the wrapping department. There are many elves, each filling one sleigh and as many different wrapping papers as there are elves. Each elf wraps each present in a random paper and places it in his sleigh (so there are many sleighs each with presents in many different colours.

Santa is furious. How will he sort them out in time to deliver them? Apparently he wants each sleigh to have just one colour of present. An elf can only move one present at a time to reorganise the sleigh and it has to be done as quickly as possible

What is the smallest number of moves to sort all the presents? It doesn't matter which sleigh they end up in, as long as the sleigh is uniformly coloured

Your input data is of the form:

A1 B1 C1 D1 A2 B2 C2 D2 ... where A1 is the number of presents in paper A in sled 1.

(click to show/hide)

I may post some data later.

Potential solutions in spoilers..
"By creating we think. By living we learn" - Patrick Geddes

Ben T

Re: AOC++
« Reply #1 on: 22 December, 2017, 03:30:07 pm »
does a sleigh always have to maintain at least one present in it?

so if there are more distinct colours than there are sleighs, then it's impossible.
If fewer different colours than sleighs, then at least one will have to finish empty, therefore must be allowed to go empty at some point.
But if the same amount, then each sleigh will end up with some in , but can it transition through an intermediate state of emptiness?

am I right in thinking the example input as given implies a starting state of
sleigh 1 containing one of each of A, B, C and D
sleigh 2 containing one of each of A, B, C and D

think that could be good, thanks for posting  :thumbsup:

(and presumably not, but does a sleigh have a maximum capacity?)

David Martin

  • Thats Dr Oi You thankyouverymuch
Re: AOC++
« Reply #2 on: 22 December, 2017, 04:13:35 pm »
No maximum capacity, and no limit on intermediate states. I'll post some numbers in a bit. There are the same number of sleighs as papers as elves.

So you could end up with sleigh 1 having 5 of colour A , 3 of colour B, 12 of colour C, and so on for 3 sleighs.

The obvious constraint of totals
(click to show/hide)
"By creating we think. By living we learn" - Patrick Geddes

David Martin

  • Thats Dr Oi You thankyouverymuch
Re: AOC++
« Reply #3 on: 25 December, 2017, 09:44:43 pm »
OK, some example data.
76 44 96 29 43 51 72 64 36 91 100 82 21 74 58 49 76 98 52 88 97 64 50 75 69 44 73 91 81 35 69 90 97 22 85 73 12 77 80 26 37 98 24 25 53 89 50 79 74 35 63 52 46 48 27 69 77 84 75 41 19 78 89 42 58 48 29 92 70 83 34 71 16 72 24 76 13 84 13 56 79 65 73 82 12 56 11 80 29 10 96 76 8 31 11 65 87 91 80 15

Remember it is colour1elf1 colour2elf1 C3E1 ... C1E2 C2E2 etc.

"By creating we think. By living we learn" - Patrick Geddes

Ben T

Re: AOC++
« Reply #4 on: 25 December, 2017, 09:59:04 pm »
Sorry so is the first one colour 7 elf 6? Then colour 4 elf 4? If so what's 100?

David Martin

  • Thats Dr Oi You thankyouverymuch
Re: AOC++
« Reply #5 on: 25 December, 2017, 10:18:14 pm »
Sorry so is the first one colour 7 elf 6? Then colour 4 elf 4? If so what's 100?

No. 76 is the number of presents elf 1 wrapped in colour A. 44 is the number of presents elf 1 wrapped in colour B and so on.
"By creating we think. By living we learn" - Patrick Geddes

Ben T

Re: AOC++
« Reply #6 on: 26 December, 2017, 12:25:34 am »
Sorry so is the first one colour 7 elf 6? Then colour 4 elf 4? If so what's 100?

No. 76 is the number of presents elf 1 wrapped in colour A. 44 is the number of presents elf 1 wrapped in colour B and so on.
Ok so it's line delimited , ie 35 is elf 2 colour A, 41 is elf 3 colour B etc...

David Martin

  • Thats Dr Oi You thankyouverymuch
Re: AOC++
« Reply #7 on: 26 December, 2017, 08:45:25 am »
Sorry so is the first one colour 7 elf 6? Then colour 4 elf 4? If so what's 100?

No. 76 is the number of presents elf 1 wrapped in colour A. 44 is the number of presents elf 1 wrapped in colour B and so on.
Ok so it's line delimited , ie 35 is elf 2 colour A, 41 is elf 3 colour B etc...
No, it's all on one line. Work out how many elves/colours there are.
"By creating we think. By living we learn" - Patrick Geddes

Ben T

Re: AOC++
« Reply #8 on: 26 December, 2017, 01:37:02 pm »
OK here's a good one for you.

Santa delivers presents to each house in turn. He has been told that every family lives on one long street with numbers starting at 1. He starts with number 1, and delivers 1 present to number 1.
Unfortunately, however, the children are greedy and each house expects more presents than the last. Many times more, in fact.
They are so greedy that the children in each house expect their house number times the amount of presents as the last. So the child in number 3 expects 6 presents. The child in number 4 expects 24 presents. The children in number 5 expect 120 presents. [You can probably see where this is going.]

Part 1
Santa soon realises that the number of presents is going to get quite large and realises he will be better off getting his super elves to deal with them. Each superelf can take any number of batches of a million presents at ridiculous speed (but can't take any less than a million and can only take exact multiples of a million). Santa will have to deal with the remainder himself.
How many presents in total will Santa have to deliver himself? (Assume he can arrange all the elves prior to starting out any deliveries, i.e. the answer is by definition less than a million)

[On my machine my implementation takes
(click to show/hide)
]


Part 2
Unfortunately, Santa still has to wrap all the presents before he sets out.
To his computer's relief, and being the brexiteer that he is, Santa decides to sod europe and just concentrate on Britain. He estimates (possibly incorrectly) that the number of households is around 30 million (your puzzle input). Again, he (possibly incorrectly) assumes that every family lives on one long street numbered from 1 to about 30million.
He approximates the amount of wrapping paper in metres for the nth household by how hot his computer's RAM chip is getting when it stores the number of presents for that household, which is proportional to how many bits are lit up.
For the first and second households (1, 2 presents respectively), he orders 1 metre each. For the 3rd and 4th household (6, 24 presents respectively), he orders 2 metres. For the 5th and 6th households, he orders 4 metres. etc.
How many metres does he need to order for the Nth household
(just for the Nth household this time - not the total for all households!)
 - where N (your puzzle input) = (pick one and stick to it)
(click to show/hide)
(click to show/hide)
(click to show/hide)
etc

[On my machine my implementation takes
(click to show/hide)
]

Part 3
Santa decides to type out the total number of presents for the Nth household. This in itself is thirsty work, so Santa's wife decides to go and get Santa a cup of tea whenever she sees Santa type the digits "123" together. How many cups of tea does Santa end up drinking?
(Assume that Santa's wife is a very very quick tea maker and the time it takes her is negligible, so if Santa encounters 123 twice, e.g. 123123, then he will neck two cups of tea on the trot, etc.)

[On my machine my implementation takes
(click to show/hide)
]



Ben T

Re: AOC++
« Reply #9 on: 26 December, 2017, 02:58:29 pm »
Sorry so is the first one colour 7 elf 6? Then colour 4 elf 4? If so what's 100?

No. 76 is the number of presents elf 1 wrapped in colour A. 44 is the number of presents elf 1 wrapped in colour B and so on.
Ok so it's line delimited , ie 35 is elf 2 colour A, 41 is elf 3 colour B etc...
No, it's all on one line. Work out how many elves/colours there are.

OK ...only problem is I don't see how to tell where elf 1 ends and elf 2 begins. Or, thus, how many elves there are in total.
Can't the elements of the input include two pieces of info rather than 1, i.e. the colour and the elf/sleigh number. Or is that part of the problem, if so what should I be using to calculate where one elf/sleigh starts and the other ends...?


Ben T

Re: AOC++
« Reply #10 on: 26 December, 2017, 03:02:03 pm »
Answers:
Part 1
(click to show/hide)

Part 2
(one for each puzzle input)
(click to show/hide)
(click to show/hide)
(click to show/hide)


Part 3
(one for each puzzle input)
(click to show/hide)
(click to show/hide)
(click to show/hide)



David Martin

  • Thats Dr Oi You thankyouverymuch
Re: AOC++
« Reply #11 on: 26 December, 2017, 08:53:29 pm »
Sorry so is the first one colour 7 elf 6? Then colour 4 elf 4? If so what's 100?

No. 76 is the number of presents elf 1 wrapped in colour A. 44 is the number of presents elf 1 wrapped in colour B and so on.
Ok so it's line delimited , ie 35 is elf 2 colour A, 41 is elf 3 colour B etc...
No, it's all on one line. Work out how many elves/colours there are.

OK ...only problem is I don't see how to tell where elf 1 ends and elf 2 begins. Or, thus, how many elves there are in total.
Can't the elements of the input include two pieces of info rather than 1, i.e. the colour and the elf/sleigh number. Or is that part of the problem, if so what should I be using to calculate where one elf/sleigh starts and the other ends...?



Same numerb of elves as colours. Each elf wraps in each colour. Elf * colours is therefore a square.
"By creating we think. By living we learn" - Patrick Geddes

Ben T

Re: AOC++
« Reply #12 on: 26 December, 2017, 09:16:07 pm »
Still don't get it, sorry. I can't understand where the data for elf 1 ends and elf 2 starts. Would be better with an example.

David Martin

  • Thats Dr Oi You thankyouverymuch
Re: AOC++
« Reply #13 on: 26 December, 2017, 10:04:36 pm »
10 30 20 20 20 15 20 35 40

9 data points = 3 elves * 3 colours

If all the packages for colour 1 are moved to elf 1, all the packages for colour 2 moved to elf 2 etc. this is

20 packages from elf 2 to elf 1
20 packages from elf 3 to elf 1
30 packages from elf 1 to elf 2
20 packages from elf 1 to elf 3
20 packages from elf 2 to elf 3
and 35 packages from elf 3 to elf 2

What is the minimum number of moves so each elf ends up with a single colour (elf 1 does not have to have colour 1 but has to have just one colour)

"By creating we think. By living we learn" - Patrick Geddes

Ben T

Re: AOC++
« Reply #14 on: 26 December, 2017, 11:10:26 pm »
But you've got 6 colours there, 10,20,30,15,35 and 40?
Or does the 2 digit number represent a colour, or an elf?? Or is it split 1 digit each? Or is it the number of packages - but if so what's the colour / elf number it goes with?
I sort of get the general principle / rules on how to proceed - it's a sorting algorithm, once I know what colours each elf starts with.
Can you not write the starting configuration in the following format:
Elf 1 colour 26
Elf 1 colour 95
Elf 2 colour 76
Elf 3 colour 21
...
Elf n colour n

Rather than just
21 56 78 43 etc.


David Martin

  • Thats Dr Oi You thankyouverymuch
Re: AOC++
« Reply #15 on: 27 December, 2017, 05:02:53 pm »
Elf 1 produces n packages of colour 1. n is the first number
Elf 1 produces m packages of colour 2. m  is the second number.
"By creating we think. By living we learn" - Patrick Geddes

Ben T

Re: AOC++
« Reply #16 on: 27 December, 2017, 05:33:06 pm »
Elf 1 produces n packages of colour 1. n is the first number
Elf 1 produces m packages of colour 2. m  is the second number.

OK, I think I see. So of your 100 starting numbers each elf 1-10 wraps a number of presents in each of 1 to 10 colours.
How you doing on mine?

Ben T

Re: AOC++
« Reply #17 on: 27 December, 2017, 06:28:56 pm »
OK well for part 1 I make the minimum number this many moves
(click to show/hide)
unless I've made a heinous error which is possible.

Ben T

Re: AOC++
« Reply #18 on: 27 December, 2017, 07:00:28 pm »
Part 2,unless I've completely misunderstood,
(click to show/hide)

David Martin

  • Thats Dr Oi You thankyouverymuch
Re: AOC++
« Reply #19 on: 27 December, 2017, 07:44:43 pm »
How did you get to the solution? The journey is often more interesting than the destination.
"By creating we think. By living we learn" - Patrick Geddes

Ben T

Re: AOC++
« Reply #20 on: 27 December, 2017, 10:06:57 pm »
How did you get to the solution? The journey is often more interesting than the destination.
Well, am I right?

Re: AOC++
« Reply #21 on: 27 December, 2017, 10:12:20 pm »
How did you get to the solution? The journey is often more interesting than the destination.
Well, am I right?

It's the same answer I got. It's unlikely we've both come up with the same incorrect answer.

(I haven't done part 2 yet so I can't comment on that.)
"Yes please" said Squirrel "biscuits are our favourite things."

Ben T

Re: AOC++
« Reply #22 on: 27 December, 2017, 10:31:29 pm »
How did you get to the solution? The journey is often more interesting than the destination.
Well, am I right?

It's the same answer I got. It's unlikely we've both come up with the same incorrect answer.

(I haven't done part 2 yet so I can't comment on that.)

Part 2's actually easier unless i've completely misunderstood it.
For part 1
(click to show/hide)

For part 2
(click to show/hide)

David Martin

  • Thats Dr Oi You thankyouverymuch
Re: AOC++
« Reply #23 on: 28 December, 2017, 12:04:03 am »
(click to show/hide)
"By creating we think. By living we learn" - Patrick Geddes

Re: AOC++
« Reply #24 on: 28 December, 2017, 09:58:52 am »
(click to show/hide)

"Yes please" said Squirrel "biscuits are our favourite things."