Guest User

Untitled

a guest
Oct 23rd, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. unsigned long peak(unsigned long nel, int(*less)(unsigned long i, unsigned long j)) {
  2. if (nel < 3) return less(0, 1);
  3. for (unsigned long k = (nel-1); k >= 0; k--) {
  4. if(less(k-1, k) && less(k+1, k)) return k;
  5. }
  6. }
  7.  
  8. int less(unsigned long i, unsigned long j)
  9. {
  10. if (i == j) return 0;
  11.  
  12. if (i < j) {
  13. if (j <= 11241155978086311589UL) return 1;
  14. if (i >= 11241155978086311589UL) return 0;
  15. return (11241155978086311589UL-i) < (j-11241155978086311589UL);
  16. }
  17.  
  18. if (i <= 11241155978086311589UL) return 0;
  19. if (j >= 11241155978086311589UL) return 1;
  20. return (11241155978086311589UL-j) < (i-11241155978086311589UL);
  21. }
  22.  
  23. unsigned long peak(unsigned long, int (*)(unsigned long, unsigned long));
  24.  
  25. int main(int argc, char **argv)
  26. {
  27. unsigned long i = peak(13356955260197607378UL, less);
  28. if (i == 11241155978086311589UL) {
  29. printf("CORRECTn");
  30. } else {
  31. printf("WRONGn");
  32. }
  33. return 0;
  34. }
Add Comment
Please, Sign In to add comment