Questions tagged [collatz-sequence]

This tag should be used for code related to the sequences described in the Collatz conjecture.

Filter by
Sorted by
Tagged with
3 votes
1 answer

Computational verification of Collatz conjecture

Prerequisites The typedef name uint128_t designates an unsigned integer type with width exactly 128 bits. The ...
  • 249
19 votes
1 answer

Streaming Collatz

Challenge The recent question The 3n + 1 algorithm for a range inspired me to investigate a Java-8 dependent streaming mechanism for solving the programming challenge: For any two numbers ...
  • 96.8k
15 votes
2 answers

Automate the Boring Stuff with Python - The Collatz sequence project

I am new to programming and started learning with Automate the Boring Stuff with Python. I just completed chapter 3's "Collatz sequence" project. I was wondering what would you do differently and ...
  • 151
10 votes
4 answers

Python Automate the Boring Stuff Collatz exercise

I'm looking for some feedback on my code for the collatz function exercise in the Python book Automate the Boring Stuff. It works, but doesn't feel very elegant to me. Is there a better way to ...
8 votes
4 answers

Project Euler problem 14 (longest Collatz sequence) in Swift 3

I was trying to solve Project Euler:Problem 14 using Swift 3, but it takes ages to give me an answer, which is a sign that my code is absolute garbage performance-wise. What could I do to increase the ...
user avatar
7 votes
3 answers

Hailstone Sequences in Python

For the problem given: Douglas Hofstadter’s Pulitzer-prize-winning book, Gödel, Escher, Bach, poses the following mathematical puzzle. Pick a positive integer \$n\$ as the start. If \$n\$ is ...
  • 3,339
6 votes
2 answers

UVA 100: "The 3n + 1 problem"

I’ve solved UVA Problem 100: The 3n + 1 problem . In short, the task was to write a program that calculates a maximum of Collatz sequence lengths for any given range of starting values. My program: <...
  • 571
6 votes
1 answer

Locating the largest Collatz Sequence with memoization

Inspired by this question I wrote a memoized form of the collatz sequence calculator. The idea was to cache the sequence lengths for as many sequences as possible, from 0 to some value. I managed to (...
4 votes
3 answers

Generator for the collatz conjecture sequence

I tried to write this code as concisely as possible. Is this the best way to do it? ...
3 votes
2 answers

Contest Solution: Hailstones

The Problem In the January 1984 issue of Scientific American, an interesting sequence of numbers known as a hailstone series was described. The series is formed by generating the next number ...
  • 2,927
3 votes
1 answer

Project Euler #14 (Longest Collatz sequence)

A Collatz sequence for a given positive integer \$n\$ is to take half of \$n\$ if even and \$3n+1\$ if \$n\$ is odd; repeat until the value goes to \$1\$. The question is which number from 1 to 1,000,...
2 votes
3 answers

Determine Collatz sequence length for given starting values

I am trying to get into the habit of solving programming puzzles in my spare time but am stuck on the first one (which I know can be for a large number of reasons, hence my posting for help). Shown ...
2 votes
1 answer

Automate the Boring Stuff - Collatz Exercise

I wrote the following code for the Collatz exercise: The Collatz Sequence Any feedback is appreciated. Write a function named collatz() that has one parameter ...
  • 115
-4 votes
3 answers

Finding the longest Collatz Sequence

Inspired by Project Euler 14: Longest Collatz Sequence "Which starting number, under one million, produces the longest Collatz Sequence chain?" I wrote the following Java code: ...
  • 13