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
|
46 Discussions
|
Please Login in order to post a comment
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
`
here is my submission in java, i have tested the code and provides correct results in almost all tests using the help from the discussions below however i failed the timeout, if anyone wants some refrence you can refer below-
import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set;
public class Main { public static void main(String[] args) { int n = 4; int k = 3;
}