Guest User

Untitled

a guest
Oct 23rd, 2017
70
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. {
  3. if (nel < 3) return less(0, 1);
  4. for (unsigned long k = 1; k < (nel - 1); k++) {
  5. if(less(k-1, k) && less(k+1, k)) return k;
  6. }
  7. }
  8.  
  9. int less(unsigned long i, unsigned long j)
  10. {
  11. if (i == j) return 0;
  12.  
  13. if (i < j) {
  14. if (j <= 11241155978086311589UL) return 1;
  15. if (i >= 11241155978086311589UL) return 0;
  16. return (11241155978086311589UL-i) < (j-11241155978086311589UL);
  17. }
  18.  
  19. if (i <= 11241155978086311589UL) return 0;
  20. if (j >= 11241155978086311589UL) return 1;
  21. return (11241155978086311589UL-j) < (i-11241155978086311589UL);
  22. }
  23.  
  24. unsigned long peak(unsigned long, int (*)(unsigned long, unsigned long));
  25.  
  26. int main(int argc, char **argv)
  27. {
  28. unsigned long i = peak(13356955260197607378UL, less);
  29. if (i == 11241155978086311589UL) {
  30. printf("CORRECTn");
  31. } else {
  32. printf("WRONGn");
  33. }
  34. return 0;
  35. }
Add Comment
Please, Sign In to add comment