collatz

Code Golf: Collatz Conjecture

 ̄綄美尐妖づ 提交于 2019-11-27 09:42:58
问题 Locked . This question and its answers are locked because the question is off-topic but has historical significance. It is not currently accepting new answers or interactions. Inspired by http://xkcd.com/710/ here is a code golf for it. The Challenge Given a positive integer greater than 0, print out the hailstone sequence for that number. The Hailstone Sequence See Wikipedia for more detail.. If the number is even, divide it by two. If the number is odd, triple it and add one. Repeat this

Project Euler Question 14 (Collatz Problem)

天大地大妈咪最大 提交于 2019-11-26 22:51:51
The following iterative sequence is defined for the set of positive integers: n ->n/2 (n is even) n ->3n + 1 (n is odd) Using the rule above and starting with 13, we generate the following sequence: 13 40 20 10 5 16 8 4 2 1 It can be seen that this sequence (starting at 13 and finishing at 1) contains 10 terms. Although it has not been proved yet (Collatz Problem), it is thought that all starting numbers finish at 1. Which starting number, under one million, produces the longest chain? NOTE: Once the chain starts the terms are allowed to go above one million. I tried coding a solution to this

Project Euler Question 14 (Collatz Problem)

血红的双手。 提交于 2019-11-26 08:29:31
问题 The following iterative sequence is defined for the set of positive integers: n ->n/2 (n is even) n ->3n + 1 (n is odd) Using the rule above and starting with 13, we generate the following sequence: 13 40 20 10 5 16 8 4 2 1 It can be seen that this sequence (starting at 13 and finishing at 1) contains 10 terms. Although it has not been proved yet (Collatz Problem), it is thought that all starting numbers finish at 1. Which starting number, under one million, produces the longest chain? NOTE: