fork download
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. public class SentenceGenerator
  5. {
  6. public static List<List<string>> ExpandSentences(List<List<string>> partialSentences, List<string> uniqueWords)
  7. {
  8. var newSentences = new List<List<string>>();
  9. foreach(var sentence in partialSentences)
  10. {
  11. foreach(var word in uniqueWords)
  12. {
  13. if(sentence.Contains(word))
  14. {
  15. continue;
  16. }
  17.  
  18. // Make a copy of the old sentence
  19. var newSentence = new List<string>(sentence);
  20.  
  21. // Add a new word
  22. newSentence.Add(word);
  23.  
  24. newSentences.Add(newSentence);
  25. }
  26. }
  27.  
  28. return newSentences;
  29. }
  30.  
  31. public static void Main()
  32. {
  33. var uniqueWords = new List<string>() {
  34. "hello",
  35. "beautiful",
  36. "world",
  37. "full",
  38. "of",
  39. "people" };
  40.  
  41. var sentences = new List<List<string>>() {
  42. // Start with an empty sentence
  43. new List<string>()
  44. };
  45.  
  46. for(int i = 1; i <= 3; i++)
  47. {
  48. sentences = ExpandSentences(sentences, uniqueWords);
  49. }
  50.  
  51. System.Console.WriteLine("Generated " + sentences.Count + " sentences.");
  52. foreach(var sentence in sentences)
  53. {
  54. System.Console.WriteLine(string.Join(" ", sentence));
  55. }
  56. }
  57. }
  58.  
Success #stdin #stdout 0.03s 22664KB
stdin
Standard input is empty
stdout
Generated 120 sentences.
hello beautiful world
hello beautiful full
hello beautiful of
hello beautiful people
hello world beautiful
hello world full
hello world of
hello world people
hello full beautiful
hello full world
hello full of
hello full people
hello of beautiful
hello of world
hello of full
hello of people
hello people beautiful
hello people world
hello people full
hello people of
beautiful hello world
beautiful hello full
beautiful hello of
beautiful hello people
beautiful world hello
beautiful world full
beautiful world of
beautiful world people
beautiful full hello
beautiful full world
beautiful full of
beautiful full people
beautiful of hello
beautiful of world
beautiful of full
beautiful of people
beautiful people hello
beautiful people world
beautiful people full
beautiful people of
world hello beautiful
world hello full
world hello of
world hello people
world beautiful hello
world beautiful full
world beautiful of
world beautiful people
world full hello
world full beautiful
world full of
world full people
world of hello
world of beautiful
world of full
world of people
world people hello
world people beautiful
world people full
world people of
full hello beautiful
full hello world
full hello of
full hello people
full beautiful hello
full beautiful world
full beautiful of
full beautiful people
full world hello
full world beautiful
full world of
full world people
full of hello
full of beautiful
full of world
full of people
full people hello
full people beautiful
full people world
full people of
of hello beautiful
of hello world
of hello full
of hello people
of beautiful hello
of beautiful world
of beautiful full
of beautiful people
of world hello
of world beautiful
of world full
of world people
of full hello
of full beautiful
of full world
of full people
of people hello
of people beautiful
of people world
of people full
people hello beautiful
people hello world
people hello full
people hello of
people beautiful hello
people beautiful world
people beautiful full
people beautiful of
people world hello
people world beautiful
people world full
people world of
people full hello
people full beautiful
people full world
people full of
people of hello
people of beautiful
people of world
people of full