Day 13 - Grant

You agreed to be the campsite host at the Grant campground for the night. You arrive at the check-in booth and find out that all the campsite assignments have been lost! All you have is a mixed up list of campsite details and camper requests. You need to assign sites quickly to the campers before check-in opens at 4:00 PM! Campers like large sites that are close to the restrooms. To assign campers to the sites, you need to sort the campsites by length (decreasing) and distance from the restroom (increasing). Then sort the camper requests in the same way.

Match the sites to the campers based on the lists. Calculate a Happiness Factor for each campsite/camper assignment. Each camper starts with 100 Happiness. Subtract 5 points for every foot the campsite is too short. Subtract 1 point for every foot the campsite is too far from the restrooms.

For example, suppose this is the input:

restroom = 35,length = 25,type = campsite,number = 158
restroom = 55,number = 261,length = 30,type = campsite
restroom = 50,number = 363,type = camper,length = 25
length = 15,number = 401,type = camper,restroom = 86
length = 30,number = 81,restroom = 71,type = camper
number = 283,type = campsite,length = 20,restroom = 35
restroom = 92,type = camper,number = 244,length = 20
number = 188,type = camper,restroom = 128,length = 30
type = campsite,number = 382,length = 15,restroom = 93
number = 62,type = campsite,length = 20,restroom = 77

The sorted camper data is:

Type Number Length Restroom
camper 81 30 71
camper 188 30 128
camper 363 25 50
camper 244 20 92
camper 401 15 86

The sorted campsite data is:

Type Number Length Restroom
campsite 261 30 55
campsite 158 25 35
campsite 283 20 35
campsite 62 20 77
campsite 382 15 93

The assignments and Happiness Factors are:

Type Number Length Restroom Type Number Length Restroom Score
camper 81 30 71 campsite 261 30 55 100
camper 188 30 128 campsite 158 25 35 75
camper 363 25 50 campsite 383 20 35 75
camper 244 20 92 campsite 62 20 77 100
camper 401 15 86 campsite 382 15 93 93

The total Happiness Factor is 443.

What is the total Happiness Factor at the Grant campground tonight?

Input

Test input

Hints

Copyright 2022 Robin A. Reynolds-Haertle