Advertisement
Guest User

Untitled

a guest
Jun 10th, 2014
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
D 0.98 KB | None | 0 0
  1. import std.stdio;
  2. import std.string;
  3. import std.conv;
  4.  
  5. void main()
  6. {
  7.     hello();
  8.     writeln("---");
  9.     writeln(firstHundred());
  10.     writeln("---");
  11.     writeln(isAnagram("Male ness", "Sales Men"));
  12.     writeln(removeLetterFromWord("hello", 'l'));
  13.     writeln(sumArray(firstHundred()));
  14. }
  15.  
  16. void hello()
  17. {
  18.     writeln("Hello World!");
  19. }
  20.  
  21. int[] firstHundred()
  22. {
  23.     int[] results;
  24.     int i = 0;
  25.  
  26.     while (results.length < 100)
  27.     {
  28.         if (i % 3 == 0 && i % 5 == 0)
  29.         {
  30.             results ~= i;
  31.         }
  32.  
  33.         i++;
  34.     }
  35.  
  36.     return results;
  37. }
  38.  
  39. bool isAnagram(in string a, in string b)
  40. {
  41.     auto aCopy = a.toLower.removechars(" ").dup;
  42.     auto bCopy = b.toLower.removechars(" ").dup;
  43.  
  44.     aCopy.sort;
  45.     bCopy.sort;
  46.  
  47.     return aCopy.length == bCopy.length && aCopy == bCopy;
  48. }
  49.  
  50. string removeLetterFromWord(in string word, in char letter)
  51. {
  52.     return word.removechars(letter.to!string ~ letter.to!string.toUpper);
  53. }
  54.  
  55. int sumArray(in int[] arr)
  56. {
  57.     int sum = 0;
  58.     foreach(int i; arr)
  59.     {
  60.         sum += i;
  61.     }
  62.     return sum;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement