Advertisement
Guest User

a rewrite

a guest
Feb 12th, 2020
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.49 KB | None | 0 0
  1. ;; https://stackoverflow.com/questions/60076982/
  2. ;; i-want-to-make-a-function-that-deletes-only-a-single-minimum-element-in-a-list
  3.  
  4. deleteMin []      =  []
  5. deleteMin (x:xs)  =  if (imin==0) then xs else (x:ys)
  6.   where
  7.   (ys, imin)  =  foldr g z xs  1 (0 :: Int) x
  8.      where
  9.      z  _ im _  =  ([], im)  
  10.      g x r  !i !im !xm  =  (if (i == imin) then ys else (x:ys), im')
  11.        where
  12.        (ys, im') | x < xm     =  r  (i + 1) i  x
  13.                  | otherwise  =  r  (i + 1) im xm
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement