Showing posts with label Exercism. Show all posts
Showing posts with label Exercism. Show all posts

Tuesday, July 14, 2015

Exercism: "Largest Series Product in Clojure"

I solved the Largest Series Product problem in Clojure.

This is my solution:

This Exercism problem is based on a Project Euler's exercise I solved some time ago.

You can nitpick my solution here and/or see all the exercises I've done so far in this repository.

Monday, July 13, 2015

Exercism: "Hexadecimal in Clojure"

I solved the Hexadecimal problem in Clojure.

As usual I extracted some helpers and played with partial and the thread last macro (->>) to try to make the solution more readable:

You can nitpick my solution here and/or see all the exercises I've done so far in this repository.

Wednesday, July 8, 2015

Exercism: "Difference Of Squares in Clojure"

I solved the Difference Of Squares problem in Clojure.

This exercise was very easy.

I played with partial and the thread last macro (->>) to try to make the solution more readable:

It turns out that I had done this exercise before.
You can see that version in Euler Project: Problem 6 in Clojure

You can nitpick my solution here and/or see all the exercises I've done so far in this repository.

Sunday, July 5, 2015

Exercism: "Binary Search Tree in Clojure"

I solved the Binary Search Tree problem in Clojure.

I wrote three versions of the to-list function which makes a depth-first traversal of the tree returning the sequence of visited values.

This is my first version:

This is the second one using concat:

And the last one using the tree-seq function that I discovered looking at other solutions in Exercism: You can nitpick my solutions here and/or see all the exercises I've done so far in this repository.

Saturday, July 4, 2015

Exercism: "Accumulate in Clojure"

I solved the Accummulate problem in Clojure.

This is an easy one in Clojure, the only restriction is that you can't use map.

I did 3 versions to practice:

A recursive one:

Another one using reduce:

And another one using a sequence comprehension: You can nitpick the solutions here and/or see all the exercises I've done so far in this repository.

Wednesday, May 20, 2015

Exercism: "Queen Attack in Clojure"

I solved the Queen Attack problem in Clojure.

This is my solution:

I think that the can-attack function should be called can-attack?. I've kept its original name because it's being exercised from the tests given by Exercism.

You can nitpick the solution here and/or see all the exercises I've done so far in this repository.

Exercism: "Robot Simulator in Clojure"

I solved the Robot Simulator problem in Clojure.

This is my solution:

I think that the turn-right and turn-left functions aren't necessary. I've kept them because they are being exercised from the tests given by Exercism.

You can nitpick the solution here and/or see all the exercises I've done so far in this repository.

Tuesday, May 19, 2015

Exercism: "Kindergarten Garden in Clojure"

I solved the Kindergarten Garden problem in Clojure.

This is my solution:

You can nitpick this solution here and/or see all the exercises I've done so far in this repository.

Saturday, May 16, 2015

Exercism: "Crypto Square in Clojure"

I solved the Crypto Square problem in Clojure.

This is my solution:

You can nitpick this solution here or see all the exercises I've done so far in this repository.

Wednesday, May 13, 2015

Sunday, October 5, 2014

Exercism: "Atbash Cipher in Clojure"

I solved the Atbash Cipher problem in Clojure.

This is my solution:


And this is the same but using the ->> macro inside the encode function:


For this exercise I had to learn how the padding parameter of the partition function works.

You can nitpick my solution here or see all the exercises I've done so far in this repository.

Exercism: "Allergies in Clojure"

I solved the Allergies problem in Clojure.

This is my first iteration of the solution:


And this is the second one which is tail-recursive:


This problem was very interesting. To solve it you need to find a solution for a problem called subset sum. Both iterations use backtracking to find the subset of numbers that sum to the allergies score.

I had used this backtracking algorithm once before to solve the N-Queens problem in Racket for the Introduction to Systematic Program Design 1 Coursera course.

You can nitpick my solution here or see all the exercises I've done so far in this repository.

Thursday, August 28, 2014

Exercism: "Raindrops in Clojure"

I solved the Raindrops problem in Clojure.

This is my solution:


Where I used the code I wrote for the Prime factors kata in Clojure

You can nitpick my solution here or see all the exercises I've done so far in this repository.

Exercism: "Prime Factors in Clojure"

I solved the Prime factors problem in Clojure.

You can check my solution in my previous post:
You can nitpick my solution here or see all the exercises I've done so far in this repository.

Wednesday, August 27, 2014

Exercism: "Roman Numerals in Clojure"

I solved the Roman Numerals problem in Clojure.

You can check my solution in my previous post:
You can nitpick my solution here or see all the exercises I've done so far in this repository.

Tuesday, August 26, 2014

Exercism: "Scrabble Score in Clojure"

This is my solution to the Scrabble Score problem in Clojure.


I added some extra tests to complete the provided ones:


You can nitpick my solution here or see all the exercises I've done so far in this repository.

Tuesday, August 5, 2014

Exercism: Revisiting "Space Age in Clojure"

I used metaprogramming as I did in the Meetup problem to simplify the code of the Space Age problem (you can find my previous versions here):


This version has less repetition than the previous ones.

You can nitpick my solution here or see all the exercises I've done so far in this repository.

Exercism: "Triangle in Clojure"

This is my solution to the Triangle problem in Clojure.


This was an easy one.

You can nitpick my solution here or see all the exercises I've done so far in this repository.

Sunday, August 3, 2014

Exercism: "Gigasecond in Ruby"

I solved the Gigasecond exercise in Ruby a month ago but I forgot to post it.

Since my previous post was about the solution to this exercise using Clojure, I'll post here its solution in Ruby:


In this case life is much easier in Ruby :)