Re: Learning recursion with hailstone seqence



"DAVID B MORGAN" <lepton2@xxxxxxxxxxx> schreef in bericht
news:J%47h.3638$v93.2468@xxxxxxxxxxx
I'm playing with the hailstone sequence. My function will
need to iterate millions of times to process the data. I have two
questions:

1. Can this function be optimised ? (approx 2^67 iterations are neccessary
on current dataset)
2. How can I test huge numbers (like 2^1000) --- Int64 can't handle it

function hailstone(x:int64):int64;
begin
if odd(x) then result:=x*3+1
else result:=x shr 1;
if result<>1 then hailstone(result) ;
end;


If the purpose is to exercise with recursion, then consider this function
instead:

function hailstone(x:int64):int64;
// will return iteration length
begin
if odd(x) then x:=x*3+1 else x:=x shr 1;
if x>1 then result:=1+hailstone(x) else result:=0;
end;

Count on a recursion depth of 50 times the bit-length of x.
Tom


.



Relevant Pages

  • Re: Learning recursion with hailstone seqence
    ... iterate millions of times to process the data. ... else result:=x shr 1; ... Perhaps using shorter values or using MMX in some way, ...
    (comp.lang.pascal.delphi.misc)
  • Re: Learning recursion with hailstone seqence
    ... need to iterate millions of times to process the data. ... else result:=x shr 1; ... A Hailstone sequence is the sequence of integers, ... without contributing to the result. ...
    (comp.lang.pascal.delphi.misc)
  • Re: Documentaion on m_viewList?
    ... I just use CDocument::GetNextViewto iterate the list. ... Tom ... > I can't find anything at MSDN. ... Prev by Date: ...
    (microsoft.public.vc.mfc)
  • Re: Line Input not finding Chr10 or 13
    ... Tom - That worked well. ... because I thought it would take forever but it actually processes ... can handle the modifications to iterate on different sheets for the ...
    (microsoft.public.excel.programming)