Skip to content

Instantly share code, notes, and snippets.

@nolgan
Last active January 12, 2020 07:46
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 nolgan/b8a8405215acb9498d83bc090f82bc20 to your computer and use it in GitHub Desktop.
Save nolgan/b8a8405215acb9498d83bc090f82bc20 to your computer and use it in GitHub Desktop.
For Riddler Express Challenge from 538
public class SmallestDenominator {
public static void main(String[] args) {
double min_denominator = 1000000000;
double numerator = 0;
for(double i=1;i<100000;i++){
for(double j=1;j<50000;j++){
if(((double)1/2019 > i/j) && (i/j > (double)1/2020)){
if(j<min_denominator){
min_denominator = j;
numerator = i;
}
}
}
}
System.out.println("Smallest denominator: " + min_denominator);
System.out.println("Numerator for smallest denominator: " + numerator);
}
}
@nolgan
Copy link
Author

nolgan commented Jan 12, 2020

This value is between 1/2019 and 1/2020.

Output:

Smallest denominator: 4039.0
Numerator for smallest denominator: 2.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment