-
Jan 17th, 2017, 02:24 PM
#1
Contest 11: Sorting Characters - [.paul.]
code.cs
couldn't save in dotnetfiddle. submitting a text file...
code.cs
Source:
Code:
using System;
using System.Linq;
public class Program
{
public static void Main()
{
Console.WriteLine("Enter message...");
String input = Console.ReadLine();
Console.WriteLine(string.Concat(input.ToLower().Where(c => char.IsLetter(c)).OrderBy(c => c).ToArray()));
}
}
Fiddle: https://dotnetfiddle.net/wXlZen
Last edited by dday9; Jan 20th, 2017 at 11:18 AM.
Reason: Added source and fiddle.
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Jan 24th, 2017, 10:20 PM
#2
Re: Contest 11: Sorting Characters - [.paul.]
Moderator's notes:
The time taken for 100,000 iterations of "Wow! Whenever you go outside, it is actually a very pretty world." (as per the contest description) on my computer was:
IDE: 8432 ms
Comments on the submission: The algorithm that sorts the text is only 1 line. The algorithm uses LINQ to do the sorting which takes a performance hit in favor of a concise code.
There is only one minor change that could be made so that multiple variables are not declared and that is to treat the LINQ as a query:
Code:
Console.WriteLine(string.Concat((from c in input.ToLower() where char.IsLetter(c) orderby c select c).ToArray()));
Though the difference to the speed on my computer was minuscule.
-
Jan 26th, 2017, 03:19 AM
#3
Re: Contest 11: Sorting Characters - [.paul.]
It was certainly concise, and I'd much rather program in C# than any of the other languages used, but it illustrates that a one liner is possible with LINQ but not possible in most other languages. For that reason, it would be useful to have categories in the contests, but with just four entrants, that wouldn't be very practical...
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|