The Collatz Conjecture is a conjecture that a certain algorithm always terminates. The algorithm is stated as follows: starting with some positive integer n, divide n by two if it is even and otherwise triple n and add one. The algorithm terminates when n reaches one. It is currently an open problem whether this terminates for all positive integers. It is also called the Hailstone Sequence.
Questions tagged [collatz]
284 questions
0
votes
2 answers
Segmentation fault with high values (Xeon Phi)
I am working on a Collatz Conjecture problem using Xeon Phi through Stampede.
I have tested my code been tested and works fine for values up to 100,000, but testing values up 1 million, I receive a segmentation fault ("SIGSEV") almost immediately.…

Sam
- 387
- 1
- 6
- 15
0
votes
1 answer
Type signature in a single-function collatz chain
I'm new to haskell and struggling with type signatures. I'm working on a single-function Collatz chain generator. I have seen a few haskell collatz questions, but haven't seen any that answer the kind of problem that I'm trying to answer. I'm…

Mark Karavan
- 2,654
- 1
- 18
- 38
0
votes
0 answers
Collatz memoisation with a C++ map
Ive decided to write code that'd output a Collatz tree. That'd probably have to wait for another question; the current question is this:
We want to calculate the Collatz sequence for a given number only once, and then use memoization. That's what I…

Chiffa
- 1,486
- 2
- 19
- 38
0
votes
1 answer
collatz conjecture using recursion and multiple arguments in python 2.7
I am required to write python code for the collatz conjecture using recursion in which the user is prompted for a positive integer and that number is either divided by 2 if even of multiplied by 3 and added to 1 if odd and this sequence continues…

user3565596
- 3
- 2
0
votes
0 answers
Reverse Collatz sequence code not computing
Using C++, I was writing a program that would take the first n numbers starting at 1 and output their respective "path count", which is what I call the number of iterations of the Collatz sequence it takes to get from the number to zero (see the…

user1892304
- 617
- 1
- 6
- 11
0
votes
1 answer
Why does the java program freeze on 113882?
I wrote a java program that finds the length of the chain of a number using the collatz sequence.
The collatz sequence goes: if the number is even, divide it by two, if odd, multiply by 3 and add one. The sequence ends when the number reaches 1.…

A Parikh
- 146
- 1
- 1
- 10
0
votes
2 answers
Why does my number only stay at 2 for the Collatz sequence?
I am trying to make a program that calculates when a number will reach zero using the Collatz sequence. Here is my code for that program:
import time
def run(z):
while z != 1:
if isEven(z) == True:
z = z/2
print…

A.J. Uppal
- 19,117
- 6
- 45
- 76
0
votes
2 answers
Getting a runtime error against an online programming judge
So here is my code for the 3n+1 problem on UVa. It runs perfectly on my PC in Eclipse AFAIK, however, I keep getting a runtime error against the UVa judge. Unfortunately, the judge does not tell me what inputs it uses, nor provide any information…

user690421
- 422
- 1
- 5
- 15
0
votes
2 answers
Finding maximum Collatz sequence between 1-1000000
I'm trying to find maximum the Collatz sequence between 1 and 1000000. I wrote the following code below. I guess it is correct but it is extremely slow. Can you give me a few hints to make it faster? Thanks.
#include
#include…

jason
- 6,962
- 36
- 117
- 198
0
votes
1 answer
Collatz sequence of a number
I'm trying to find the Collatz sequence of a number. The following code runs into infinite loop for number 113383.
int collatz(long number) {
int length = 1; //length of the sequence
while (number != 1) {
printf("%ld-", number);
if…

SureshS
- 589
- 8
- 23
0
votes
0 answers
3n+1 runtime error while submitting to UVA
While trying to submit my 3n+1 code, I keep on getting a runtime error although it works perfectly with a huge number of sample input. I've spent lots of time trying to spot the error but I can't find it. Can anybody help?
#include…
0
votes
1 answer
Can someone tell me why I get this output?
Ok, so I have a Collatz sequence length defined by the following code:
private static int count = 0;
private static int collatz(int n){
count++;
if(n > 1){
if(n % 2 == 0){
return collatz(n/2);
…

constant
- 113
- 5
0
votes
0 answers
Collatz sequence?
Im trying to solve the Collatz problem. It's all working except of one my int highest which should compare whether counter of one number is greater than counter of next number seems not to be working. I also tried my highest variable as array but…

Peter F
- 83
- 2
- 3
- 12
0
votes
1 answer
find the max of Collatz sequence from a giving list
i'm new in scheme syntax.
this is the last part of the project i've been working on.
i was able to find the max from a giving Collatz sequence, but this part of the project requires finding the max length from a multiple Collatz sequences lists.
So…

Muhsag
- 155
- 3
- 11
0
votes
1 answer
An extended collatz calculation in java
I'm really confused about how to use the java for each - loop correct. Can anyone help me?
Okay, so here is the deal. I've got an extended Collatz problem that I can't get out of my head. The thing is that I want to list all Collatz iterations for…

Bobby Falck
- 11
- 2