Advertisement
Guest User

D Lang

a guest
Aug 8th, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
D 0.99 KB | None | 0 0
  1. import std.stdio,std.string,std.conv;
  2.  
  3. void main()
  4. {
  5.     string[] possibleWords = ["YIPPING","VIEWING","BEELINE","COCAINS","LUNGING","SESTINE","FAILING","DETAINS","BUSTING","WASTING","GLOBINS","PUPPING"];
  6.  
  7.     write("First Guess > ");
  8.     string firstGuess = strip(readln);
  9.  
  10.     write("First Likeness > ");
  11.     int firstLikeness = to!int(strip(readln));
  12.  
  13.     foreach (string word; possibleWords)
  14.     {
  15.         writeln(word , " : " , matches(firstGuess, word));
  16.     }
  17.  
  18.     readln;
  19. }
  20.  
  21.  
  22. int matches(string str1, string str2)
  23. {
  24.     int count = 0;
  25.  
  26.     if (str1.length > str2.length)
  27.     {
  28.         char[] stringArray = to!(char[])(str1);
  29.        
  30.         foreach (char character; stringArray)
  31.         {
  32.             if(containsChar(str2, character))
  33.             {
  34.                 count += 1;
  35.             }
  36.         }
  37.  
  38.     }else{
  39.         char[] stringArray = to!(char[])(str2);
  40.  
  41.         foreach (char character; stringArray)
  42.         {
  43.             if(containsChar(str1, character))
  44.             {
  45.                 count += 1;
  46.             }
  47.         }
  48.     }
  49.     return count;
  50. }
  51.  
  52.  
  53.  
  54. bool containsChar(string x, char y)
  55. {
  56.     return (x.indexOf(y) != -1);
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement