Skip to content

Instantly share code, notes, and snippets.

@AlexCheese
Created August 28, 2019 01:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlexCheese/1544a73ee978f10024e40ed013efbda8 to your computer and use it in GitHub Desktop.
Save AlexCheese/1544a73ee978f10024e40ed013efbda8 to your computer and use it in GitHub Desktop.
Simple program to determine the number of ticks it takes to open a combo lock
using System;
namespace Yeet
{
public class Program
{
static void Main(string[] args)
{
while (true)
{
Console.Write("Enter combo: ");
string combo = Console.ReadLine();
if (combo == "end") return;
string[] comboArray = combo.Split(' ');
try
{
int comboA = int.Parse(comboArray[0]);
int comboB = int.Parse(comboArray[1]);
int comboC = int.Parse(comboArray[2]);
int tickNumber = ComboThingy(comboA, comboB, comboC);
Console.WriteLine("Number of ticks = " + tickNumber + "\n");
}
catch
{
Console.WriteLine("Invalid combination\n");
continue;
}
}
}
static int ComboThingy(int comboA, int comboB, int comboC)
{
if (comboA < 0 || comboA > 39 || comboB < 0 || comboB > 39 || comboC < 0 || comboC > 39)
{
throw new Exception("Invalid combination");
}
int totalTicks = 0;
const int FULL_TURN = 40;
totalTicks += FULL_TURN;
int diffAB = comboB - comboA;
if (diffAB < 0)
{
diffAB += FULL_TURN;
}
totalTicks += diffAB;
int diffBC = comboB - comboC;
if (diffBC < 0)
{
diffBC += FULL_TURN;
}
totalTicks += diffBC;
return totalTicks;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment