Live coding Advent of Code 2015 (first 10 puzzles, OCaml, F#, Haskell and Python)

preview_player
Показать описание
Some friends and family have gone back to Advent of Code 2015 for practice. I decided to join in on the fun!

0:00 Intro
0:37 Day 1, Part 1 in OCaml
6:20 Day 1, Part 2 in OCaml
12:39 Day 2, Part 1 in F#
20:00 Day 2, Part 2 in F#
24:19 Day 3, Part 1 in Haskell
33:23 Day 3, Part 2 in Haskell
39:27 Day 4, Part 1 in Python
46:48 Day 4, Part 2 in Python
48:05 Day 5, Part 1 in F#
1:02:33 Day 5, Part 2 in F#
1:15:37 Day 6, Part 1 in Python
1:33:25 Day 6, Part 2 in Python
1:36:51 Day 7, Part 1 in Haskell
1:47:12 Day 7, Part 2 in Haskell
1:49:25 Day 8, Part 1 in F#
1:59:41 Day 8, Part 2 in F#
2:04:33 Day 9, Part 1 in Python
2:29:52 Day 9, Part 2 in Python
2:30:55 Day 10, Part 1 in Haskell
2:40:00 Day 10, Part 2 in Haskell
2:41:15 Day 11, Unfinished (had to leave) in Python
Рекомендации по теме
Комментарии
Автор

appreciate your videos! looking forward to other days! great!!

rastislavsvoboda
Автор

Hi
for D9 I've iterated over permutations(cities, len(cities))
and computed the distance of all possible paths
then get min/max

rastislavsvoboda
Автор

Hi
I did D10 in F# (at 2:30:50)
not sure it there is some kind of group like you used in Haskell
but I've did this



let lookAndSay nums =

        match nums with




|> List.rev

let solve limit input =
    [ 1 .. limit ]

    |> List.length



rastislavsvoboda
Автор

Hi Michael
I think in D5p2 isReallyNice function is not correct
maybe you got lucky and it counts good for your input
but I believe it is wrong for lines when there are 4 same chars in row
I have function

let isNice2' (line: string) =
let hasDoubles =
let mutable res = false

for i in 0 .. line.Length - 2 do
let pair = line.Substring(i, 2)
let newLine = line.ToCharArray()
newLine.[i] <- ' '
newLine.[i + 1] <- ' '
let s = new string (newLine)
if s.Contains pair then res <- true

res

hasDoubles
&& hasRepeatWithBetween (line |> Seq.toList)

I'm not that good at F#
what I do here is that for any consecutive 2 chars
I replace it with 2 spaces at that position
and trying to find if the same 2 chars are still in the string
I've used some idea from my original python version when I first time solved D5

def is_nice(word):

hasDoublePair = False
hasRepeat = False
wordLen = len(word)
for i, s in enumerate(word):
if i < wordLen - 1:
searchPair = word[i:i+2]
newW = word[:i] + " " + word[i+2:]
hasDoublePair |= searchPair in newW

if i < wordLen - 2:
hasRepeat |= word[i] == word[i+2]

if hasDoublePair and hasRepeat:
return True

return False

and I did not know how to better translate it to F# (for the doublePair stuff)

when I compared your and my func, I got these different answers
[(false, true, "xilodxfuxphuiiii"); (false, true, "pzkkkkwrlvxiuysn"); (false, true, "bkkkkcwegvypbrio")]

rastislavsvoboda