Skip to content

Instantly share code, notes, and snippets.

@Mjiig
Created April 1, 2012 09:02
Show Gist options
  • Save Mjiig/2273876 to your computer and use it in GitHub Desktop.
Save Mjiig/2273876 to your computer and use it in GitHub Desktop.
Project euler #52
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include <math.h>
void digits ( char digits[10], int n )
{
int top=(int)log10((float)n)+1;
int i=0;
memset(digits, 0, 10);
while(i<top)
{
digits[n%10]++;
n/=10;
i++;
}
}
bool answer( int n )
{
char digits1[10];
char digits2[10];
int i;
digits(digits1, n);
for(i=2; i<=6; i++)
{
digits(digits2, i*n);
if(memcmp(digits1, digits2, 10)) //true if the values are different
{
return false; //the number is not the answer
}
}
return true; // if we got this far the number is the answer
}
int main ( void )
{
int i=0;
while(!answer(++i));
printf("%d\n", i);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment