Skip to content

Commit 2116c72

Browse files
committed
4:32 / 8:19 : wrong answer for .2, had to wait a minute to resubmit. and pretty slow.
1 parent 13f2737 commit 2116c72

File tree

6 files changed

+1220
-0
lines changed

6 files changed

+1220
-0
lines changed

2024/solutions/day2/day2.1.ts

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import {fhmain} from "../../../src/fheader";
2+
fhmain(__filename);
3+
/*
4+
input: string, lines: string[], dblines: string[][]
5+
copy(text: string) → clipboard
6+
error(message: string) → thrown error
7+
-5..mod(3) → @mod(-5, 3)
8+
*/
9+
10+
// Cardinals:
11+
// [[1,0],[-1,0],[0,1],[0,-1]]
12+
// +Diagonals:
13+
// [[1,0],[-1,0],[0,1],[0,-1],[-1,-1],[-1,1],[1,-1],[1,1]]
14+
15+
export {};
16+
17+
const practice = `
18+
7 6 4 2 1
19+
1 2 7 8 9
20+
9 7 6 2 1
21+
1 3 2 4 5
22+
8 6 4 4 1
23+
1 3 6 7 9`;
24+
// input = practice;
25+
input = input.trim();
26+
27+
let count = 0;
28+
for(const line of input.split("\n")) {
29+
let pv = null;
30+
let pass_incr = true;
31+
let pass_decr = true;
32+
33+
for(const itm of line.split(/\s+/)) {
34+
const v = +itm;
35+
if(pv != null) {
36+
// 3 - 1 = 2
37+
const diff = v - pv;
38+
const dabs = Math.abs(diff);
39+
if(diff > 0) {} else {pass_incr = false}
40+
if(diff < 0) {} else {pass_decr = false}
41+
if(dabs >= 1 && dabs <= 3) {
42+
43+
}else{
44+
pass_incr = false;
45+
pass_decr = false;
46+
}
47+
}
48+
pv = v;
49+
}
50+
console.log(pass_incr, pass_decr);
51+
if(pass_incr || pass_decr) {
52+
count += 1;
53+
}
54+
}
55+
console.log(count);
56+
57+
// input.
58+
59+
// hi! i'm glad you're excited to code
60+
// but consider fully reading the problem statement first.
61+
// Sincerely, future you.
62+
63+
64+
// 4:32

2024/solutions/day2/day2.2.ts

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import {fhmain} from "../../../src/fheader";
2+
fhmain(__filename);
3+
/*
4+
input: string, lines: string[], dblines: string[][]
5+
copy(text: string) → clipboard
6+
error(message: string) → thrown error
7+
-5..mod(3) → @mod(-5, 3)
8+
*/
9+
10+
// Cardinals:
11+
// [[1,0],[-1,0],[0,1],[0,-1]]
12+
// +Diagonals:
13+
// [[1,0],[-1,0],[0,1],[0,-1],[-1,-1],[-1,1],[1,-1],[1,1]]
14+
15+
export {};
16+
17+
const practice = `
18+
7 6 4 2 1
19+
1 2 7 8 9
20+
9 7 6 2 1
21+
1 3 2 4 5
22+
8 6 4 4 1
23+
1 3 6 7 9`;
24+
input = practice;
25+
input = input.trim();
26+
27+
function dotry(ls: string[]) {
28+
29+
30+
31+
let pv = null;
32+
let pass_incr = true;
33+
let pass_decr = true;
34+
35+
for(const itm of ls) {
36+
const v = +itm;
37+
if(pv != null) {
38+
// 3 - 1 = 2
39+
const diff = v - pv;
40+
const dabs = Math.abs(diff);
41+
if(diff > 0) {} else {pass_incr = false}
42+
if(diff < 0) {} else {pass_decr = false}
43+
if(dabs >= 1 && dabs <= 3) {
44+
45+
}else{
46+
pass_incr = false;
47+
pass_decr = false;
48+
}
49+
}
50+
pv = v;
51+
}
52+
console.log(pass_incr, pass_decr);
53+
if(pass_incr || pass_decr) {
54+
return true;
55+
}
56+
return false;
57+
}
58+
59+
let count = 0;
60+
olp: for(const line of input.split("\n")) {
61+
const ls = line.split(/\s+/);
62+
63+
if(dotry(ls)) {count += 1; continue;}
64+
for(let i = 0; i < ls.length; i++) {
65+
const ldup = [...ls];
66+
ldup.splice(i, 1);
67+
if(dotry(ldup)) {
68+
count += 1;
69+
continue olp;
70+
}
71+
}
72+
}
73+
console.log(count);
74+
75+
// input.
76+
77+
// hi! i'm glad you're excited to code
78+
// but consider fully reading the problem statement first.
79+
// Sincerely, future you.
80+
81+
// 8:19

2024/solutions/day2/day2.3.ts

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import {fhmain} from "../../../src/fheader";
2+
fhmain(__filename);
3+
/*
4+
input: string, lines: string[], dblines: string[][]
5+
copy(text: string) → clipboard
6+
error(message: string) → thrown error
7+
-5..mod(3) → @mod(-5, 3)
8+
*/
9+
10+
// Cardinals:
11+
// [[1,0],[-1,0],[0,1],[0,-1]]
12+
// +Diagonals:
13+
// [[1,0],[-1,0],[0,1],[0,-1],[-1,-1],[-1,1],[1,-1],[1,1]]
14+
15+
export {};
16+
17+
const practice = ``;
18+
// input = practice;
19+
input = input.trim();
20+
21+
// input.
22+
23+
// hi! i'm glad you're excited to code
24+
// but consider fully reading the problem statement first.
25+
// Sincerely, future you.

2024/solutions/day2/day2.4.ts

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import {fhmain} from "../../../src/fheader";
2+
fhmain(__filename);
3+
/*
4+
input: string, lines: string[], dblines: string[][]
5+
copy(text: string) → clipboard
6+
error(message: string) → thrown error
7+
-5..mod(3) → @mod(-5, 3)
8+
*/
9+
10+
// Cardinals:
11+
// [[1,0],[-1,0],[0,1],[0,-1]]
12+
// +Diagonals:
13+
// [[1,0],[-1,0],[0,1],[0,-1],[-1,-1],[-1,1],[1,-1],[1,1]]
14+
15+
export {};
16+
17+
const practice = ``;
18+
// input = practice;
19+
input = input.trim();
20+
21+
// input.
22+
23+
// hi! i'm glad you're excited to code
24+
// but consider fully reading the problem statement first.
25+
// Sincerely, future you.

2024/solutions/day2/day2.5.ts

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import {fhmain} from "../../../src/fheader";
2+
fhmain(__filename);
3+
/*
4+
input: string, lines: string[], dblines: string[][]
5+
copy(text: string) → clipboard
6+
error(message: string) → thrown error
7+
-5..mod(3) → @mod(-5, 3)
8+
*/
9+
10+
// Cardinals:
11+
// [[1,0],[-1,0],[0,1],[0,-1]]
12+
// +Diagonals:
13+
// [[1,0],[-1,0],[0,1],[0,-1],[-1,-1],[-1,1],[1,-1],[1,1]]
14+
15+
export {};
16+
17+
const practice = ``;
18+
// input = practice;
19+
input = input.trim();
20+
21+
// input.
22+
23+
// hi! i'm glad you're excited to code
24+
// but consider fully reading the problem statement first.
25+
// Sincerely, future you.

0 commit comments

Comments
 (0)