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
7
votes
3answers
957 views

Python - The Collatz Sequence

Can I get a review of my code for the the Collatz Sequence from Chapter three of Automate the Boring Stuff with Python? The Collatz Sequence Write a function named collatz() that has one ...
3
votes
2answers
68 views

Computational verification of Collatz conjecture using gmplib

Prerequisites The unsigned long type has a size of 64 bits. The following macros are defined. ...
3
votes
1answer
257 views

Computational verification of Collatz conjecture

Prerequisites The typedef name uint128_t designates an unsigned integer type with width exactly 128 bits. The ...
1
vote
1answer
58 views

python : Collatz Sequence

I am a beginner in python. I found this problem in the book Automate the Boring Stuff with Python. How can I improve this program using latest version of python. ...
0
votes
1answer
122 views

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 ...
0
votes
1answer
88 views

Finding the longest Collatz sequence using Go, concurrently

I am working through this problem on project euler. Basic purpose of the code: ...
3
votes
4answers
727 views

Testing a Collatz Conjecture Conjecture (Python)

I had an intuition that the maximal trajectory lengths for collatz conjecture numbers would be produced by numbers of the form (2**n)-1 so I wrote a program to test ...
4
votes
0answers
76 views

Collatz Conjecture Disprover Unit - Googol Edition

The Wikipedia article about the Collatz Conjecture has these quotes: If the conjecture is false, it can only be because there is some starting number which gives rise to a sequence that does not ...
3
votes
2answers
156 views

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 ...
15
votes
2answers
3k views

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 ...
4
votes
0answers
135 views

Collatz fractal in Rust

Among the many fractals, there is Collatz Fractal based on a complex extension of: $$f(x) = \left\{ \begin{array}{ll} \frac{x}{2} \space \text{if even} \\ 3x + 1 \space \text{if odd} \end{array} \...
1
vote
1answer
74 views

Longest Collatz sequence in Scala

I am trying to find the longest Collatz Sequence: Which starting number, ≤ N, produces the longest chain? If many possible such numbers are there print the maximum one. (1 ≤ N ≤ 5×106) I tried ...
1
vote
3answers
217 views

Euler Project 14 Longest Collatz Sequence [closed]

I have been working through the euler project and I have created the following code for Problem 14, which asks which starting number, under 1 million, produces the longest Collatz Sequence chain. It ...
10
votes
4answers
3k views

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 ...
4
votes
1answer
73 views

Generating the Collatz sequence in F#

Below is my code for building the collatz sequence so a given number. I'm trying to make the function tail recursive and I believe that this impelemtation is tail recursive but I'm not yet so ...
3
votes
1answer
131 views

Project Euler problem #14 (longest Collatz chain) in Swift

This is my Swift code for finding the starting number, under one million, which produces the longest collatz chain. ...
5
votes
4answers
3k views

Collatz Conjecture (c++)

I am new to C++ and this is my first program. The objective of this program is to fully complete the sequence called the Collatz conjecture. It concerns a sequence defined as follows: start with ...
3
votes
2answers
273 views

Counting terms in Collatz sequences until 1 is reached or a limit is exceeded

My friend and I are into competitive programming and we wrote two very similar programs for a problem. His got accepted with a runtime of 0.6 s while mine didn't get accepted even after 3 s. I was ...
3
votes
1answer
261 views

Collatz Conjecture Meet of 2 Numbers

I need the most efficient way to calculate when the Collatz Conjecture of two numbers, a and b respectively, are the same. Here ...
3
votes
3answers
341 views

Longest Collatz sequence using dynamic programming in Java

I'm not getting where else should I optimize it. Is there any way to optimize this code any further? Just give me hints. ...
4
votes
2answers
2k views

Project Euler #14 - Longest Collatz Sequence in Python

I recently solved Project Euler Problem 14 in Python: The following iterative sequence is defined for the set of positive integers: ...
3
votes
2answers
142 views

UVA 100: “The 3n + 1 problem” take 2

This is my second attempt to solve this problem, my first attempt is here: UVA 100: "The 3n + 1 problem" This time I tried to take lessons from the failures and mistakes You pointed out in ...
12
votes
2answers
2k views

“Longest Collatz sequence” in C slower than in Python 3

This tight-looped memoization-less C solution to Project Euler's problem 14 seems efficient, but ran much slower than a similarly trivial Python 3 program. For the desired ...
8
votes
4answers
1k views

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 ...
6
votes
2answers
509 views

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: <...
2
votes
3answers
495 views

Project Euler: Longest Collatz Sequence

The Collatz Sequence is an iterative sequence that is defined for all positive integers as such: n → n/2 (n is even) n → 3n + 1 (n is odd) If 13 were to be entered into this sequence, the result ...
6
votes
1answer
333 views

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
3answers
2k views

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: ...
1
vote
1answer
366 views

Python program for testing the Collatz Conjecture

This is a simple program to test if integers will follow an interesting, improvable statement that if disproven, calls for a bravo. But, ignoring the pretentious poetry, this code allows the user to ...
3
votes
2answers
910 views

Calculating the Collatz conjecture of a number

I've made a Collatz Conjecture sequence calculator and I would like some feedback on what I can do better in regards to the code I've implemented, i.e. bad practices you see, improvements that can be ...
4
votes
2answers
144 views

Euler Project 14 (Longest Collatz Sequence)

Project Euler 14 asks: Which starting number, under one million, produces the longest Collatz sequence? I've been trying to optimize this solution to execute in less then 1s. Agenda for first 50 ...
3
votes
2answers
357 views

Efficient solution to Project Euler 14 (Longest Collatz sequence)

This is an iterative review. I asked for reviews on a Collatz sequence generator here. I tried to address all of the suggestions that were made. I've added a new function ...
4
votes
3answers
1k views

Generator for the collatz conjecture sequence

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

3n + 1 programming challenge in Python

I am trying to find a efficient solution for the 3n + 1 problem on uvaonlinejudge. The code I have uses memoization using a dictionary. I am getting a 'Time limit Exceeded' error when I submit the ...
1
vote
1answer
573 views

Python script to calculate the Collatz conjecture

Here is the code. ...
5
votes
1answer
208 views

Syracuse conjecture in OCaml

I am wondering how to optimize the following OCaml simple code. ...
7
votes
1answer
615 views

I CAN HAS EULR 14, PLZ?

A few days ago I found myself learning lolcode. It turns out it's (almost) a real language and capable of handling (pseudo-)serious problems. So, let's try some (pseudo-)serious code this time. ...
2
votes
3answers
765 views

Calculating the Collatz Conjecture

Today I read this thing about the Collatz Conjecture and wanted to try and write a program that calculates all the numbers. If you have any idea how the code could be shortened, please tell me. ...
3
votes
4answers
716 views

Find out the number under 1 million which produces the largest Collatz Sequence

So, I have written a code which calculates the number under n( 1 million in this case) which produces the largest Collatz Sequence in that ...
2
votes
3answers
2k views

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 ...
4
votes
2answers
806 views

Memoized Collatz sequence

Here is one of my programs that utilized memoization and array to improve performance and memory usage. The performance seems satisfactory but the memory usage is ridiculous and I can't figure out ...
4
votes
0answers
111 views

Project Euler #14 in Clojure (finding long Collatz sequence chain)

I'm working on a Clojure implementation for Project Euler #14, which asks for the initial element, under 106, that produces the longest collatz-sequence chain. I'm trying to make use of every ...
-1
votes
1answer
1k views

Code that calculates Hailstone Sequence of input numbers, and code that calculates the number with the largest Hailstone sequence smaller than `z`

I managed to make a simple function that calculates the Hailstone sequence of numbers and print it out, and I just done a calculator that grabs the number with the largest sequence smaller than ...
4
votes
1answer
1k views

Collatz Sequence in Python

I'm trying to use Python to solve the Project Euler problem regarding the Collatz sequence. With some research online, I have come up with the code below. However, it still takes a long time to find ...
6
votes
2answers
296 views

Calculating numbers in the Collatz sequence

I have found two ways in which I can generate the Collatz sequence given a start number. I have looked briefly into their performance, but I'd like a more in depth/solid review into the difference in ...
5
votes
3answers
778 views

Optimize Collatz conjecture

This was the exercise: Exercise PSD Think about a number under 25. Write down the number. If the number is even, divide in to two en write down the result below. If the number isn’t even (...
3
votes
2answers
446 views

Ulam numbers (calculates your life expectancy if you want to)

I'm new to Java and wanted to present to you my latest project: Ulam Numbers ...
19
votes
1answer
271 views

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 ...
0
votes
2answers
652 views

Uva Online Judge problem 100, 3n + 1

I am having a tough time submitting this code to UVa Online judge and having it pass. I keep getting the message - Your program used more CPU time than what is allowed for this problem. That means ...
6
votes
3answers
13k views

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 ...