Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unsigned long peak(unsigned long nel, int(*less)(unsigned long i, unsigned long j)) {
- if (nel < 3) return less(0, 1);
- for (unsigned long k = (nel-1); k >= 0; k--) {
- if(less(k-1, k) && less(k+1, k)) return k;
- }
- }
- int less(unsigned long i, unsigned long j)
- {
- if (i == j) return 0;
- if (i < j) {
- if (j <= 11241155978086311589UL) return 1;
- if (i >= 11241155978086311589UL) return 0;
- return (11241155978086311589UL-i) < (j-11241155978086311589UL);
- }
- if (i <= 11241155978086311589UL) return 0;
- if (j >= 11241155978086311589UL) return 1;
- return (11241155978086311589UL-j) < (i-11241155978086311589UL);
- }
- unsigned long peak(unsigned long, int (*)(unsigned long, unsigned long));
- int main(int argc, char **argv)
- {
- unsigned long i = peak(13356955260197607378UL, less);
- if (i == 11241155978086311589UL) {
- printf("CORRECTn");
- } else {
- printf("WRONGn");
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment