![]() |
| In portuguese "uva" means grape :D |
![]() |
| Sure you do, Borat... sure you do... |
Back to session, UVa Online Judge is a site developed by Valladolid University that has hundreds of problems used during programming contests. I've never participated in one during college, as I was too busy with classes projects, so let's see what is all about :)
I've started with 100 - 3 n + 1 problem
The problem is pretty straightforward: we must check if the described algorithm 3 n + 1 will terminate. And then calculate the maximum cycle length between two numbers i and j.
The solution was not that hard. My main challenge was solving it using TDD.
I've started to write a test to calculate 22 cycle length.
As it was required to know if a number is odd I've also setup some tests to that auxiliary function. The solution must be submitted in a single line, that reads from standard input writes to standard output. I then proceeded to calculate the maximum cycle length between numbers.
My first submission failed.
![]() |
| NOOOOOOOOO! |
After a quick inspection I was not validating if i and j were ordered. A quick new test failing test, change the code to make it green, some small refactorings and voilá. Success!
![]() |
| Yeah you go kid! |
Lessons learned:
- TDD gives a lot of confidence when coding (as expected).
- TDD demands a lot of discipline (sometimes I only wanted to see if something worked and had to force myself to create a new test).
- I only found later that we can submit input to check for correct solutions in http://www.udebug.com/UVa/100
Code available at: https://github.com/DiogoTavaresDeAlmeidaRibeiro/UVa100
















