Last active
August 29, 2015 14:02
-
-
Save lovasoa/20732844b13a035a01ac to your computer and use it in GitHub Desktop.
My first program in csharp. Explores the power of the english syntax.
This file contains hidden or 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
using System; | |
using System.Collections.Generic; | |
class HelloWorld | |
{ | |
public static string NestedWithList (string[] subject, string[] verb) { | |
// Hey, I can haz lists! | |
List<string> sentence = new List<string>(); | |
for (var i=subject.Length-1; i>=0; i--) { | |
sentence.Insert(0, subject[i]); | |
sentence.Insert(0, "the"); | |
sentence.Add(verb[i]); | |
} | |
return string.Join(" ", sentence); | |
} | |
public static string Nested (string[] subject, string[] verb) { | |
// Keywords: funny, lambda, recursive | |
Func<string[],string[],int,string> recursive = null; | |
recursive = (s,v,n) => n>=s.Length ? "": "the " + s[n] + " " + recursive(s,v,n+1) + v[n] + " "; | |
return recursive (subject, verb, 0); | |
} | |
public static string Flat (string[] subject, string[] verb) { | |
// Boring | |
string ret = ""; | |
for (var i=subject.Length-1; i>=0; i--) { | |
ret += "the " + subject[i] + " " + verb[i] + ((i==0)?".": " the " + subject[i-1] + ". "); | |
} | |
return ret; | |
} | |
public static void Main() | |
{ | |
string[] subject = new string[] {"mouse", "cat", "dog"}; | |
string[] verb = new string[] {"died", "killed", "chase"}; | |
Console.WriteLine(Flat(subject,verb)); | |
Console.WriteLine(Nested(subject,verb)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment