I tried to solve Easy Practice https://www.codingame.com/ide/puzzle/addem-up
I passed all tests with no cheats.
when I Submit it - all tests was failed.
probably internal tests and “Submit tests” use some different configs.
We fixed the issue. Thanks for reporting the problem.
BTW, @RichardAndrewCatterm I see that your solution for Horse Racing Dual, which seems to be optimal, does not pass the last validator. This is likely to be an issue on our side. We’ll investigate (more time needed for execution of a D program?, bad handling of inputs?) but this will require more time to fix.
my experience tells me that D input/output should work x10+ faster than C++.
if you are building an executable there should be no brakes when processing data, the GC does not intervene at the beginning either.
LDC generates excellent machine code, DMD is 10-20% worse (maybe), but DMD compiles faster (maybe). and I didnt use GDC, so nothing to tell about it.
that tells to runtime use precise garbage collector - do less work than conservative one that checks all memory that eats time for Stop-The-World.
option “parallel” ask to use 4 threads for mark&sweep processing (u know better how many thread test instance has)
u can read here more https://dlang.org/spec/garbage.html#gc_config
and u can play with other options too: initReserve, minPoolSize, maxPoolSize, incPoolSize cuz u better know how many memory test instance has.
I just tried out this D language (already looking forward to the E support ) with some easy puzzles and found this minor issue:
When input is a single integer the stub generates:
int variable;
readf!" %d\n"(variable);
This throws a nice exception with not too meaningful message td.format.FormatException@/opt/coderunner/dlang/dmd/linux/bin64/…/…/src/phobos/std/format.d(1535): parseToFormatSpec: Cannot find character ’ in the input string.
Examples: Rubik, Count as I count
As I am completely new to D, it took me some time to figure out that I need to delete \n from the readf line…
I experienced similar problem to my previous post also in cases with multiple integer inputs. It seems the problem is with the expected \n after the very last input
Example. puzzle ‘Smooth’ stub generates:
int N;
readf!" %d\n"(N);
for (int i = 0; i < N; i++) {
long F;
readf!" %d\n"(F);
Works for N-1 iterations and throws exception when reading the last input. But works like charm if I replace readf with:
if (i < N - 1)
readf!" %d\n"(F);
else
readf!" %d"(F);
Thanks for your valuable feedback @zelyony . I’ve adapted the code generator we use for the C to generate the D code but maybe that wasn’t the right decision. I had to add these \n in the reads as a workaround for other issues.
I think I should change the way I read the input by instead reading the whole line, and split when there are several variables on the same line. That’s how we handle in input in Python for instance.
use only long for integers and double for floats. that simplifies decision in cases where to use int or long
reading one number in whole line: long/double
// “strip” removes last ‘\n’
// “auto” allow simplifies generator too - no need check rvalue for valid type
auto N = readln.strip.to!long; // or .to!double
reading string:
auto S = readln.strip; // removes ‘\n’
read set of numbers:
// “split” removes any spaces (’ ', ‘\n’, ‘\r’, ‘\t’)
auto NumArray = readln.split.to!(double[]); // or .to!(long[])
read set of words:
auto StrArray = readln.split; // StrArray is string[] with .length etc
u can wait a week for approval/suggestions from other users.
if u have another questions for some specific situation just ask.
auto nums = readln.split.to!(long[]);
auto oneValue = nums[0];
auto nextValue = nums[1];
// using oneValue & nextValue
auto data = readln.split; // string[]
auto name = nums[0];
auto age = nums[1].to!long;
// using name and age
I’m not sure to understand the advantages of using auto?
I’ve modified how we read stdin to read the whole line every time. Feedback welcome! (Do not forget to reset the code if you’ve already modified the code)
I solved Mars Lander 2 in D. My solution is a hardcoded solution because (because it’s my solution from the mars lander 2 optimization puzzle).
It’s a little weird because i submit my code once, one of the validator failed. A little disturbing for a hardcoded solution. I submit again the same code and now everyting works.
auto means in D, auto type inference. The compiler looks at the right side of the assignment for the type.
int i = 0; is technical idential to auto i = 0;
I use for “easy” assignments the type, while for compex assignments I use auto. Some types could be really complex or some other types can’t even be named (Voldermort types). Here is auto really handy.
auto also saves you some key presses like here: auto myFunction = function string(string s) => s ~ s;
When to use and when not to use might be a personal decision.
I perfectly understand what it does, many languages have the same feature, I’m just trying to understand why should the generated code should use auto instead of the real type. So for now the autogenerated code is int i = readln.strip.to!int and not auto i = readln.strip.to!int. My question is: should I use auto instead of the type, and if so, why?