Skip to main content
6 of 12
deleted 125 characters in body
proud haskeller
  • 6.1k
  • 1
  • 23
  • 37

#Haskell, 154 149 147 145 bytes

import Data.List
a@(r,x)%y|r==[]=a|0<1=(\t->(r\\t,x++(y\\t)))$[t|t<-tails x,isPrefixOf t y]!!0
h n=snd$foldl(%)("",['0'..'9'])$map show[n,n-1..1]

adding in the recycling-checking cost a lot of characters... sigh

golfed a bit by remembering what digits weren't recycled yet and stopping when the list is empty

example output:

*Main> h 110
"110910810710610510410310210100998979695949392919089887868584838281807978776757473727170696867665646362616059585756554535251504948474645443424140393837363534332313029282726252423221"
proud haskeller
  • 6.1k
  • 1
  • 23
  • 37