Skip to main content
added 77 characters in body
Source Link
Dominic van Essen
  • 37.2k
  • 2
  • 24
  • 61

R, 5656 44 bytes

Edit: saved 12 bytes after looking at Jonathan Allan's answer: please upvote that!

f=functionfunction(c)`if`(t<-sum(h<-c<=1/sum,d=sum(c|1)),t+fmatch(c[!h])T,01/c<d:1,d+1)-1 

Try it online!Try it online!

R, 56 bytes

f=function(c)`if`(t<-sum(h<-c<=1/sum(c|1)),t+f(c[!h]),0) 

Try it online!

R, 56 44 bytes

Edit: saved 12 bytes after looking at Jonathan Allan's answer: please upvote that!

function(c,d=sum(c|1))match(T,1/c<d:1,d+1)-1 

Try it online!

Source Link
Dominic van Essen
  • 37.2k
  • 2
  • 24
  • 61

R, 56 bytes

f=function(c)`if`(t<-sum(h<-c<=1/sum(c|1)),t+f(c[!h]),0) 

Try it online!