Created
July 6, 2015 07:08
-
-
Save stormwild/8d7a4f41c7dcfc099a70 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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