Skip to content

Instantly share code, notes, and snippets.

@KvanTTT
Created October 8, 2020 18:51
Show Gist options
  • Save KvanTTT/aa42c34078cde128b01e3e5d601a68a3 to your computer and use it in GitHub Desktop.
Save KvanTTT/aa42c34078cde128b01e3e5d601a68a3 to your computer and use it in GitHub Desktop.
using System;
class Program
{
static void Main()
{
int validTimeCount = 0;
for (int hour = 0; hour < 24; hour++)
{
int newRightMinuteDigit = CheckAndReflect(hour, true);
if (newRightMinuteDigit == -1)
continue;
int newLeftMinuteDigit = CheckAndReflect(hour, false);
if (newLeftMinuteDigit == -1)
continue;
int newMinute = newLeftMinuteDigit * 10 + newRightMinuteDigit;
if (newMinute >= 60)
continue;
for (int minute = 0; minute < 60; minute++)
{
int newRightHourDigit = CheckAndReflect(minute, true);
if (newRightHourDigit == -1)
continue;
int newLeftHourDigit = CheckAndReflect(minute, false);
if (newLeftHourDigit == -1)
continue;
int newHour = newLeftHourDigit * 10 + newRightHourDigit;
if (newHour >= 24)
continue;
validTimeCount++;
Console.WriteLine($"Orig data: {hour:00}:{minute:00}, reflected time: {newHour:00}:{newMinute:00}");
}
}
Console.WriteLine();
Console.WriteLine($"Valid reflected time count: {validTimeCount}");
}
private static int CheckAndReflect(int number, bool left)
{
int digit = left ? number / 10 : number % 10;
if (digit == 3 || digit == 4 || digit == 6 || digit == 7 || digit == 9)
return -1;
if (digit == 2)
return 5;
return digit == 5 ? 2 : digit;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment