Skip to content

Instantly share code, notes, and snippets.

@stormwild
Created July 6, 2015 07:08
Show Gist options
  • Save stormwild/8d7a4f41c7dcfc099a70 to your computer and use it in GitHub Desktop.
Save stormwild/8d7a4f41c7dcfc099a70 to your computer and use it in GitHub Desktop.
using System;
using System.Globalization;
using System.Linq;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
var input = Console.ReadLine();
try
{
if (IsValid(input))
{
var result = GetLowestMultipleThatIsZeroOne(input);
Console.WriteLine(result);
}
else
{
Console.WriteLine("Invalid input: Enter a number between 0 and 100000 exclusive.");
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
// Keep the console open in debug mode.
Console.WriteLine("Press any key to exit.");
Console.ReadKey();
}
/// <summary>
/// Returns the lowest multiple of a number that is only zero's or one's
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
private static object GetLowestMultipleThatIsZeroOne(string input)
{
var n = Convert.ToInt32(input);
var zeroOne = n;
while (!zeroOne.ToString(CultureInfo.InvariantCulture).All(c => c == '0' || c == '1'))
{
zeroOne += n;
}
return zeroOne;
}
private static bool IsValid(string input)
{
var n = Convert.ToInt32(input);
return 0 < n && n < 100000;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment