Last active
August 29, 2015 14:05
-
-
Save tbillington/ef5e884da6f479933c1f to your computer and use it in GitHub Desktop.
calc
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.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