Skip to content

Commit b8fe741

Browse files
committed
Day 3.
1 parent 2434b70 commit b8fe741

File tree

1 file changed

+145
-0
lines changed

1 file changed

+145
-0
lines changed

2024/day-03.ts

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
import { Expect, Equal } from "../test";
2+
3+
/**
4+
* **🎅Santa Wants Housing Data**
5+
*
6+
* [🎅Santa and 🎩Bernard (the head elf) arguing about the fairness of the reindeer demanding a raise]
7+
*
8+
* [🎅Santa] ABSO-FRICKIN-LOUTLEY NOT!!
9+
*
10+
* [🎩Bernard] Look. They literally are starving out there. You haven't raised the minimum wage at the North Pole since 2009 and they're beginning to realize that if you take inflation into account they're making half of what they did then. Then if you consider how much housing has gone up over the same time it all adds up to a..
11+
*
12+
* [🎅Santa] I don't want to hear another word of this! NOT ONE MORE WORD! If I could, I'd send some of them to prison for their piss poor job performance!!
13+
*
14+
* [🎩Bernard] It's not gonna be simple to keep this going.
15+
*
16+
* [🎅Santa] I don’t have time to crunch numbers, Bernard! I’m trying to figure out if eggnog futures are still a thing.
17+
*
18+
* [🎩Bernard] Alright, you know what. Because we go way back, you and me, I'll do you a favor and make you a program that will calculate their cost of living for a given year since 2009.
19+
*
20+
* [🎅Santa] GOOD! Because this operation is hanging by a thread! The elves are threatening to unionize, the reindeer are planning a hunger strike, and Mrs. Claus wants a Peloton.
21+
*
22+
* The function 🎩Bernard created works for numbers, but it also accepts other data types like strings, booleans, arrays, and objects. That's not quite what we want! TypeScript can help us here.
23+
*
24+
* Hint
25+
*
26+
* How can we change the signature to `survivalRatio` to make TypeScript give us type errors on the invocations that pass things other than numbers?
27+
*/
28+
const survivalRatio = (input: number) => {
29+
const data = annualData[input];
30+
if (!data) {
31+
throw new Error("Data not found");
32+
}
33+
return data.housingIndex / data.minimumWage;
34+
};
35+
36+
type AnnualData = {
37+
[key: string]: {
38+
/** inflation corrected housing price index */
39+
housingIndex: number;
40+
41+
/** inflation corrected North Pole minimum wage */
42+
minimumWage: number;
43+
};
44+
};
45+
46+
const annualData: AnnualData = {
47+
2009: {
48+
housingIndex: 159.50891,
49+
minimumWage: 92.85234,
50+
},
51+
2010: {
52+
housingIndex: 143.02079,
53+
minimumWage: 100.50286,
54+
},
55+
2011: {
56+
housingIndex: 134.38007,
57+
minimumWage: 98.68833,
58+
},
59+
2012: {
60+
housingIndex: 128.14281,
61+
minimumWage: 96.31795,
62+
},
63+
2013: {
64+
housingIndex: 129.07457,
65+
minimumWage: 94.94066,
66+
},
67+
2014: {
68+
housingIndex: 133.94671,
69+
minimumWage: 93.72707,
70+
},
71+
2015: {
72+
housingIndex: 143.30408,
73+
minimumWage: 93.59833,
74+
},
75+
2016: {
76+
housingIndex: 150.21623,
77+
minimumWage: 92.9189,
78+
},
79+
2017: {
80+
housingIndex: 154.90384,
81+
minimumWage: 91.06557,
82+
},
83+
2018: {
84+
housingIndex: 161.67095,
85+
minimumWage: 89.39745,
86+
},
87+
2019: {
88+
housingIndex: 167.71417,
89+
minimumWage: 88.11883,
90+
},
91+
2020: {
92+
housingIndex: 173.5093,
93+
minimumWage: 86.81302,
94+
},
95+
2021: {
96+
housingIndex: 182.89259,
97+
minimumWage: 85.10033,
98+
},
99+
2022: {
100+
housingIndex: 199.43678,
101+
minimumWage: 79.80175,
102+
},
103+
2023: {
104+
housingIndex: 205.8372,
105+
minimumWage: 75.95666,
106+
},
107+
2024: {
108+
housingIndex: 214.9681,
109+
minimumWage: 73.98181,
110+
},
111+
};
112+
113+
// *************************************************************************************
114+
// *** Tests ***
115+
// *************************************************************************************
116+
117+
export const reportForSanta = {
118+
2009: survivalRatio(2009),
119+
2010: survivalRatio(2010),
120+
2011: survivalRatio(2011),
121+
2012: survivalRatio(2012),
122+
2013: survivalRatio(2013),
123+
2014: survivalRatio(2014),
124+
2015: survivalRatio(2015),
125+
2016: survivalRatio(2016),
126+
2017: survivalRatio(2017),
127+
2018: survivalRatio(2018),
128+
2019: survivalRatio(2019),
129+
2020: survivalRatio(2020),
130+
2021: survivalRatio(2021),
131+
2022: survivalRatio(2022),
132+
2023: survivalRatio(2023),
133+
};
134+
135+
// @ts-expect-error
136+
survivalRatio("1");
137+
138+
// @ts-expect-error
139+
survivalRatio(true);
140+
141+
// @ts-expect-error
142+
survivalRatio([1]);
143+
144+
// @ts-expect-error
145+
survivalRatio({ 1: 1 });

0 commit comments

Comments
 (0)