Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,21 @@
Object subclass: Hammer [
Hammer class >> hammingNumbers: howMany [
|h i j k x2 x3 x5|
h := OrderedCollection new.
i := 0. j := 0. k := 0.
h add: 1.
x2 := 2. x3 := 2. x5 := 5.
[ ( h size) < howMany ] whileTrue: [
|m|
m := { x2. x3. x5 } sort first.
(( h indexOf: m ) = 0) ifTrue: [ h add: m ].
( x2 = (h last) ) ifTrue: [ i := i + 1. x2 := 2 * (h at: i) ].
( x3 = (h last) ) ifTrue: [ j := j + 1. x3 := 3 * (h at: j) ].
( x5 = (h last) ) ifTrue: [ k := k + 1. x5 := 5 * (h at: k) ].
].
^ h sort
]
].
(Hammer hammingNumbers: 20) displayNl.
(Hammer hammingNumbers: 1690) last displayNl.

View file

@ -0,0 +1,21 @@
limit := 10 raisedToInteger: 84.
tape := Set new.
hammingProcess := [:newHamming|
(newHamming <= limit)
ifTrue:
[| index |
index := tape scanFor: newHamming.
(tape array at: index)
ifNil:
[tape atNewIndex: index put: newHamming asSetElement.
hammingProcess value: newHamming * 2.
hammingProcess value: newHamming * 3.
hammingProcess value: newHamming * 5]]].
hammingProcess value: 1.
sc := tape asSortedCollection.
sc first: 20. "a SortedCollection(1 2 3 4 5 6 8 9 10 12 15 16 18 20 24 25 27 30 32 36)"
sc at: 1691. "2125764000"
sc at: 1000000. "519312780448388736089589843750000000000000000000000000000000000000000000000000000000"

View file

@ -0,0 +1,16 @@
tape := Heap with: 1 -> 1.
hammingStream :=
[| next |
next := tape removeFirst.
next value <= 2 ifTrue: [tape add: next key * 2 -> 2].
next value <= 3 ifTrue: [tape add: next key * 3 -> 3].
next value <= 5 ifTrue: [tape add: next key * 5 -> 5].
next key]
reading.
hammingStream read: 20. "get first 20 values => #(1 2 3 4 5 6 8 9 10 12 15 16 18 20 24 25 27 30 32 36)"
hammingStream ++ 1670. "skip the next 1670 values"
hammingStream get. "and the 1691th value is => 2125764000".
hammingStream ++ (999999 - 1691). "now skip more to position at 999,999".
hammingStream get. "and the 1,000,000th value is => 519312780448388736089589843750000000000000000000000000000000000000000000000000000000".
tape size. "See how many we have buffered => 24904"