Puzzle 2 — Seagulls and Chips

< APUG Nov 2024

Part 1

After a long journey, Santa's sleigh finally touches down on Union Street. But the elves are restless. “Santa, Santa! We're starving!” they say jumping up and down.

“But you just ate!” Santa snapped, shaking his head “Between rising candy cane prices, Rudolph's vet bill, and that unfair labour practices legal settlement, the workshop's budget is a little tighter this year. I just don't think we have the pennies for it.”

Thankfully, Santa's chief technology elf has downloaded a list of chip shops in the area. “With this list, Santa, we can quickly find the most cost-effective chips available and fill all our bellies!” The elves cheer.

Your task is to identify the most cost-effective chip shop. To answer the puzzle, state the portion size of this chip shop.

Example Input File

Let's look at our small example list:

1.80 80
1.50 160
2.80 50
1.50 140
1.90 180
2.00 80

The first column appears to be the price for a portion of chips, and the second column seems to be the number of chips in a portion, the portion size. The columns are separated by a single space.

We can see from these prices that the cheapest chips cost 0.9375 pence per chip, this is the chip shop which sells 160 chips for £1.50. So the answer to our question is 160.

Real Input File

The above was a small example file. To see the real list of chip shops, download input2.txt

How many chips are in a portion from the most cost-effective chip shop?

Part 2

Santa sent out one of his elves out to buy chips from the cheapest shop, but sadly, the chips and elf were whisked away by a seagull!

“Oh no!” Santa laments, “Santa smells another lawsuit!” shaking his head once more.

Santa' chief technology elf, clutching Santa's iPhone 16 Pro Max, explaining that they are reading the list all wrong! “The city council has recently mandated that all the chip shops in Aberdeen standardise on the same number of chips per portion.”

The CTE continues to explain, “The second column on the list is actually the size of the local seagull population, information updated by nightly radar drones, a critical piece of safety information the people of Aberdeen rely upon!”

“Oh yes,” says Santa, “that means many of these chip shops are not a good idea to visit at all and should be skipped.”

A chip shop should be skipped if at least one other chip shop has fewer seagulls for the same portion price, or cheaper chips for the same number of seagulls, or both cheaper chips and fewer seagulls.

Your task now becomes identifying which chips shops are worth visiting. To answer the puzzle, state the total price of portions of chips from each of those chip shops.

Example Input File

Let's look again at our small example list:

1.80 80
1.50 160
2.80 50
1.50 140
1.90 180
2.00 80

Consider the second and forth chip shops:

Since they are the same price, you would skip the one with more seagulls, more chance your chips and elves be eaten! For this reason, we skip the second chip shop.

“Skip Shops!” the CTE interjects.

“Skip Shops! Chip shops that we should skip.”

“Yes.”

“It sounds like ‘chip shop’ but we skip visiting them so ‘skip shop’.”

“We're in the middle of explaining the puzzle.”

Now consider the first and sixth chip shops:

Since have the same number of seagulls, you would skip the one with the higher price! For this reason, we skip the second chip shop.

“I took the ‘c’ in ‘chip’ and replaced it with an ‘s’ so it rhymes.”

Now consider the first and fifth chip shops:

In this case not only is the first chip shop cheaper, but it also has fewer seagulls! For these reasons, we skip the fifth chip shop.

Dazed and confused from his earlier altercation with a seagull, one of Santa's elves asks, “So which chip shop is the best then?”

Santa shakes his head and explains, “It's not that simple, right?”

The CTE joins in, “Yup, there is no one single best chip shop, just different options.”

Consider the first and fourth chip shops:

The first chip shop has fewer seagulls, making it safer.

The fourth chip shop is cheaper.

Neither is strictly better, we would not use this comparison to eliminate either chip shop.

A chip shop should be skipped, if any of these are true:

  1. There exists another chip shop which has cheaper chips and fewer seagulls; or
  2. There exists another chip shop which the same chip price and fewer seagulls; or
  3. There exists another chip shop which has cheaper chips and the same number of seagulls.

“Skip Shop!”

After comparing all chip shops, we would eliminate all the ones we skip:

1.80 80
1.50 160 (skip)
2.80 50
1.50 140
1.90 180 (skip)
2.00 80  (skip)

Then to resolve our indecision between the remaining chip shops, we send one elf to each remaining chip shop.

This will cost a total of £1.80 + £2.80 + £1.50 = £6.10

Real Input File

After eliminating each chip shop that we should skip, how much does it cost to send an elf to buy chips for each that remains?

The real list of chip shops is the same file we used for Part 1: input2.txt