Number Mysteries – Considering Bases Exercise

Here’s a sample C# program for working out the Considering Bases exercise:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NumberMysteries
{
	/// <summary>
	///  Wrapper for the Number Mysteries course.
	/// </summary>
	class Program
	{
		/// <summary>
		/// Standard entry point.
		/// </summary>
		/// <param name="args">Ignored.</param>
		static void Main(string[] args)
		{
			int knutsInSickle = 29;
			int sicklesInGalleon = 17;
			int knutsInGalleon = knutsInSickle * sicklesInGalleon;

			int answerA = (1 * knutsInGalleon) + (14 * knutsInSickle) + 3;

			int numGalleons = 1509 / (knutsInGalleon);
			int knutsLeftOver1 = 1509 % (knutsInGalleon);
			int numSickles = knutsLeftOver1 / knutsInSickle;
			int knutsLeftOver2 = knutsLeftOver1 % knutsInSickle;

			Console.WriteLine("For answer A:\nNumber of knuts:{0:d}", answerA);
			Console.WriteLine("For answer B:\nNumber of Galleons:{0:d}, Number of Sickles:{1:d}, Knuts left over:{2:d}", numGalleons, numSickles, knutsLeftOver2);
		}
	}
}

If you want to download the solution then click here.

Advertisements
This entry was posted in Number Mysteries and tagged . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s