Skip to content

Instantly share code, notes, and snippets.

@tbillington
Last active August 29, 2015 14:05
Show Gist options
  • Save tbillington/ef5e884da6f479933c1f to your computer and use it in GitHub Desktop.
Save tbillington/ef5e884da6f479933c1f to your computer and use it in GitHub Desktop.
calc
using System;
using System.Text.RegularExpressions;
using System.Linq;
namespace fun {
class MainClass {
public static void Main (string[] args) {
var input = Console.ReadLine ();
Console.WriteLine (input.Contains ("+") ? Enumerable.Aggregate (from n in (new Regex (@"\d+|\.\d+|\d+\.").Matches (input).OfType<Match> ())select (n.ToString ()), (acc, x) => (float.Parse (acc) + float.Parse (x)).ToString()) : "");
}
}
}
// Tests
> 2 + 3
5
> .1 + 1 + 1.
2.1
> 111.111 + 222.222 + 333.333
666.666
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment