Skip to main content
added 6 characters in body
Source Link
user42682
user42682

Haskell, 82 8181 80 bytes

This is a port of my Clean answer.

r!n=foldr(f n)[[last r]]$initn|let r
f n x(r@(a:_):s)|x>a=[x,n+a]:(x-n:r):s|y<-x:r=y:ss=foldr f[[last r]]$init r

Try it online!Try it online!

-1, -1 thanks to Laikoni

Haskell, 82 81 bytes

This is a port of my Clean answer.

r!n=foldr(f n)[[last r]]$init r
f n x(r@(a:_):s)|x>a=[x,n+a]:(x-n:r):s|y<-x:r=y:s

Try it online!

-1 thanks to Laikoni

Haskell, 82 81 80 bytes

This is a port of my Clean answer.

r!n|let f x(r@(a:_):s)|x>a=[x,n+a]:(x-n:r):s|y<-x:r=y:s=foldr f[[last r]]$init r

Try it online!

-1, -1 thanks to Laikoni

Source Link
user42682
user42682

Haskell, 82 81 bytes

This is a port of my Clean answer.

r!n=foldr(f n)[[last r]]$init r
f n x(r@(a:_):s)|x>a=[x,n+a]:(x-n:r):s|y<-x:r=y:s

Try it online!

-1 thanks to Laikoni