Advent of Code – Day 10

Part 1: The code is pretty simple if we go ahead with using recursion. I started with an iterative solution but quickly realised I am dealing with a list of numbers, going through the numbers one at a time. This is the prerequisite of solving a recursive problem. The Recursive Solution: The condition is that the input string will have at least one number, otherwise it won’t make any sense. Though we are not dealing with erroneous input here.

PAIP

I have recently started with Paradigms of Artificial Intelligence Programming in order to learn Common-Lisp. I did use it for the AI course that I had in college. The course was mostly a joke, with just a few low-level algorithms being covered (and these too were taught in Prolog), but getting some information about AI I came across Lisp and read through Paul Graham’s excellent book ANSI Common Lisp. Although I didn’t get much chance to use Lisp anywhere else after that, the book and its exercises made me understand recursion at the very basic and grand level.

Magit – A use case

I have been using magit for some time at a more superficial level. From what I can see, it is remarkable; at least I don’t have to type a lot of git commands. Command line is cool and everything, but typing a command again and again will waste the time and just might start a pain in your hand. Since most of my coding happens in emacs, I am delighted that magit exists and makes common and most repetitive things only a matter of few keystrokes.

Overly Technical Brain and Life

I hope what I am writing here makes sense, but I believe – from whatever life experience that I have – that an overly technical brain is somewhat good for the professional life, but is not so good when it comes to understanding the world surrounding us. And the world includes everything from not so living things to most of the living things (e.g. people). Somewhat good for the professional life, because no matter in which profession you are in, the limits of understanding the field is almost impossible, which is a good thing because that means a lot of development might happen in that area, and this is good for everyone.

Advent of Code – Day 7

Part 1: This part took the most time till now. It presents the user with a small DSL which has to be solved because little Bobby Tables cannot solve it. My first thought was to solve it by Algebraic Data Types since the operations and data are essentially recursive and pattern matching would have helped here too. But instead of jumping from one language to another, I decided to go ahead with C# right now.

Understanding Events in C#

Events in CSharp Events in C# follow the pub-sub model where the publisher class holds a list of subscribers which let the publisher know that they are waiting for something interesting to happen and the publisher should make them aware if the interesting thing does happen. Event handling in C# requires one to understand delegates: which are boxes which can hold methods of a particular shape and can call them at runtime.

DFS in Graphs

DFS (Depth First Search) helps in finding the connected nodes in a graph. By connected, we mean two nodes which can be reached by following a set of edges. This makes sense in both directed and undirected graph – in directed graph, there’s only one way of moving along the edge, but in the undirected graph we can move both forward and backwards along the edge. In simpler terms, we would want to start at a given node, follow along a path until we reach a deadend, and then move backtrack until we reach a new unvisited node, choose it and start moving along its path.

For Comprehensions in Scala

What is a for comprehension? Just like imperative programming languages, Scala provides a for-loop, but the similarities end there. Primarily it is used for iterating collections, and to extract items out of them. The benefit of for is that its clear and concise. Taking the example of creating a list of all the indices of a matrix, we will do something like this in Scala: 1 2 3 4 5 6 def indices(row: Int, col: Int) = (0 until row).

Functional Programming in Scala: Weeks 5 and 6

List methods: How to create the methods like take, drop, reverse, append, etc. on Lists. Implementation of mergesort. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 def msort(list: List[Int]): List[Int] = { val mid = list.length / 2 if (mid == 0) list else { def merge(xs: List[Int], ys: List[Int]): List[Int] = (xs, ys) match { case (Nil, ys) => ys case (xs, Nil) => xs case (x::xs1, y::ys1) => if (x < y) x :: merge(xs1, ys) else y :: merge(xs, ys1) } val (ys, zs) = list.

Functional Programming in Scala: Week 4

Everything is an Object This week has been pretty dense as compared to the other weeks and Prof. Odersky started with showing how unlike Java, Scala treats every type as objects. Therefore, as compared to Java, every type a built-in wrapper which transforms to Java type pseudo-objects during compile time. And since the method names can be almost anything, the operations are usually method names: a + b is actually a.