Skip to content

Commit 5ca82f9

Browse files
committed
day06
1 parent c6161a9 commit 5ca82f9

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

2020/Untitled-1.ipynb

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,49 @@
402402
}
403403
]
404404
},
405+
{
406+
"cell_type": "code",
407+
"execution_count": 1,
408+
"metadata": {},
409+
"source": [
410+
"#!fsharp\n",
411+
"#load \"day06.fsx\"\n",
412+
"open Day06\n",
413+
"\n",
414+
"let testData06 = [\n",
415+
" \"abc\"\n",
416+
" \"\"\n",
417+
" \"a\"\n",
418+
" \"b\"\n",
419+
" \"c\"\n",
420+
" \"\"\n",
421+
" \"ab\"\n",
422+
" \"ac\"\n",
423+
" \"\"\n",
424+
" \"a\"\n",
425+
" \"a\"\n",
426+
" \"a\"\n",
427+
" \"a\"\n",
428+
" \"\"\n",
429+
" \"b\"\n",
430+
"]\n",
431+
"\n",
432+
"// testData06\n",
433+
"readLines \"06\"\n",
434+
"|> day06\n",
435+
"|> printf \"%A\""
436+
],
437+
"outputs": [
438+
{
439+
"output_type": "execute_result",
440+
"data": {
441+
"text/plain": "6504"
442+
},
443+
"execution_count": 1,
444+
"metadata": {}
445+
}
446+
]
447+
},
405448
{
406449
"cell_type": "code",
407450
"execution_count": 1,

2020/day06.fsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
let day06 (arr: seq<string>) =
2+
seq {
3+
let mutable cSet = Set.empty<char>
4+
for x in arr do
5+
match x.Length with
6+
| 0 ->
7+
yield cSet
8+
cSet <- Set.empty<char>
9+
| _ -> cSet <- x.ToCharArray() |> Set.ofArray |> (Set.union cSet)
10+
yield cSet
11+
}
12+
|> Seq.map Set.count
13+
|> Seq.sum
14+
15+
16+

0 commit comments

Comments
 (0)