Sunday, October 19, 2014

hackerrank scala template for i/o (reading and writing) from STDIN and STDOUT

https://www.hackerrank.com is a fun way to hone your programming skills in algorithms, functional programming, and other areas.

You do small exercises and get computer feedback immediately, which is what makes it so great. Some of the exercises have you just fill out a method body, but other ones require you to process from STDIN and write to STDOUT.

This makes it a bit harder to test in an IDE. Here is a simple template for Scala which lets you just plug in what you will copy back to hackerrank.

This example does the factorial function, with inputs of 2, 3 and 5. Once you're done testing your solution, copy the Solution object only back to hackerrank.

https://gist.github.com/cngdean/3702b7be4b6d298dd69c

I am still in the process of learning Scala so apologies for any non-idiomatic Scala above :)

No comments:

Post a Comment