Thread overview
Are there any exercises/challenges for D?
Aug 24, 2014
maik klein
Aug 24, 2014
bearophile
Aug 24, 2014
Weaseldog
Aug 24, 2014
maik klein
Aug 24, 2014
Ola Fosheim Gr
Aug 25, 2014
bearophile
Aug 26, 2014
Meta
Aug 26, 2014
Meta
Aug 26, 2014
bearophile
August 24, 2014
Are there any exercises/challenges for D?

Something like this? http://www.haskell.org/haskellwiki/99_questions/1_to_10
August 24, 2014
maik klein:

> Are there any exercises/challenges for D?
>
> Something like this? http://www.haskell.org/haskellwiki/99_questions/1_to_10

This is an interesting question. There are many exercises/challenges that can be done in D, but I don't know any specific for D. As D challenge I suggest to write a useful Phobos pull request, there are many many missing useful functions.

Bye,
bearophile
August 24, 2014
On Sunday, 24 August 2014 at 20:32:02 UTC, maik klein wrote:
> Are there any exercises/challenges for D?
>
> Something like this? http://www.haskell.org/haskellwiki/99_questions/1_to_10

Well, you could port 99 lisp problems to D - D can be written in a fairly functional style ;)
August 24, 2014
On Sunday, 24 August 2014 at 21:51:39 UTC, Weaseldog wrote:
> On Sunday, 24 August 2014 at 20:32:02 UTC, maik klein wrote:
>> Are there any exercises/challenges for D?
>>
>> Something like this? http://www.haskell.org/haskellwiki/99_questions/1_to_10
>
> Well, you could port 99 lisp problems to D - D can be written in a fairly functional style ;)

I am just trying to learn D by writing code. Of course I could just do them in D but I would like to compare my version with idiomatic D.

It's actually quite strange that no one has done something like this in D, it's usually the first thing people do.

August 24, 2014
On Sunday, 24 August 2014 at 23:20:21 UTC, maik klein wrote:
> It's actually quite strange that no one has done something like this in D, it's usually the first thing people do.

Bearophile has created many such examples at Rosettacode.
August 24, 2014
On Sunday, 24 August 2014 at 23:36:55 UTC, Ola Fosheim Grøstad wrote:
> On Sunday, 24 August 2014 at 23:20:21 UTC, maik klein wrote:
>> It's actually quite strange that no one has done something like this in D, it's usually the first thing people do.
>
> Bearophile has created many such examples at Rosettacode.

http://rosettacode.org/wiki/Category:D

Pretty long list of tasks?
August 25, 2014
Ola Fosheim Grøstad:

> Bearophile has created many such examples at Rosettacode.

I am updating and improving them, but I have created only a percentage of them (60-70%? I don't know).

Bye,
bearophile
August 26, 2014
On Sunday, 24 August 2014 at 23:20:21 UTC, maik klein wrote:
> On Sunday, 24 August 2014 at 21:51:39 UTC, Weaseldog wrote:
>> On Sunday, 24 August 2014 at 20:32:02 UTC, maik klein wrote:
>>> Are there any exercises/challenges for D?
>>>
>>> Something like this? http://www.haskell.org/haskellwiki/99_questions/1_to_10
>>
>> Well, you could port 99 lisp problems to D - D can be written in a fairly functional style ;)
>
> I am just trying to learn D by writing code. Of course I could just do them in D but I would like to compare my version with idiomatic D.
>
> It's actually quite strange that no one has done something like this in D, it's usually the first thing people do.

Have you heard of Project Euler? https://projecteuler.net/

The problems are mostly mathematical, and once you answer you can compare your solution to the other solutions people have written in other languages. The early questions also have some very unique and beautiful range-based D solutions.

import std.algorithm;
import std.range;
import std.stdio;

alias fold = std.functional.binaryReverseArgs!(reduce!((n1, n2) => n1 + n2));
enum limit = 4_000_000;

void main()
{
    recurrence!q{a[n-1] + a[n-2]}(1, 1)
        .take(1000)
        .filter!(n => n >= 0 && n < limit && n % 2 == 0)
        .sum.writeln;
}
August 26, 2014
On Tuesday, 26 August 2014 at 01:57:06 UTC, Meta wrote:
> Have you heard of Project Euler? https://projecteuler.net/
>
> The problems are mostly mathematical, and once you answer you can compare your solution to the other solutions people have written in other languages. The early questions also have some very unique and beautiful range-based D solutions.
>
> import std.algorithm;
> import std.range;
> import std.stdio;
>
> alias fold = std.functional.binaryReverseArgs!(reduce!((n1, n2) => n1 + n2));
> enum limit = 4_000_000;
>
> void main()
> {
>     recurrence!q{a[n-1] + a[n-2]}(1, 1)
>         .take(1000)
>         .filter!(n => n >= 0 && n < limit && n % 2 == 0)
>         .sum.writeln;
> }

Whoops, wrong code. Also, this is the answer to PE problem 2.

import std.algorithm;
import std.range;
import std.stdio;

enum limit = 4_000_000;

void main()
{
    recurrence!q{a[n-1] + a[n-2]}(1, 1)
        .take(1000)
        .filter!(n => n >= 0 && n < limit && n % 2 == 0)
        .sum
        .writeln;
}
August 26, 2014
maik klein:

> Are there any exercises/challenges for D?

Some exercises here:
http://rosettacode.org/wiki/Reports:Tasks_not_implemented_in_D

Please announce them here when you solve some of them :-)

Bye,
bearophile