Humble numbers: Difference between revisions

Realize in F#
(Realize in F#)
Line 636:
1767 have 9 digits</pre>
 
=={{header|F_Sharp|F#}}==
===The Functions===
<lang fsharp>
// Generate humble numbers. Nigel Galloway: June 18th., 2020
let fN g=let mutable n=1UL in (fun()->n<-n*g;n)
let fI (n:uint64) g=let mutable q=n in (fun()->let t=q in q<-n*g();t)
let fG n g=let mutable vn,vg=n(),g() in fun()->match vg<vn with true->let t=vg in vg<-g();t |_->let t=vn in vn<-n();t
let rec fE n=seq{yield n();yield! fE n}
let fL n g=let mutable vn,vg,v=n(),g(),None
fun()->match v with
Some n->v<-None;n
|_->match vg() with
r when r<vn->r
|r->vg<-fG vg (fI vn (g()));vn<-n();v<-Some r;vg()
let humble = seq{yield 1UL;yield! fE(fL (fN 7UL) (fun()->fL (fN 5UL) (fun()->fL (fN 3UL) (fun()->fN 2UL))))}
</lang>
===The Tasks===
<lang fsharp>
humble |> Seq.take 50 |> Seq.iter (printf "%d ");printfn ""
</lang>
{{out}}
<pre>
1 2 3 4 5 6 7 8 9 10 12 14 15 16 18 20 21 24 25 27 28 30 32 35 36 40 42 45 48 49 50 54 56 60 63 64 70 72 75 80 81 84 90 96 98 100 105 108 112 120
</pre>
<lang fsharp>
for n in [1..18] do let g=pown 10UL n in printfn "There are %d humble numbers with %d digits" (humble|>Seq.skipWhile(fun n->n<g/10UL)|>Seq.takeWhile(fun n->n<g)|>Seq.length) n
</lang>
{{out}}
<pre>
There are 9 humble numbers with 1 digits
There are 36 humble numbers with 2 digits
There are 95 humble numbers with 3 digits
There are 197 humble numbers with 4 digits
There are 356 humble numbers with 5 digits
There are 579 humble numbers with 6 digits
There are 882 humble numbers with 7 digits
There are 1272 humble numbers with 8 digits
There are 1767 humble numbers with 9 digits
There are 2381 humble numbers with 10 digits
There are 3113 humble numbers with 11 digits
There are 3984 humble numbers with 12 digits
There are 5002 humble numbers with 13 digits
There are 6187 humble numbers with 14 digits
There are 7545 humble numbers with 15 digits
There are 9081 humble numbers with 16 digits
There are 10815 humble numbers with 17 digits
There are 12759 humble numbers with 18 digits
</pre>
=={{header|Factor}}==
<lang factor>USING: accessors assocs combinators deques dlists formatting fry
2,172

edits