Tag: Scala

Elf and Guards – Days 5 and 6

It couldn’t last forever—spending consecutive days writing about my progress in the Advent of Code took too much time and the rest of my life knocked on the door. In this post, I will try to update you quickly on days five and six.

On day 5 we had to assist an unfortunate handbook printer to get the updated pages in the correct order. Being magic-elven stuff, the proper order is not the natural increasing order of integers, but a custom order defined by number pairs – e.g. 43|12 means that page 43 has to be followed immediately by page 12. But stuff is not that simple, the order relationship is not linear like abc, but may branch, so to give you an idea, after a may come either b or d and then are both followed by c.

Continue reading “Elf and Guards – Days 5 and 6”

Finding XMAS – Day 4

Day 4 of the Advent of Code presents you with two new puzzles based on the word search puzzle idea. For some reason, you are teleported to the Ceres Elven Station (that made an appearance in AoC 2019), but there’s nothing for you to see here (yet) – not even the chief historian we looking for. So a small elf asks for your help to solve her word search.

Being Xmas elves the word you have to look for is “XMAS”, it can be written straight or reverse and can be written in any direction left, up left, up, up right, right down right, down and down left.

Continue reading “Finding XMAS – Day 4”

Elves’ Programming Language – Day 3

There are plenty of programming languages and, of course, Xmas elves have their own. Although your main goal is still to find the Chief Historian, we are now in a warehouse, historian minions are wandering around looking for their boss and we are tasked to fix the computer1.

This puzzle seemed a bit easier than the first two days, but I found it somewhat underspecified. You have to scan a text for patterns like “mul(n,m)” with n and m integers. For each pattern multiply n by m and sum all the products together.

Continue reading “Elves’ Programming Language – Day 3”

Elves’ Advent Quest – Day 2

After warming up with the first day’s puzzle, here we are with the second day. The bar is still low, but not as low as yesterday. With the coordinates decoded in the last puzzle, everyone runs to the nearest location which happens to be a nuclear plant (for reindeer needs). While we are here the elves running the plant ask for your help to analyze some data looking for anomalies.

Yes, we are in a hurry to look for the chief historian elf, but we also have 25 days to fill with puzzles. So here we go.

Continue reading “Elves’ Advent Quest – Day 2”

Helping Elves One Star at a Time

That period of the year has finally come. That cozy winter feeling of cold outside the window, while busy waiting for the holidays. As a long-standing tradition that started last year, this is the time I help Elves prepare for Xmas in the Advent of Code.

Each day of Advent, the Advent of Code, proposes a couple of puzzles that can be solved by writing some code. There are no constraints on the language or the approach since the result of the puzzle is an integer number. Also, there is no deadline, you can continue working on the puzzles after Xmas. And there is no prize, you just know you did the right thing helping the elves and Santa.

Continue reading “Helping Elves One Star at a Time”

The Advent of Scala Code – What I Learned

It all started with an innocent-looking question, from a colleague – “This year I’d like to propose an office leaderboard for the Advent of Code, what do you think?”. Well, why not? I made a lame attempt at AoC some years ago and possibly gave up on the first day for lack of time (and commitment).

But this looked like an interesting challenge and I agreed and promoted the idea. Since I miss working in Scala, I wrote AoC solutions in Scala 3 to dust off some rust (ops) and learn the new syntax. Solving a (double) puzzle a day for 25 days (Xmas day included), is not a light endeavor. It requires at least from 1 to 2 hours and is increasingly difficult to squeeze into a normal working day especially if you have a life.

Continue reading “The Advent of Scala Code – What I Learned”

Scala Italy 2023 – Scala Blues

It was 2015 when I attended my first Scala Italy conference. I was freshly landed in the functional programming magic world and I was tasked by my boss to asses whether Scala was a technology with a future or just a fade. I sat there, as proved by the picture used over the years as a background for the conference website, and enjoyed the show.

The conference was well organized, with a bunch of sponsors and some hundred people attending. My report, reinforced by attending Scala Days 2016 in Berlin, was that Scala was viable with quite a strong interest and support from the industry.

Over the years the conference grew, I missed the Venice edition in 2016, but I was in Rome in 2017, Florence in 2018, and eventually Bologna in 2019. Both Florence and Bologna were two-day events.

Continue reading “Scala Italy 2023 – Scala Blues”

Lambda Headache for Mere Mortals

A few years ago I attended a talk at a Lambda World Conference about Lambda Calculus. Although not an eye-opener (in fact that level of abstraction is rarely needed, nor advisable, in everyday programming), it was thought-provoking. By wisely crafting mathematical functions you could describe algorithms, fully equivalent to the good old recipe-like imperative programming code.

The point is that those lambda functions are really twisted.

Reading some anecdotes about Alonzo Church it is immediately clear he was quite a guy. And devising lambda calculus required quite a mind.

Since lambda calculus is just functions, no statement, it came to my mind I could use it to devise a solution to my “if-less” programming quiz.

The solution I prepared was too complex to be explained in my previous post, so I decided to write this post.

Continue reading “Lambda Headache for Mere Mortals”

Scala Job Interview – FP questions

Welcome to the third installment of the Scala Job Interview Questions series. This time I’ll try to answer functional programming questions, likely my score will be a bit less than the first two editions (General Questions and Language Questions) because I like Functional Programming, but I’m still a traditional programmer (imperial?) who studied Algebra at high school and uni and then consider Algebra as useful (for programmers) as a doorstop in a tent.

Young and foolish I was, but who could imagine, back then that to run the dance of the bits I would ever need monoids?

Let’s not waste other time in void introduction, and start with the questions and my answers.

Continue reading “Scala Job Interview – FP questions”

Scala Job Interview – Language Questions

This is the second installment of this series. The first post in the series gives you a bit more context. Anyway, this is my try to answer Scala Interview grade Questions I found in a blog post by Signify. You can find alternate answers here.

Language Questions

What is the difference between a var, a val and def?

All these keywords are for declaring something. var declares a variable, val declares a variable that cannot be re-assigned and def declares a function.

scala
var a = 3
val b = 3
def c = 3

In the above code, a is a variable as you can find in almost every language, you can increment it, re-assign it. Standard stuff.

b is a variable bound to value 3 forever? Attempting to change its value results in a compile-time error. c is a parameterless function that returns 3. Interestingly a, b and c evaluate to the integer 3. Also note that val just prevents reassignment, not value change. E.g. in the following code:

scala
class Foo {
  private var a: Int = 3
  def change( newA : Int ) : Unit = { a = newA }
}

val x = new Foo()
x.change(8)

There is no compile-time error because you are not changing the bound between x and the instance that references. You are just changing the instance.

Continue reading “Scala Job Interview – Language Questions”