D-lang problems (Dlang for searching)

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.

OT: made topic for fixing early bugs

1 Like

HORSE-RACING DUALS

Has same outcome for me.

Did Java ages ago, non-0%, reran to confirm.
Did D today, 0% consistently.

1 Like

we’re on it. Thanks!

Hello guys,

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.

1 Like

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.

not to ur problem but for all D-code:

u can run executable with ext.options:

program.exe “–DRT-gcopt=gc:precise parallel:4” “–DRT-scanDataSeg=precise” <input.data >output.data

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 requested more info on D-lang forum https://forum.dlang.org/post/nkndlpuilmyxcvovrlqe@forum.dlang.org

UPD:
I’ve got detailed answer in Dlang forum:

probably another issue:
It seemed to me that the points do not give for solving problems.
I got 20 points for multilingualism, but not for decisions.

UPD:
I checked, solved Easy “Bank Robery” and I’ve got points.
no issue

I just tried out this D language (already looking forward to the E support :slight_smile: ) 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);

Do I miss something or is it a stub problem?

@TBali, thanks a lot, I can confirm, you identified the root cause. Also occuring in e.g. " 1D SPREADSHEET"

I rewrite readf to:

auto N = readln.strip.to!int; // when number in whole line

or (NB: I used “strip” above, and “split” below)

auto Nums = readln.split.to!(int[]); // when list of numbers in 1 line

u can convert same way double-s too

for just string[] u can use (1D spreadsheet):

auto Strs = readln.split;

for converting between types u can use to!newType:

int N = str[5].to!int; // string[] str and converting element

for a="$123" u can use:

int cellRef = a[1…$].to!int; // [1…$] means from 1(included) to post last element (excluded)

etc

OT:

stderr.writefln( "%s %s", __VENDOR__, __VERSION__ );

shows “Digital Mars D 2088”, so u use last version of DMD.
good.
then u can simplify import.
autogenerated D-code starts with:

import std.stdio;

u can replace it to:

import std;

that import stdio, algorithm and many other modules and it shorter

also see about readf and reading nums in loops, u can simplify it too:

for future:
u can ask such things on forum/SO: they have more experience and no shame to ask something new, u are learning.
as people says:

one head is good, but two better

and this is about brain storm not about radiation

Hi,

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.

What do you think?

1 Like

well, as I said for D we can:

  • 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?

In my opinion the specific type should be used here and not auto. It makes the coding a lot more readable.