parent
93fa2dc974
commit
e41af087e1
@ -0,0 +1,8 @@
|
||||
.toggler {
|
||||
display: grid;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
grid-template-rows: 1fr 1fr;
|
||||
row-gap: 1em;
|
||||
justify-items: center;
|
||||
}
|
@ -1,15 +1,17 @@
|
||||
import Switch from 'react-switch';
|
||||
|
||||
import 'components/toggler/Toggler.css';
|
||||
|
||||
interface Props {
|
||||
checked: boolean;
|
||||
handleChange: any;
|
||||
onChange(checked: boolean): void;
|
||||
}
|
||||
|
||||
export const Toggler = ({ handleChange, checked = false }: Props) => {
|
||||
export const Toggler = ({ onChange, checked = false }: Props) => {
|
||||
return (
|
||||
<label>
|
||||
<label className="toggler">
|
||||
<span>Answer Part 2</span>
|
||||
<Switch onChange={handleChange} checked={checked} />
|
||||
<Switch onChange={(checked) => onChange(checked)} checked={checked} />
|
||||
</label>
|
||||
);
|
||||
};
|
||||
|
@ -1,24 +0,0 @@
|
||||
const domParser = new DOMParser(); // the dom parser is reusable
|
||||
|
||||
export async function getPuzzlesByDay(day: number): Promise<string[]> {
|
||||
const document = await fetchDocument(`https://adventofcode.com/2022/day/${day}`);
|
||||
|
||||
const puzzleNames: string[] = [];
|
||||
const dayDescriptions = document.getElementsByClassName('day-desc');
|
||||
|
||||
for (const dayDescription of dayDescriptions) {
|
||||
const name = dayDescription.children[0].textContent;
|
||||
name && puzzleNames.push(name);
|
||||
}
|
||||
|
||||
return puzzleNames;
|
||||
}
|
||||
|
||||
async function fetchDocument(url: string) {
|
||||
const headers = new Headers({});
|
||||
headers.set('Content-Type', 'text/html');
|
||||
headers.set('Access-Control-Allow-Origin', '*');
|
||||
const response = await fetch(url, { headers });
|
||||
const text = await response.text();
|
||||
return domParser.parseFromString(text, 'text/html');
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
export const day_2 = (input: string) => {
|
||||
return { values: [], answer: '' };
|
||||
};
|
||||
|
||||
export const day_2_part_2 = (input: string) => {
|
||||
return { values: [], answer: '' };
|
||||
};
|
@ -0,0 +1,7 @@
|
||||
export const day_3 = (input: string) => {
|
||||
return { values: [], answer: '' };
|
||||
};
|
||||
|
||||
export const day_3_part_2 = (input: string) => {
|
||||
return { values: [], answer: '' };
|
||||
};
|
@ -0,0 +1,7 @@
|
||||
export const day_4 = (input: string) => {
|
||||
return { values: [], answer: '' };
|
||||
};
|
||||
|
||||
export const day_4_part_2 = (input: string) => {
|
||||
return { values: [], answer: '' };
|
||||
};
|
@ -0,0 +1,7 @@
|
||||
export const day_5 = (input: string) => {
|
||||
return { values: [], answer: '' };
|
||||
};
|
||||
|
||||
export const day_5_part_2 = (input: string) => {
|
||||
return { values: [], answer: '' };
|
||||
};
|
@ -1,11 +0,0 @@
|
||||
import { day_1 } from 'data/solutions/day_1';
|
||||
import { PuzzleResult } from 'models';
|
||||
|
||||
export async function solvePuzzle(day: number, input: string): Promise<PuzzleResult> {
|
||||
switch (day) {
|
||||
case 1:
|
||||
return day_1(input);
|
||||
default:
|
||||
return { values: [], answer: '' };
|
||||
}
|
||||
}
|
@ -0,0 +1,79 @@
|
||||
import { day_1, day_1_part_2 } from 'data/solutions/day_1';
|
||||
import { PuzzleResult } from 'models';
|
||||
import { day_2, day_2_part_2 } from './solutions/day_2';
|
||||
import { day_3_part_2, day_3 } from './solutions/day_3';
|
||||
import { day_4_part_2, day_4 } from './solutions/day_4';
|
||||
import { day_5_part_2, day_5 } from './solutions/day_5';
|
||||
|
||||
export async function solvePuzzle(
|
||||
day: number,
|
||||
part2: boolean,
|
||||
input: string,
|
||||
): Promise<PuzzleResult> {
|
||||
switch (day) {
|
||||
case 1:
|
||||
return part2 ? day_1_part_2(input) : day_1(input);
|
||||
case 2:
|
||||
return part2 ? day_2_part_2(input) : day_2(input);
|
||||
case 3:
|
||||
return part2 ? day_3_part_2(input) : day_3(input);
|
||||
case 4:
|
||||
return part2 ? day_4_part_2(input) : day_4(input);
|
||||
case 5:
|
||||
return part2 ? day_5_part_2(input) : day_5(input);
|
||||
// case 6:
|
||||
// return part2 ? day_6_part_2(input) : day_6(input);
|
||||
// case 7:
|
||||
// return part2 ? day_7_part_2(input) : day_7(input);
|
||||
// case 8:
|
||||
// return part2 ? day_8_part_2(input) : day_8(input);
|
||||
// case 9:
|
||||
// return part2 ? day_9_part_2(input) : day_9(input);
|
||||
// case 10:
|
||||
// return part2 ? day_10_part_2(input) : day_10(input);
|
||||
// case 11:
|
||||
// return part2 ? day_11_part_2(input) : day_11(input);
|
||||
// case 12:
|
||||
// return part2 ? day_12_part_2(input) : day_12(input);
|
||||
// case 13:
|
||||
// return part2 ? day_13_part_2(input) : day_13(input);
|
||||
// case 14:
|
||||
// return part2 ? day_14_part_2(input) : day_14(input);
|
||||
// case 15:
|
||||
// return part2 ? day_15_part_2(input) : day_15(input);
|
||||
// case 16:
|
||||
// return part2 ? day_16_part_2(input) : day_16(input);
|
||||
// case 17:
|
||||
// return part2 ? day_17_part_2(input) : day_17(input);
|
||||
// case 18:
|
||||
// return part2 ? day_18_part_2(input) : day_18(input);
|
||||
// case 19:
|
||||
// return part2 ? day_19_part_2(input) : day_19(input);
|
||||
// case 20:
|
||||
// return part2 ? day_20_part_2(input) : day_20(input);
|
||||
// case 21:
|
||||
// return part2 ? day_21_part_2(input) : day_21(input);
|
||||
// case 22:
|
||||
// return part2 ? day_22_part_2(input) : day_22(input);
|
||||
// case 23:
|
||||
// return part2 ? day_23_part_2(input) : day_23(input);
|
||||
// case 24:
|
||||
// return part2 ? day_24_part_2(input) : day_24(input);
|
||||
// case 25:
|
||||
// return part2 ? day_25_part_2(input) : day_25(input);
|
||||
// case 26:
|
||||
// return part2 ? day_26_part_2(input) : day_26(input);
|
||||
// case 27:
|
||||
// return part2 ? day_27_part_2(input) : day_27(input);
|
||||
// case 28:
|
||||
// return part2 ? day_28_part_2(input) : day_28(input);
|
||||
// case 29:
|
||||
// return part2 ? day_29_part_2(input) : day_29(input);
|
||||
// case 30:
|
||||
// return part2 ? day_30_part_2(input) : day_30(input);
|
||||
// case 31:
|
||||
// return part2 ? day_31_part_2(input) : day_31(input);
|
||||
default:
|
||||
return { values: [], answer: '' };
|
||||
}
|
||||
}
|
Loading…
Reference in new issue