Forked from karfau/aocXX_00
December 4, 2023
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import { expect } from "https://esm.town/v/karfau/chai";
const sum = (sum, current) => sum + current;
const firstStar = (input: string) => {
return input.split("\n").map(
(line, li) => {
if (/ab|cd|pq|xy/.test(line)) return 0;
const vowels = line.match(/[aeiou]/g)?.length;
if ((vowels ?? 0) < 3) return 0;
const double = line.split("").find((c, i) => c === line[i + 1]);
// double && debug(double, `${li} ${line} (${vowels})`);
return double ? 1 : 0;
},
).reduce(sum, 0);
};
const secondStar = (input: string) => {
return input.split("\n").map(
(line, li) => {
const chars = line.split("");
const pair = chars.findIndex((c, i) => line.match(new RegExp(c + line[i + 1], "g"))?.length > 1);
if (pair < 0) return 0;
const oneBetween = chars.findIndex((c, i) => c === line[i + 2]);
return oneBetween < 0 ? 0 : 1;
},
).reduce(sum, 0);
};
expect(
firstStar(`ugknbfddgicrmopn
aaa
jchzalrnumimnmhp
haegwjzuvuyypxyu
haegwjzuvuyyypqu
haegwjzuvuyypcdu
haegwjzuvuyypabu
dvszwmarrgsiwjxmb
dvszwmarrgswjxmb`),
"*1 sample 1",
).to.equal(2);
expect(
secondStar(`qjhvhtzxzqqjkmpb
xxyxx
uurcxstgmygtbstg
ieodomkazucvgmuy`),
"*2 sample 1",
).to.equal(2);
// expect(secondStar(""), "*1 sample 2").to.equal("?");
const input = `uxcplgxnkwbdwhrp
suerykeptdsutidb
dmrtgdkaimrrwmej
ztxhjwllrckhakut
gdnzurjbbwmgayrg
gjdzbtrcxwprtery
fbuqqaatackrvemm
pcjhsshoveaodyko
lrpprussbesniilv
mmsebhtqqjiqrusd
vumllmrrdjgktmnb
ptsqjcfbmgwdywgi
mmppavyjgcfebgpl
zexyxksqrqyonhui
npulalteaztqqnrl
mscqpccetkktaknl
ydssjjlfejdxrztr
jdygsbqimbxljuue
ortsthjkmlonvgci
jfjhsbxeorhgmstc
vdrqdpojfuubjbbg
xxxddetvrlpzsfpq
zpjxvrmaorjpwegy
laxrlkntrukjcswz
pbqoungonelthcke
niexeyzvrtrlgfzw
zuetendekblknqng
lyazavyoweyuvfye
tegbldtkagfwlerf
xckozymymezzarpy
ehydpjavmncegzfn
jlnespnckgwmkkry
bfyetscttekoodio
bnokwopzvsozsbmj
qpqjhzdbuhrxsipy
vveroinquypehnnk
ykjtxscefztrmnen
vxlbxagsmsuuchod
punnnfyyufkpqilx
zibnnszmrmtissww
cxoaaphylmlyljjz
zpcmkcftuuesvsqw
wcqeqynmbbarahtz
kspontxsclmbkequ
jeomqzucrjxtypwl
ixynwoxupzybroij
ionndmdwpofvjnnq
tycxecjvaxyovrvu
uxdapggxzmbwrity
csskdqivjcdsnhpe
otflgdbzevmzkxzx
verykrivwbrmocta
ccbdeemfnmtputjw
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
December 4, 2023