Skip to content

Instantly share code, notes, and snippets.

Created September 9, 2012 22:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/3687693 to your computer and use it in GitHub Desktop.
Save anonymous/3687693 to your computer and use it in GitHub Desktop.
import std.algorithm;
import std.conv;
import std.stdio;
import std.c.stdlib;
auto begin = 1985;
auto end= 2015;
bool noRepeatDigits(ref string str)
{
foreach(i, _; str)
{
if(count(str, str[i]) != 1) return false;
}
return true;
}
void fail()
{
writeln("You're doing it wrong.");
writeln("\t./digits begin end");
exit(1);
}
void main(string[] args)
{
if(args.length == 3)
{
begin = to!int(args[1]);
end = to!int(args[2]);
if(end <= begin)
{
fail();
}
}
else if (args.length != 1)
{
fail();
}
foreach(i; begin .. (end + 1))
{
auto str = to!string(i);
if(noRepeatDigits(str))
{
writeln(str);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment