We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Project Euler #33: Digit canceling fractions
Project Euler #33: Digit canceling fractions
Sort by
recency
|
47 Discussions
|
Please Login in order to post a comment
I wrote my code in python and got 66.67%. Tried to improve it so hard, but couldn't then wrote the same code in C++ and got 83.33% then wrote the same in Go and got 100%...
(GO has very fast compilation time)
python code:
int take_element_4_1 (int a, int b) { int count=0; int res=0; if(b<10) return 0; else if (b>9 && b<100) { res=a-b; if (res%1000 !=0 ) return 0; else return res/1000; } else { while (a) { if (a%10==b%10) { a/=10; b/=10; count ++; } else { res= res*10+a%10;
a/=10;
}
}
int check_last_case (int a,int b ,int x,int y ) {
}
main() int i=1;
JAva code
Some points as also mentioned by other programmers
1) You can't cancel any 0, irrespective of whatever position it is at.
2) 0's at end are allowed as long as point 1 is followed.
3) You have to 'cancel' common digits in numerator and denominator not reduce the fractions, and hence the order of digits can be any.
4) Don't repeat count fractions
100points/- python 3
`