[Challenge] Version finder

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

[Challenge] Version finder

Post 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! :)
There are 10 types of people in this world, those who understand binary and those who don't
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: [Challenge] Version finder

Post 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...
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: [Challenge] Version finder

Post 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 +).
There are 10 types of people in this world, those who understand binary and those who don't
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: [Challenge] Version finder

Post by Benjamin »

I can build this. What's your budget? :wink:
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: [Challenge] Version finder

Post 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).
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: [Challenge] Version finder

Post 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 :)
There are 10 types of people in this world, those who understand binary and those who don't
Post Reply