Created
September 9, 2012 22:28
-
-
Save anonymous/3687693 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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