Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
|
|
@ -8,7 +8,7 @@ say x ' has a hailstone sequence of ' words($)
|
|||
say ' and starts with: ' subword($, 1, 4) " ∙∙∙"
|
||||
say ' and ends with: ∙∙∙' subword($, max(1, words($)-3))
|
||||
say
|
||||
if y==0 then exit /*═══════════════════task 2═════════════════════════*/
|
||||
if y==0 then exit /*═══════════════════task 2═════════════════════════*/
|
||||
w=0; do j=1 for y /*traipse through the numbers. */
|
||||
call hailstone j /*compute the hailstone sequence.*/
|
||||
if #hs<=w then iterate /*Not big 'nuff? Then keep going.*/
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ say x ' has a hailstone sequence of ' words($)
|
|||
say ' and starts with: ' subword($, 1, 4) " ∙∙∙"
|
||||
say ' and ends with: ∙∙∙' subword($, max(1, words($)-3))
|
||||
say
|
||||
if y==0 then exit /*═══════════════════task 2═════════════════════════*/
|
||||
if y==0 then exit /*═══════════════════task 2═════════════════════════*/
|
||||
w=0; do j=1 for y /*loop through all numbers <100k.*/
|
||||
$=hailstone(j) /*compute the hailstone sequence.*/
|
||||
#hs=words($) /*find the length of the sequence*/
|
||||
|
|
@ -20,11 +20,11 @@ exit /*stick a fork in it, we're done.*/
|
|||
/*──────────────────────────────────HAILSTONE subroutine────────────────*/
|
||||
hailstone: procedure expose @.; parse arg n 1 s 1 o /*N,S,O = 1st arg.*/
|
||||
@.1= /*special case for unity. */
|
||||
do forever /*loop while N isn't unity. */
|
||||
if @.n\==0 then do; s=s @.n; leave; end /*been here before?*/
|
||||
do while @.n==0 /*loop while residual is unknown.*/
|
||||
if n//2 then n=n*3+1 /*if N is odd, calc: 3*n +1 */
|
||||
else n=n%2 /* " " " even, perform fast ÷ */
|
||||
s=s n /*build a sequence list (append).*/
|
||||
end /*forever*/
|
||||
end /*while*/
|
||||
s=s @.n /*append to a sequence list. */
|
||||
@.o=subword(s,2) /*memoization for this hailstone.*/
|
||||
return s
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue