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;
}