Showing results for 
Search instead for 
Did you mean: 
Level 2
29 17 1 1
Message 1 of 3
Flag Post


[HP Prime] Sequence App: end condition, maximum (at index?), path length?

HP Recommended
HP Prime

Do you guys know the Collatz Conjecture, sometimes known as the Ulam numbers or (thanks to Brian Hayes) the hailstone numbers?

It‘s an easily sted problem but mathematics doesn‘t seem to be ready for such kinds of problems (I think it was Paul Erdös who said that). It‘s still unsolved, however.


Take a start number n. If it‘s odd, the next number shall be 3*n+1. If it‘s even the next number shall be n/2.

We stop when we reach 1, because otherwise we‘re in an endless loop, 4->2->1->4->2->1->...


Nobody knows whether any start number reaches 1. It seems so because mathematicians have tested a HUGE amount of start numbers. But it‘s not proven. 


I love to play with this and write programs and scribble on (huge) paper regarding this problem.


Very cool: the HP Prime‘s Sequence App can be used to explore this sequence!


Just define U1(1) as your start number (try 27! ;-)), leave U1(2) empty.

Define U1(N) as a piecewise defined function:

Ulam sequenceUlam sequence

Now you can play with your plot settings. Try N Rng and X Rng 0..112, Y Rng 0..9232


However, I was wondering:

- How can I let the Prime determine the maximum value that occured in the sequence before it hit 1?

- And at what position (index) was that?

- And how long was the path from the start number until we reached the 1?


0 Kudos
Level 6
305 297 32 76
Message 2 of 3
Flag Post
HP Recommended

Hello Stefan,


A nice thing is that we can also get the elements of our sequence in Home view.


Let us take as an example that U1(1)=10023.

When we enter in Home view: U1(4), we get 45106, which is the 4th element of the sequence.


Now we can also put these elements into a list.


We can dispose of many list commands via the menu: Toolbox-Math-List.


We put the first 1000 elements into L1 by:



We can find the position of 1 by:

POS(L1,1) which returns: 66


If we want we can now shorten the list a little by:



Now we sort the list:



and take its last element, which is its maximum:

L3(66) returns 76120


We get the position of the maximum in our original list by:

POS(L1,76120) which gives: 11.




Level 2
29 17 1 1
Message 3 of 3
Flag Post
HP Recommended

That's very nice, Jan, thanks a lot!


It would be cool if at least some of those possibilities would be directly integrated into the Sequence App. 😉



0 Kudos
† The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation