Celsius - Fahrenheit anagram Task


  Make a complete program or a function which calculates sum of all temperatures which, when written in Celsius and Fahrenheit scale, are anagram of each other.


Description

For example, 275 degree Celsius = 527 degree Fahrenheit, and 527 is anagram of 275. Non-integer temperatures (either in degree Celsius or degree Fahrenheit) and temperatures colder than 0 degree Celsius (like -40C = -40F) will not be considered.

Input

Input is a temperature in format ([1-9][0-9]*)(C|F) (example: 42F = 42 degree Fahrenheit, 125C = 125 degree Celsius, ...).

The program should be able to handle temperature less than 1000000C.

Output

Output is sum of all temperatures less than the temperature given by input, which, when written in Celsius and Fahrenheit scale, are anagram (without leading zeroes) of each other. Output will be two integers separated by a space. The first one will be the sum in degree Celsius, and the second one will be the sum in degree Fahrenheit.

If there's no such temperature, return or output 0 0.

Example


Input : 42C

There's no such temperature
Output : 0 0

Input : 300C

There's one temperature : 275C = 527F
Output : 275 527

Input : 10000F

There're three temperatures : 275C = 527F, 2345C = 4253F, and 4685C = 8465F
Output : 7305 13245
C# - 166

Due to the small number of matches, I thought it might be easier to hardcode the outputs:

void F(string i){int n=int.Parse(i.Substring(0,i.Length-1));
n=i.Last()=='C'?n:5*(n-32)/9;
Console.Write(n&gt;4685?"7305 13245":n&gt;2345?"2620 4780":n&gt;275?"275 527":"0 0");}


Edit: 352

To do it right requires a bit more work. Here's a first attempt at using a whole pile of linq:

using System;
using System.Linq;
class P{static void Main(string[] i)
{
   int n=int.Parse(i[0].Substring(0,i[0].Length-1));
   n=i[0].Last()=='C'?n:5*(n-32)/9;
   var q=Enumerable.Range(1,n).Where(x=&gt;new string(((decimal)x*9/5+32).ToString().OrderBy(y=&gt;y).ToArray())==new string(x.ToString().OrderBy(y=&gt;y).ToArray()));
   Console.Write(q.Sum()+" "+q.Sum(x=&gt;x*9/5+32));
}}


Maybe the 'use a pile of linq instead of a loop' approach hurt me too much. I'll try and shorten it.

Edit 2: 356

Since I'm already way behind in raw count, here's a one-liner from hell:

Console.Write(Enumerable.Range(1,i.Last()=='C'?int.Parse(i.Substring(0,i.Length-1)):5*(int.Parse(i.Substring(0,i.Length-1))-32)/9).Where(x=&gt;new string(((decimal)x*9/5+32).ToString().OrderBy(y=&gt;y).ToArray())==new string(x.ToString().OrderBy(y=&gt;y).ToArray())).Aggregate("0 0",(a,t)=&gt;(int.Parse(a.Split(' ')[0])+t)+" "+(int.Parse(a.Split(' ')[1])+t*9/5+32)))