Page 1 of 1

[Challenge] Version finder

Posted: Tue Dec 07, 2010 7:16 am
by VladSun
Suppose we have a directory/file structure like this:

/Version/1
/Version/1/1/class.php
/Version/1/2
/Version/1/2/1/class.php
/Version/1/2/3/class.php
/Version/2
/Version/2/0/class.php
/Version/2/3/class.php
/Version/2/3/1/class.php
/Version/2/3/5/class.php

etc.

Task: Create a function (class) that accepts a version number and returns the file path to class.php.
Specs:
[*] $version is formatted as a dot separated string - e.g. 1.4.2
[*] function should return the next lowest version number path
[*] function should throw an Exception if no appropriate versions are found (i.e. the lowest version is higher than the searched one)

Expected results:
[text]1.0.1 => throws Exception
1.1 => /Version/1/1/class.php
1.1.3 => /Version/1/1/class.php
1.2 => /Version/1/1/class.php
1.2.1 => /Version/1/2/1/class.php
1.2.2 => /Version/1/2/1/class.php
1.2.3.5 => /Version/1/2/3/class.php
2 => /Version/2/0/class.php
2.1 => /Version/2/0/class.php
2.4 => /Version/2/3/5/class.php
10 => /Version/2/3/5/class.php[/text]

Good luck! :)

Re: [Challenge] Version finder

Posted: Tue Dec 07, 2010 2:06 pm
by Jonah Bron
Sounds like an interesting challenge. Although, it seems like it would be much more practical to just error if that version doesn't exist, instead of trying to find one...

Re: [Challenge] Version finder

Posted: Tue Dec 07, 2010 2:18 pm
by VladSun
Well, define "version doesn't exist" first.
In general minor version changes doesn't involve interface changes, so it seems practical to have a "vX.Y+" object (I put a stress on the +).

Re: [Challenge] Version finder

Posted: Tue Dec 07, 2010 2:31 pm
by Benjamin
I can build this. What's your budget? :wink:

Re: [Challenge] Version finder

Posted: Tue Dec 07, 2010 2:56 pm
by Weirdan
Benjamin wrote:I can build this. What's your budget? :wink:
One metric ton of fun. You develop this - you get 850kg of fun, and I keep the rest 150kg for reading your solution (supervising your work).

Re: [Challenge] Version finder

Posted: Tue Dec 07, 2010 3:13 pm
by VladSun
Benjamin wrote:I can build this. What's your budget? :wink:
I have already built this ... So... I don't need a budget :P Except my knowledge to share :)