Skip to content

Instantly share code, notes, and snippets.

@Xhendos
Created October 20, 2017 19:45
Show Gist options
  • Save Xhendos/cd4feeb41851e2d9ef8fbf5cffa5ed5c to your computer and use it in GitHub Desktop.
Save Xhendos/cd4feeb41851e2d9ef8fbf5cffa5ed5c to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdbool.h>
/* Contains floor() which will round */
#include <math.h>
/* Prototyping */
bool calculate_instructions(int delay1, int delay2);
bool float_mod(double instructions);
int desired_instructions = 31244;
int main()
{
int delay1, delay2;
bool found = false;
P1:while(!found)
{
for(delay1 = 1; delay1 <= 255; delay1++)
{
for(delay2 = 1; delay2 <= 255; delay2++)
{
bool b = calculate_instructions(delay1, delay2);
if(b)
{
printf("%d and %d\n", delay1, delay2);
found = true;
goto P1;
}
}
}
return 1;
}
return 0;
}
bool calculate_instructions(int delay1, int delay2)
{
double instructions = ((((delay1 - 1) * 3) + 2 + 2) * (delay2 - 1));
if(float_mod(instructions) && ((int) instructions == desired_instructions))
{
return true;
}
return false;
}
bool float_mod(double instructions)
{
double modulo = instructions - floor(instructions);
if(!modulo)
{
return true;
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment