# F#

## Advent of Code F# – Day 15

ps. look out for all my other solutions for Advent of Code challenges here.   Day 15 See details of the challenge here. Today’s challenge is pretty straight forward, and a brute force approach would have suffice – try every t from 0 to inifinity and return the first t that satisfies this equation for all …

## Advent of Code F# – Day 14

ps. look out for all my other solutions for Advent of Code challenges here.   Day 14 See details of the challenge here. Today’s challenge is very similar to that of Day 5, but the requirements for a valid hash value is different this time. As before, we’ll start by defining a hash function that will accept a string and return …

## Advent of Code F# – Day 13

ps. look out for all my other solutions for Advent of Code challenges here.   Day 13 See details of the challenge here. Today’s challenge involves solving two separate problems: counting set bits in an integer level order tree traversal For the first problem, I recommend reading through this blog post which covers several approaches and optimizations for this …

## Equilibrium Index problem in F#

A good friend pointed me to a nice coding challenge she encountered – finding the Equilibrium Index of an array in O(n) time. After a quick discussion we ended up with 2 solutions, and naturally I had to code them up in F#   Solution 1 This is the same approach to the one you saw in …

## Advent of Code F# – Day 12

ps. look out for all my other solutions for Advent of Code challenges here.   Day 12 See details of the challenge here. The input for today’s challenge looks like this: cpy 1 a cpy 1 b cpy 26 d jnz c 2 jnz 1 5 cpy 7 c … This is very similar to Day 23 …

## Advent of Code F# – Day 11

ps. look out for all my other solutions for Advent of Code challenges here.   Day 11 See details of the challenge here. Today is perhaps the first AOC challenge that is really challenging and required a lot of thought, and I really enjoyed it! First, let’s model the problem domain. and we’ll need a way to …

## Implementing a BST in F#

Binary Search Trees (BST) seem to be a hot topic in technical interviews. So, in order to help me prepare for all these grilling technical tests, I thought I’d give it a crack at implementing insertion, deletion and verification logic since I’ve already done both breath-first and depth-first traversals.   Verification Starting with something nice and …

## Depth-First Tree Traversal in F#

We looked at breath-first tree traversal earlier today, now let’s take a look at depth-first tree traversal as well. Here, we loop through the tree starting with the root, yield the value for each of the nodes before recursively traversing down all the left branch first and then the right branch.   Try it Yourself   Links Breath-First …

## Level Order Tree Traversal in F#

Another common problem I see during my preparation for technical interviews is the Level Order Tree Traversal (or Breadth-First) problem. I always like to think with my F# hat on when I solve algorithm problem, so here’s an implementation in F# . Here we have a nested recursive loop function that: yields the value from the nodes …

## Advent of Code F# – Day 10

ps. look out for all my other solutions for Advent of Code challenges here.   Day 10 See details of the challenge here. The input for today’s challenge looks like this: bot 171 gives low to bot 4 and high to bot 84 bot 1 gives low to bot 117 and high to bot 81 bot 82 …