Last active
August 29, 2015 14:03
-
-
Save bearcherian/66ea0b163cd95c4484b8 to your computer and use it in GitHub Desktop.
Solution for /r/DailyProgrammer for 6/27/2014 (http://www.reddit.com/r/dailyprogrammer/comments/299hvt/6272014_challenge_168_easy_string_index/)
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.stdio; | |
import std.regex; | |
import std.array; | |
import std.conv; | |
void main(string[] args) | |
{ | |
if (args.length < 1) | |
{ | |
writeln("No string specified"); | |
} | |
writeln("Enter the string: "); | |
string input = readln(); | |
writeln("Enter indexes to return (space delmited)"); | |
string indexes = readln(); | |
string[] index = split(indexes); | |
string[] words = split(input,regex("[^a-zA-Z0-9]+")); | |
foreach(int i, string idx; index) | |
{ | |
auto x = to!int(idx); | |
if ( x > 0 && x < words.length) | |
{ | |
write(words[x]," "); | |
} | |
} | |
writeln(""); | |
return; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment