What does C++ do better than D? - StackOverflow.com

bearophile bearophileHUGS at lycos.com
Fri Aug 5 03:26:52 PDT 2011


Caligo:

> FWIW, there is now http://codegolf.stackexchange.com/

A first solution to:
http://codegolf.stackexchange.com/questions/3258/multiples-of-67-in-a-constructed-array-of-arrays

174 chars:

import std.stdio,std.range,std.array,std.algorithm;
void main(){auto A=array(map!"a+0L"(iota(1,100,2))),t=1;while(A.length)t+=count!"!(a%67)"(A=A[0..$-1]+=A[1..$]);write(t);}

Because of a Phobos bug I have had to write: 
array(map!"a+0L"(iota(1,100,2)))

Instead of:
array(iota(1L,100,2))

A way to write unittests: create a 2D table (even on paper, if necessary), or nD tensor, of all the possible combinations of things usable by your code, even useless or absurd or outlandish ones, and then write 2 or 3 different tests for each one of those squares in your table, systematically.

Bye,
bearophile


More information about the Digitalmars-d mailing list