Much has changed since some of these old posts were written:
viewtopic.php?t=12859
viewtopic.php?t=15536
1. C# is now a very different language than C++ and offers some very creative ways to solve problems with style.
2. .Net Core is open source and can run on Linux.
UVA is awesome. I want to help make it even better. With the addition of C#, I expect you will see a big boost in usage and notoriety. In my case, I would love to be able to issue challenges to my software developers to solve problem X within a 2 hour time frame and offer prizes to the first to solve, shortest code, fastest code, etc. but it isn't practical with my staff to solve with anything other than C#. As a developer, I want to challenge myself to solve these in the most eloquent way possible using the tools I use for my job everyday.
Here's my favorite C# 3n+1, which cannot be trivially ported to C++.
Code: Select all
using System;
using System.Collections.Generic;
using System.Linq;
class Program {
static IEnumerable<uint> Cycles(uint n) { while (n > 1) yield return n = n % 2 == 1 ? 3 * n + 1 : n / 2; }
static void Main() {
for (;;) {
var inputs = Console.ReadLine().Split(' ').Select(input => int.Parse(input)).ToArray();
if (inputs.All(input => input == 0)) break;
Console.WriteLine(string.Format("{0} {1} {2}", inputs[0], inputs[1], Enumerable.Range(inputs.Min(), inputs.Max() - inputs.Min() + 1).Select(n => Cycles((uint)n).Count() + 1).Max()));
}
}
}