Smalltalk methods : Nov 1996
Smalltalk methods : Nov 1996
!Integer methods !
hailstoneHeight
"return the maximum height the hailstone number reaches"
| current max |
max :=0.
current := self.
[current > 1]
whileTrue: [ current > max
ifTrue: [max := current].
current even
ifTrue: [current := current // 2]
ifFalse: [current := current * 3 + 1]].
^max! !
|
hailstonePathLength
"return the maximum path length of a hailstone run"
| current path |
path :=0.
current := self.
[current > 1]
whileTrue: [ path := path + 1.
current even
ifTrue: [current := current // 2]
ifFalse: [current := current * 3 + 1]].
^path! !
|
hailstoneThresholdHeight
" generate the first million maximum heights
Integer hailstoneThresholdHeight
"
| a p h |
h := 0.
3 to: 1000 by: 2 do: [ :n | a := n hailstoneHeight.
a > h
ifTrue: [ h := a.
Transcript show: n asString; tab; show: h asString; tab;
show: n hailstonePathLength asString; cr]]! !
|
hailstoneThresholdPath
" generate the first million maximum paths
Integer hailstoneThresholdPath
"
| a p h |
h := 0.
3 to: 1000 by: 2 do: [ :n | a := n hailstonePathLength.
a > h
ifTrue: [ h := a.
Transcript show: n asString; tab; show: h asString; tab;
show: n hailstoneHeight asString; tab; show: (h\n) floor asString; cr]]! !
|
Hardware Projects
Hardware Projects
This section details current and historical hardware
projects.
Analog to Digital Conversion
Analog to Digital Conversion
Breadboard prototype of AD converter using an 808ADC - without Parallel port data transfer.
Hailstone (3n+1) Numbers
Hailstone (3n+1) Numbers