Jump to page: 1 24  
Page
Thread overview
Coding Challenges - Dlang or Generic
Jan 10, 2023
Paul
Jan 10, 2023
H. S. Teoh
Jan 10, 2023
matheus
Jan 10, 2023
H. S. Teoh
Jan 10, 2023
matheus
Jan 10, 2023
drug007
Jan 10, 2023
drug007
Jan 10, 2023
matheus
Jan 10, 2023
Salih Dincer
Jan 10, 2023
matheus
Jan 10, 2023
Salih Dincer
Jan 10, 2023
bachmeier
Jan 10, 2023
Paul
Jan 10, 2023
matheus
Jan 12, 2023
Salih Dincer
Jan 13, 2023
matheus
Jan 13, 2023
Salih Dincer
Jan 17, 2023
matheus
Jan 17, 2023
Siarhei Siamashka
Jan 17, 2023
H. S. Teoh
Jan 17, 2023
matheus
Jan 18, 2023
Siarhei Siamashka
Jan 18, 2023
matheus
Jan 19, 2023
Siarhei Siamashka
Jan 18, 2023
Salih Dincer
Jan 18, 2023
matheus
Jan 19, 2023
Salih Dincer
Jan 10, 2023
Ali Çehreli
Jan 10, 2023
Paul
Jan 12, 2023
Christian Köstlin
Jan 12, 2023
Paul
Jan 10, 2023
Siarhei Siamashka
Jan 10, 2023
Paul
Jan 10, 2023
thebluepandabear
Jan 10, 2023
monkyyy
Jan 10, 2023
Christian Köstlin
Jan 10, 2023
monkyyy
Jan 12, 2023
Christian Köstlin
Jan 14, 2023
TheZipCreator
January 10, 2023

Greetings Dlang-ers
I was wondering if anyone knew of any coding challenges available where the input and output are specified and its left to the programmer to find a solution? Free would be nice but even paid services would be worth considering. I'm taking a D class right now and it has little challenges in the lessons where much of the work is done for you, but I'm thinking of a site/service that is dedicated to these types of challenges (without doing any work for you).

I wonder if a site dedicated to Dlang challenges would 'fly'? It would be quite interesting and instructive to see how different coders solved a particular coding problem. Statistics could be generated for each solution (e.g. compile time, execution time, source code size, executable size, @safe, @nogc, readability of source code, helpfulness of comments, etc.). With D's multi-paradigm power it could be fascinating. I know. Someone's going to say why don't YOU do it:)

regards,

January 09, 2023
On Tue, Jan 10, 2023 at 12:17:18AM +0000, Paul via Digitalmars-d-learn wrote:
> Greetings Dlang-ers
> I was wondering if anyone knew of any coding challenges available
> where the input and output are specified and its left to the
> programmer to find a solution?

Here's a challenge.  Given an input year, for example, "2023", write a program that outputs (for the corresponding year):

--------------------------------snip---------------------------------
                              2023
       January              February                March
 Su Mo Tu We Th Fr Sa  Su Mo Tu We Th Fr Sa  Su Mo Tu We Th Fr Sa
  1  2  3  4  5  6  7            1  2  3  4            1  2  3  4
  8  9 10 11 12 13 14   5  6  7  8  9 10 11   5  6  7  8  9 10 11
 15 16 17 18 19 20 21  12 13 14 15 16 17 18  12 13 14 15 16 17 18
 22 23 24 25 26 27 28  19 20 21 22 23 24 25  19 20 21 22 23 24 25
 29 30 31              26 27 28              26 27 28 29 30 31

        April                  May                  June
 Su Mo Tu We Th Fr Sa  Su Mo Tu We Th Fr Sa  Su Mo Tu We Th Fr Sa
                    1      1  2  3  4  5  6               1  2  3
  2  3  4  5  6  7  8   7  8  9 10 11 12 13   4  5  6  7  8  9 10
  9 10 11 12 13 14 15  14 15 16 17 18 19 20  11 12 13 14 15 16 17
 16 17 18 19 20 21 22  21 22 23 24 25 26 27  18 19 20 21 22 23 24
 23 24 25 26 27 28 29  28 29 30 31           25 26 27 28 29 30
 30

        July                 August               September
 Su Mo Tu We Th Fr Sa  Su Mo Tu We Th Fr Sa  Su Mo Tu We Th Fr Sa
                    1         1  2  3  4  5                  1  2
  2  3  4  5  6  7  8   6  7  8  9 10 11 12   3  4  5  6  7  8  9
  9 10 11 12 13 14 15  13 14 15 16 17 18 19  10 11 12 13 14 15 16
 16 17 18 19 20 21 22  20 21 22 23 24 25 26  17 18 19 20 21 22 23
 23 24 25 26 27 28 29  27 28 29 30 31        24 25 26 27 28 29 30
 30 31

       October              November              December
 Su Mo Tu We Th Fr Sa  Su Mo Tu We Th Fr Sa  Su Mo Tu We Th Fr Sa
  1  2  3  4  5  6  7            1  2  3  4                  1  2
  8  9 10 11 12 13 14   5  6  7  8  9 10 11   3  4  5  6  7  8  9
 15 16 17 18 19 20 21  12 13 14 15 16 17 18  10 11 12 13 14 15 16
 22 23 24 25 26 27 28  19 20 21 22 23 24 25  17 18 19 20 21 22 23
 29 30 31              26 27 28 29 30        24 25 26 27 28 29 30
                                             31
--------------------------------snip---------------------------------

Code will be graded on readability, unittest coverage, and reusability (how many functions have wide applicability outside of this challenge).

;-)


T

-- 
A mathematician learns more and more about less and less, until he knows everything about nothing; whereas a philospher learns less and less about more and more, until he knows nothing about everything.
January 09, 2023
On 1/9/23 16:17, Paul wrote:

> coding challenges

Perhaps the following two?

  https://rosettacode.org/

  https://adventofcode.com/

Ali

January 10, 2023
On Tuesday, 10 January 2023 at 01:22:33 UTC, H. S. Teoh wrote:
> ...
>
> Here's a challenge.  Given an input year, for example, "2023", write a program that outputs (for the corresponding year):
> ...

The layout isn't like yours, I wrote this using a D Online compiler and I'm very sleepy right now:

import std.stdio, std.string, std.conv, std.datetime;

bool validDate(int y,int m,int d){
   try{
       Date(y,m,d);
       return true;
   }catch(Exception e){}
   return false;
}

void main(){
    int[string] dow;
    int i, y = 2023, m = 1, d = 1;

    for(i=1;i<8;++i){
        dow[to!string(Date(1899,1,i).dayOfWeek)]=i;
    }

    for(m=1;m<13;++m){
        write("\n\n\t\t",capitalize(to!string(Date(y,m,1).month)),"\n");

        for(i=1;i<8;++i){
        	write(to!string(Date(1899,1,i).dayOfWeek)[0..2], " ");
        }

        writeln();
        int c = dow[to!string(Date(y,m,1).dayOfWeek)];

        for(i=1;i<c;++i){ write("   "); }

    	for(d=0;d<32;++d){
    	    if(c%8==0){c=1;writeln();}
    	    ++c;
            if(validDate(y,m,d+1)){
                writef("%2s ",d+1);
            }
        }
    }
}

Prints:


	Jan
su mo tu we th fr sa
 1  2  3  4  5  6  7
 8  9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31

	Feb
su mo tu we th fr sa
          1  2  3  4
 5  6  7  8  9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28

	Mar
su mo tu we th fr sa
          1  2  3  4
 5  6  7  8  9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31

	Apr
su mo tu we th fr sa
                   1
 2  3  4  5  6  7  8
 9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30

	May
su mo tu we th fr sa
    1  2  3  4  5  6
 7  8  9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31

	Jun
su mo tu we th fr sa
             1  2  3
 4  5  6  7  8  9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30


	Jul
su mo tu we th fr sa
                   1
 2  3  4  5  6  7  8
 9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31

	Aug
su mo tu we th fr sa
       1  2  3  4  5
 6  7  8  9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31

	Sep
su mo tu we th fr sa
                1  2
 3  4  5  6  7  8  9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30


	Oct
su mo tu we th fr sa
 1  2  3  4  5  6  7
 8  9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31

	Nov
su mo tu we th fr sa
          1  2  3  4
 5  6  7  8  9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30

	Dec
su mo tu we th fr sa
                1  2
 3  4  5  6  7  8  9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31

Matheus.
January 09, 2023
On Tue, Jan 10, 2023 at 03:18:54AM +0000, matheus via Digitalmars-d-learn wrote:
> On Tuesday, 10 January 2023 at 01:22:33 UTC, H. S. Teoh wrote:
> > ...
> > 
> > Here's a challenge.  Given an input year, for example, "2023", write a program that outputs (for the corresponding year): ...
> 
> The layout isn't like yours, I wrote this using a D Online compiler and I'm very sleepy right now:
[...]
> Prints:
> 
> 
> 	Jan
> su mo tu we th fr sa
>  1  2  3  4  5  6  7
>  8  9 10 11 12 13 14
> 15 16 17 18 19 20 21
> 22 23 24 25 26 27 28
> 29 30 31
> 
> 	Feb
> su mo tu we th fr sa
>           1  2  3  4
>  5  6  7  8  9 10 11
> 12 13 14 15 16 17 18
> 19 20 21 22 23 24 25
> 26 27 28
[...]

Printing it in this format is trivial, and not very interesting.  The interest in the challenge is to lay it out like I posted, side-by-side, and to do so in a way that the code is clean, maintainable, and consists of reusable components.  That's where the challenge lies.


T

-- 
If you think you are too small to make a difference, try sleeping in a closed room with a mosquito. -- Jan van Steenbergen
January 10, 2023

On Tuesday, 10 January 2023 at 00:17:18 UTC, Paul wrote:

>

I was wondering if anyone knew of any coding challenges available where the input and output are specified and its left to the programmer to find a solution? Free would be nice but even paid services would be worth considering. I'm taking a D class right now and it has little challenges in the lessons where much of the work is done for you, but I'm thinking of a site/service that is dedicated to these types of challenges (without doing any work for you).

What kind of D class is that? Are you learning D language in a school or university? Or is it some kind of online language course?

I can recommend the https://atcoder.jp site and their beginner contests. At least the first two tasks of each beginner contest are relatively easily solvable by anyone without any kind of special knowledge or training. The next beginner contest is scheduled in 5 days. The previous beginner contest was here and the accepted solutions in D language can be found here. You can try to solve any tasks from the previous contests yourself as a practice without any time limit and without any stress of being ranked.

Additionally, there are "heuristic" contests and they are very fun in their own way. You can try https://atcoder.jp/contests/ahc015/tasks/ahc015_a as an example, which essentially boils down to implementing an AI for a simple game. Implementing some sort of a trivial solution is easy. For example, always tilting the box in the same direction is a valid solution. But it won't score a lot of points. Doing something smarter will result in a better score. And again, the already existing solutions in D language are also available here.

January 10, 2023
>

I know. Someone's going to say why don't YOU do it:)

regards,

The official book on D by Ali has many coding challenges.

There isn't any need to create a website for D coding challenges or incorporate it into an existing website since D has under 1% of the market share.

January 10, 2023

On Tuesday, 10 January 2023 at 03:18:54 UTC, matheus wrote:

>

The layout isn't like yours, I wrote this using a D Online compiler and I'm very sleepy right now:

import std.stdio, std.string, std.conv, std.datetime;

bool validDate(int y,int m,int d){
   try{
       Date(y,m,d);
       return true;
   }catch(Exception e){}
   return false;
}

void main(){
    int[string] dow;
    int i, y = 2023, m = 1, d = 1;

    for(i=1;i<8;++i){
        dow[to!string(Date(1899,1,i).dayOfWeek)]=i;
    }

    for(m=1;m<13;++m){
        write("\n\n\t\t",capitalize(to!string(Date(y,m,1).month)),"\n");

        for(i=1;i<8;++i){
        	write(to!string(Date(1899,1,i).dayOfWeek)[0..2], " ");
        }

        writeln();
        int c = dow[to!string(Date(y,m,1).dayOfWeek)];

        for(i=1;i<c;++i){ write("   "); }

    	for(d=0;d<32;++d){
    	    if(c%8==0){c=1;writeln();}
    	    ++c;
            if(validDate(y,m,d+1)){
                writef("%2s ",d+1);
            }
        }
    }
}

You don't need validDate. Because there is daysInMonth:

      writeln();
      const date = Date(y, m, 1);
      int c = dow[to!string(date.dayOfWeek)];

      for(i = 1; i < c; ++i)
        write("   ");

      for(d = 0; d < 32; ++d)
      {
        if(++c % 9 == 0)
        {
          writeln();
          c = 2;
        }
        if(d < date.daysInMonth)
          writef("%2s ", d + 1);
      }

SDB@79

January 10, 2023
On Tuesday, 10 January 2023 at 05:21:15 UTC, H. S. Teoh wrote:
>
> Printing it in this format is trivial, and not very interesting.  The interest in the challenge is to lay it out like I posted, side-by-side,...

Like I said I did it over D online compiler which unfortunately I couldn't validate the output because it "wraps" the text, and the font wasn't monospace.

But It just a case of changing the loop in a way to print 3 groups of months.

> ... and to do so in a way that the code is clean, maintainable, and consists of reusable components. ...

Talking about modularity and reusable components, I really think it depends, because if that's was really the case, then I would think of using the OS functions to move the cursor around (If console/terminal) to print a given month in some location or side by side until reach some horizontal limit (Terminal), then it could be 1 column only (Like I did), 2, 3 and maybe 4 columns if the terminal/resolution permit, and for that I would use ARSD. :]

But I think this would be too much for this kind of thing writing on online compiler.

> ... That's where the challenge lies.

To be honest when I saw your proposal, I really thought that the real challenge would be to write my own algo to handle the date, and I was pretty sure after posting above, you would say that, but not about the layout or printing in groups. =]

Matheus.
January 10, 2023
On Tuesday, 10 January 2023 at 07:38:31 UTC, Salih Dincer wrote:
> On Tuesday, 10 January 2023 at 03:18:54 UTC, matheus wrote:
> ...`
> You don't need validDate.  Because there is daysInMonth:
> ...

That's really better. thanks for the info.

Matheus.
« First   ‹ Prev
1 2 3 4