[Community Puzzle] English length units conversion

https://www.codingame.com/training/medium/english-length-units-conversion

Send your feedback or ask for help here!

Created by @nicola,validated by @DevKirill,@CopperFr and @java_coffee_cup.
If you have any issues, feel free to ping them.

Based on all the IDE tests I assumed that the unit names are single words (it is not explicitly stated in statement). As I split input by space, this resulted a nasty fail in the last validator. It took quite some time to figure out that the input parsing was the culprit, and not my solver algorithm or its implementation.

I suggest to make this fact more explicit in the statement and/or put a two-word unit name also in one of the IDE tests.

2 Likes

There are units like nautic miles or roman miles. They are in the last test case and the nautic mile is even the first met unit in the statement. :wink:

You are right, my bad.
Interestingly, my original code with bad space split passed the last ide test but not the last validator. Most likely because the first word of these composite unit names were still unique in ide, but possibly not in the validator.

3 Likes

Hello,

Thanks for the puzzle Dude !

Thanks, you just saved me a lot of time!

1 Like

Yup, my php code passes all the tests but not the last validator. I sscanf instead of splitting by spaces. I even tried md5 on the units, and htmlspecialchars on the input. What am I missing? Code works with apostrophies anyway… I can’t think of anything I missed, unless validator has bad input. help?

there’s no constraints shown for the value of n, so is it just timing out because n is too large?

Maybe yes.
What kind of algorithm are you implementing?

I’m just using one recursive function that explores the links from start to dest. The current path explored I’m just using a stack, I just added a stack for the deadends found to reduce the number of calls. The links are saved bidirectionally, so reversing start and dest shouldn’t matter. I reduce using the gcd of the n and d, i guess it’s possible php is truncating large #s. I can’t seem to finagle the 4th validator. plz help.

Hi,
How are you decoding the very first line of input? No problem with spaces in unit1 and/or unit2?

1 Like

As any rational ratio can turn up in the exchange rates, it is important to accumulate the result during tree walk as a (nominator, denominator) pair and not as a single float.
I also use a stack for DFS tree traversal, recursion is not even needed (but should be fine)

Additionally, make sure your parser works even if two unit names are starting with the same word.
My parser is like this:

$line = explode(' = ', stream_get_line(STDIN, 40 + 1, "\n"));
$left = explode(' ', $line[0], 2);
$value1 = intval($left[0]);
$unit1 = $left[1];
$right = explode(' ', $line[1], 2);
$value2 = intval($right[0]);
$unit2 = $right[1];
$conversion[$unit1][$unit2] = [$value1, $value2];
$conversion[$unit2][$unit1] = [$value2, $value1];

Do you apply normalization to the end result before outputting? (I mean getting gcd and then intdiv with it.)

1 Like

Hi,
as some others comments, i pass all the ide test but not the last validator…

Any clue about this last validator data set ?

thx

How do you parse the first line?

i m in javascript, and use a simple : fromTo = readline().split(’ in ') to get an array => “spindle in league” => [spindle, league]
did i lose something ? ^^

The units may contain spaces.

lol thank you !

hey, now i threat inputs with spaces,
as i rename spindle to spin dle with the last test (spi ndle in league, and i change the definition 1 spi ndle = 120 skein) and i get the right result,
but 100% in tests, and still 75% in submission…
i can’t figure out what happen here… :cry: lost time…
thx for your attention

my bad ^^ i understood…
don’t forget to reformalize the name of the spaced parameter as it was in inputs… thx and sorry for my last message

1 Like

Ok forget it, i think there is a problem with my debugging informations.