# F#

## Advent of Code F# — Day 9

ps. look out for all my oth­er solu­tions for Advent of Code chal­lenges here.   Day 9 See details of the chal­lenge here. The input for today’s chal­lenge is a very long string like this: (6x9)JUORKH(10x13)LNWIKDMACM(126x14)(21x8)QLKUJNVVZIQGGFCJZMPHK(2x1)ZH(59x3)(38x14)KELEPIDYLCGJUBCXACRSOCEZYXLO… First, let’s see how we’re gonna parse this input. The approach I went with is to recur­sive­ly split the input …

## O(n) solution to Multiply Others problem in F#

Anoth­er tasty chal­lenge that I ran into dur­ing my prepa­ra­tion for tech­ni­cal inter­views is this seem­ing­ly sim­ple prob­lem from Face­book. input [2,3,1,4] out­put [12,8,24,6] Mul­ti­ply all fields except it’s own posi­tion. Restric­tions: 1. no use of divi­sion 2. com­plex­i­ty in O(n) The main chal­lenge is in mak­ing the algo­rithm run in O(n) time. One solu­tion I …

## Anagram Substring Search problem in F#

One inter­est­ing prob­lem I read about as I pre­pare for var­i­ous tech­ni­cal inter­views is the so called Ana­gram Sub­string Search prob­lem where it can be boiled down to the ques­tion “find all per­mu­ta­tions of s with­in b”. Nat­u­ral­ly, after all my endeav­ours with Project Euler and Advent of Code, I cast my mind to how I’d solve this in …

## Advent of Code F# — Day 8

ps. look out for all my oth­er solu­tions for Advent of Code chal­lenges here.   Day 8 See details of the chal­lenge here. The input for today’s chal­lenge looks like this: rect 1x1 rotate row y=0 by 10 rect 1x1 rotate row y=0 by 10 rect 1x1 rotate row y=0 by 5 rotate col­umn x=43 by …

## Ransom Note problem in F#

A prob­lem that has shown up mul­ti­ple times in my prepa­ra­tion for tech­ni­cal inter­views is the so called Ran­som Note prob­lem. To solve this in F# is pret­ty sim­ple. In the inter­est of effi­cien­cy I decid­ed to use a muta­ble Dic­tio­nary instead of the F# Map to store the no. of times a let­ter appears in the …

## Advent of Code F# — Day 7

ps. look out for all my oth­er solu­tions for Advent of Code chal­lenges here.   Sor­ry for the delay in get­ting this post out today, I enjoyed some real­ly fine Ramen with some of the love­ly peo­ple I worked with at Yubl and only man­aged to find time to do the chal­lenge and write this post late in the …

## Advent of Code F# – Day 6

ps. look out for all my oth­er solu­tions for Advent of Code chal­lenges here.   Day 6 See details of the chal­lenge here. The input for today’s chal­lenge looks like this: cmezkqgn nmzrgcft ydp­nd­cps zji­h­hows kvp­txs­rx ubb­vug­wq … Since the only dif­fer­ence between the 2 parts of this chal­lenge is how the char­ac­ters in a col­umn are …

## Advent of Code F# – Day 5

ps. look out for all my oth­er solu­tions for Advent of Code chal­lenges here.   Day 5 See details of the chal­lenge here. Let’s start by adding a hash func­tion that’ll take an input string and return the hexdec­i­mal rep­re­sen­ta­tion of its MD5 hash. From there, we can cre­ate an infi­nite sequence of hash val­ues gen­er­at­ed …

## Advent of Code F# — Day 4

ps. look out for all my oth­er solu­tions for Advent of Code chal­lenges here.   Day 4 See details of the chal­lenge here. The input for today’s chal­lenge looks some­thing like this: bkwzkqsxq-tovvilokx-nozvyiwoxd-172[fstek] wifilzof-wbiwifuny-yhachyylcha-526[qrazx] jvyyvzpcl-jhukf-shivyhavyf-487[zhtsi] kwvacumz-ozilm-kivlg-kwvbiqvumvb-694[gknyw] mvhkvbdib-kmjezxodgz-mvwwdo-omvdidib-837[dmvbi] nzydfxpc-rclop-qwzhpc-lnbftdtetzy-171[cptzd] vhehkyne-unggr-inkvatlbgz-813[gnehk] tcorcikpi-hnqygt-octmgvkpi-570[nzewo] xmtjbzidx-wvnfzo-jkzmvodjin-447[uyzlp] willimcpy-mwupyhayl-bohn-mufym-734[stjoc] sbejpbdujwf-cvooz-xpsltipq-961[azfnd] … So our first task is to turn these into a more usable …

## Advent of Code F# — Day 3

ps. look out for all my oth­er solu­tions for Advent of Code chal­lenges here.   Day 3 See details of the chal­lenge here. First, let’s cap­ture the input for today’s chal­lenge in a text file, say Day03Input.txt. Then, let’s cre­ate a mod­ule to cap­ture the com­mon steps between both parts of the chal­lenge. There’s real­ly not …