Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
Will fail in case nodes addreess are not monotonically increase/decrease:
Will fail in case nodes addreess are not monotonically increase/decrease:
Thanks for the kata! Although it would be more difficult and more fun if imports were disabled :)
Nice kata, thanks! A couple of comments:
Exactly! :)
Very nice kata, thanks!
This comment is hidden because it contains spoiler information about the solution
Wow, nice to see the reference to Uncle Bob, I like this guy too :) Totally agree.
Very nice kata, thanks a lot!
This comment is hidden because it contains spoiler information about the solution
Have someone implemented solution with better than linear (O(n)) time complexity?
The probem is that in expression
d = a/n;
'a' is (signed)int
but 'n' issize_t
(which isunsigned long
). Asunsigned long
(64 bits) is longer thanint
(32 bits) the intermediate computation is performed asunsigned long
. In case 'a' is negative (i.e. the most significant bit is 1) after conversion tounsigned long
it would be a big positive number with 31st bit == 1. After division this bit is shifted right and the new 31st bit will be 0. After converson back toint
(assigning to 'd') the result would not be negative any more but an "odd number" :) To fix the issue used = a/(int)n
Nice kata, thanks. Though, the description doesn't specify the behavior in case of an incorrect format string (e.g.
"{"
(single open bracket) or"{i"
(incomplete type specifier)), neither the test suite verified such test cases.In case the format string is "{{i}" the output should be "{i}" (as the beginning "{{" should convert to "{" and the remaining "i}" is not a format specifier anymore and should copy as ordinary characters). Looks like in your solution the result would be "{<some_number>".