Questions tagged [collatz]

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.

284 questions
2
votes
3 answers

For loop not incrementing or while loop not failing test

I have this section of code that's supposed to find the Collatz sequence of all integers in a given range, defined by user input. The problem is that in the for loop, current_number never gets incremented, or in the inner while loop, current_number…
spartanhooah
  • 183
  • 4
  • 15
2
votes
2 answers

Optimizing longest Collatz chain in Haskell

I've been doing project Euler problems to learn Haskell. I've have some bumps on the way but managed to get to problem 14. The question is, which starting number under 1 000 000 produces the longest Collatz chain (numbers are allowed to go above one…
Luka Horvat
  • 4,283
  • 3
  • 30
  • 48
2
votes
4 answers

Algorithm guidance with 3n+1 Conjecture

Okay, I know this is going to sound like homework; but here goes any way. I am trying to solve this problem using C#. The excerpt from the problem description is shown below: Given an input n, it is possible to determine the number of numbers …
Daniel Lopez
  • 1,728
  • 3
  • 24
  • 40
1
vote
1 answer

Objective c, reverse Collatz, help me debug NSArrays

I am working on a math fair project using the Collatz conjecture, I am wanting to make a reverse graph as you can find here on wikipeadia although I have found that I have messed up somewhere in my code and it doesn't show all of the reverse values…
coopf
  • 59
  • 5
1
vote
1 answer

How to plot points in real time (3x+1 Problem)

I am trying to display the 3x+1 problem (if the number is odd multiply it by 3 and add 1, if it is even divide by 2) live on a line graph. How can I take the outputs that are still generating and plot them on a graph in real time? This is the code I…
1
vote
1 answer

Writing a collatz program, wish to repeat process while n == 1

I am working my way through the Boring python book and have no previous experience with coding at all. I have just worked on a collatz system and I am curious as to how to loop the system indefinitely. Attached is the coding I have so far. def…
Paxxer
  • 21
  • 3
1
vote
0 answers

Struggling to get python turtle to plot a Collatz Conjecture graph

So I wanted to create a graph that plots a Collatz Conjecture for a given number (n), but for some reason my turtle will only travel to the desired position and then not move any further, even though i have clearly specified what rotation and…
Moss
  • 11
  • 2
1
vote
1 answer

Collatz conjecture function in Python3 calling itself when being assigned to a variable

I'm reading the book "Automate the boring stuff" by Al Sweigart to start learning Python (it is free online, so you can check it if you're interested, or you think that it would help solve my problem). And by the end of Chapter 3, you are given an…
1
vote
1 answer

Function to do an operation as much as possible

I'm new to programming and I wanted to see if A is equal to B after applying the following operations toward A.` If A=1, then A=A. If A is even, then A = A/2. If A is odd, then A = A*3+1. output Yes if A is equal to B, No if it's not. I use the…
Maz Diaz
  • 37
  • 5
1
vote
1 answer

Maximizing Efficiency of Collatz Conjecture Program Python

My question is very simple. I wrote this program for pure entertainment. It takes a numerical input and finds the length of every Collatz Sequence up to and including that number. I want to make it faster algorithmically or mathematically (i.e. I…
user14872384
1
vote
1 answer

Python: Collatz sequence -- find a number where the length is greater than the starting number

So here is the question, I'm trying to it solve but I'm just getting more confused. The question wants you to find a starting number where the length of the Collatz sequence it would create is greater than the current one created with the current…
1
vote
1 answer

How to optimize checking thousands of list elements thousands of times?

I'm trying to develop a program that running the first n integers through the "Collatz Conjecture function", denoted as "c(x)", where any odd number is updated to thrice itself plus 1, and any even number is updated to half of itself, and it runs…
Take
  • 13
  • 2
1
vote
3 answers

how to keep a loop going until it reaches a set number

I have a data like this df <- seq(5,10) I pick the first number t <- df[1] I want to do the following (Collatz sequence): if it is odd then multiple by 3 and +1 if the answer is even divide by 2 otherwise multiply by 2 and keep doing this until…
nik
  • 2,500
  • 5
  • 21
  • 48
1
vote
0 answers

longest Collatz sequence 1:n

I am doing some studying on the collatz conjecture. I spend a while researching and came across the following exercise in R. I tried it for a while, but couldn't get it to work. I figured out how to make one collatz sequence, but dit not come any…
1
vote
1 answer

How do i convert an integer to an index in an "if" function?

My first question on this forum and im completely new to programming, so apologies if i do something wrong. So im trying to program something to do a collatz sequense on a number i put in. To do that i have to check if the number i put in is even or…
Daniel .S
  • 35
  • 4