Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import std.stdio;
- import std.string;
- import std.conv;
- void main()
- {
- hello();
- writeln("---");
- writeln(firstHundred());
- writeln("---");
- writeln(isAnagram("Male ness", "Sales Men"));
- writeln(removeLetterFromWord("hello", 'l'));
- writeln(sumArray(firstHundred()));
- }
- void hello()
- {
- writeln("Hello World!");
- }
- int[] firstHundred()
- {
- int[] results;
- int i = 0;
- while (results.length < 100)
- {
- if (i % 3 == 0 && i % 5 == 0)
- {
- results ~= i;
- }
- i++;
- }
- return results;
- }
- bool isAnagram(in string a, in string b)
- {
- auto aCopy = a.toLower.removechars(" ").dup;
- auto bCopy = b.toLower.removechars(" ").dup;
- aCopy.sort;
- bCopy.sort;
- return aCopy.length == bCopy.length && aCopy == bCopy;
- }
- string removeLetterFromWord(in string word, in char letter)
- {
- return word.removechars(letter.to!string ~ letter.to!string.toUpper);
- }
- int sumArray(in int[] arr)
- {
- int sum = 0;
- foreach(int i; arr)
- {
- sum += i;
- }
- return sum;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement