using System.Collections.Generic;
public class NumberWithSquareSumOfSquareDivisorsFinder
public int getSumOfAllDivisors(int x)
if (x % i == 0) sum += i * i;
public int[] Find(int start, int end)
int[] v = new int[end-start+1];
for(int i=start;i<=end;i++)
int squaredSum = getSumOfAllDivisors(i);
if (Math.Sqrt(squaredSum) == (int)(Math.Sqrt(squaredSum)))
v[numberOfNumbers++] = i;
Array.Resize(ref v, numberOfNumbers);
public class MaxcodeLatinTranslator
public string Translate(string sentence)
string[] splitedSentence = sentence.Split(' ');
for(int i=0;i<splitedSentence.Count();i++)
if("aeiou".IndexOf(splitedSentence[i][0])>=0)
string tempString = "ma" + splitedSentence[i].Substring(1) + splitedSentence[i][0];
finalString += ""+tempString;
string tempString = splitedSentence[i].Substring(1) + splitedSentence[i][0]+"ax";
finalString += ""+tempString;
public class MaxObservable
public static List<IObserver<T>> myList = new List<IObserver<T>>();
public void Emit<T>(T data)
for (int i = 0; i < obs<T>.myList.Count(); i++)
obs<T>.myList[i].Notify(data);
public void Subscribe<T>(IObserver<T> observer)
obs<T>.myList.Add(observer);
public void Unsubscribe<T>(IObserver<T> observer)
obs<T>.myList.Remove(observer);
public interface IObserver<T>
public static void Main()
private static void Run()
new NumberWithSquareSumOfSquareDivisorsFinderTests().Start();
new MaxcodeLatinTranslatorTests().Start();
new MaxObservableTests().Start();
public class NumberWithSquareSumOfSquareDivisorsFinderTests
Tests.Run("NumberWithSquareSumOfSquareDivisorsFinder should", (it) =>
it.Should(() => FindAllNumbersWithTheSumOfTheirDivisorsSquaredASquareNumber(),
"Find all numbers with the sum of their divisors squared a square number");
public void FindAllNumbersWithTheSumOfTheirDivisorsSquaredASquareNumber()
var finder = new NumberWithSquareSumOfSquareDivisorsFinder();
finder.Find(42, 1000).ShouldBe(new int[] { 42, 246, 287, 728 });
finder.Find(1000, 1880).ShouldBe(new int[] { 1434, 1673, 1880 });
public class MaxcodeLatinTranslatorTests
Tests.Run("MaxcodeLatinTranslator should", (it) =>
it.Should(() => TranslateAWordStartingWithAVowel(), "Translate a word starting with a vowel");
it.Should(() => TranslateAWordStartingWithAConsonant(), "Translate a word starting with a consonant");
it.Should(() => TranslateASentence(), "Translate a sentence");
public void TranslateAWordStartingWithAVowel()
var translator = new MaxcodeLatinTranslator();
translator.Translate("orange").ShouldBe("marangeo");
public void TranslateAWordStartingWithAConsonant()
var translator = new MaxcodeLatinTranslator();
translator.Translate("jumps").ShouldBe("umpsjax");
public void TranslateASentence()
var translator = new MaxcodeLatinTranslator();
translator.Translate("i hope you are enjoying this exercise")
.ShouldBe("mai opehax ouyax marea manjoyinge histax maxercisee");
public class MaxObservableTests
Tests.Run("MaxObservable should", (it) => {
it.Should(() => NotifySubscribedObserversOfTheEmittedDataType(), "Notify subscribed observers of the emitted data type");
it.Should(() => NotNotifyUnsubscribedObservers(), "Not notify unsubscribed observers");
public void NotifySubscribedObserversOfTheEmittedDataType()
var stringObserver = new FakeObserver<string>();
var intObserver = new FakeObserver<int>();
var anotherIntObserver = new FakeObserver<int>();
var maxObservable = new MaxObservable();
maxObservable.Subscribe(stringObserver);
maxObservable.Subscribe(intObserver);
maxObservable.Subscribe(anotherIntObserver);
intObserver.WasNotifiedWith(3).ShouldBe(true, "did not notify observers of emitted value type");
anotherIntObserver.WasNotifiedWith(3).ShouldBe(true, "did not notify observers of emitted value type");
intObserver.WasNotifiedWith(20).ShouldBe(true, "did not notify observers of emitted value type");
anotherIntObserver.WasNotifiedWith(20).ShouldBe(true, "did not notify observers of emitted value type");
stringObserver.WasNotified().ShouldBe(false, "notified observers of different type than the emitted value type");
public void NotNotifyUnsubscribedObservers()
var stringObserver = new FakeObserver<string>();
var anotherStringObserver = new FakeObserver<string>();
var maxObservable = new MaxObservable();
maxObservable.Subscribe(stringObserver);
maxObservable.Subscribe(anotherStringObserver);
maxObservable.Unsubscribe(anotherStringObserver);
maxObservable.Emit("a string value");
stringObserver.WasNotifiedWith("a string value").ShouldBe(true, "did not notify subscribed observer of emitted data type");
anotherStringObserver.WasNotifiedWith("a string value").ShouldBe(false, "notified unsubscribed observer");
public class FakeObserver<T> : IObserver<T>
private HashSet<T> notifications = new HashSet<T>();
public void Notify(T data)
public bool WasNotifiedWith(T data)
return notifications.Contains(data);
public bool WasNotified()
return notifications.Any();
public static void Run(string testGroup, Action<Tests> tests)
public static void StartTests(string testGroup)
Console.WriteLine("====================================================");
Console.WriteLine(testGroup);
Console.WriteLine("====================================================");
public void Should(Action test, string testName)
Console.WriteLine(testName);
Console.WriteLine(" Passed");
Console.WriteLine(" Failed");
Console.WriteLine(" " + e.Message);
public static void EndTests()