collatz

3n+1 challenge at UVa

泄露秘密 提交于 2020-02-02 12:12:30
问题 I'm having trouble running the "3n+1 Problem" from the "Programming Challenges" book. I've tried every solution in Java I could find on google (even the ones on Stack Overflow), and not a single one works, they all report a "Wrong answer". I also found a working C++ solution, translated it to Java, and same thing: "Wrong answer". I'm using the template from Programming Challenges for Java submissions, and I could swear my algorithm is right, the only possible problem I can think of is in the

Memoization Efficiency Problems (Collatz Hailstone Sequence)

喜你入骨 提交于 2020-01-14 13:13:11
问题 I was particularly interested over the last few days (more from an algorithmic than mathematical perspective) in investigating the length of a given number's Hailstone sequence (Collatz conjecture). Implementing a recursive algorithm is probably the simplest way to calculate the length, but seemed to me like an unnecessary waste of calculation time. Many sequences overlap; take for example 3's Hailstone sequence: 3 -> 10 -> 5 -> 16 -> 8 -> 4 -> 2 -> 1 This has length 7; more specifically, it

Memoization Efficiency Problems (Collatz Hailstone Sequence)

折月煮酒 提交于 2020-01-14 13:11:44
问题 I was particularly interested over the last few days (more from an algorithmic than mathematical perspective) in investigating the length of a given number's Hailstone sequence (Collatz conjecture). Implementing a recursive algorithm is probably the simplest way to calculate the length, but seemed to me like an unnecessary waste of calculation time. Many sequences overlap; take for example 3's Hailstone sequence: 3 -> 10 -> 5 -> 16 -> 8 -> 4 -> 2 -> 1 This has length 7; more specifically, it

Memoization Efficiency Problems (Collatz Hailstone Sequence)

我的梦境 提交于 2020-01-14 13:10:25
问题 I was particularly interested over the last few days (more from an algorithmic than mathematical perspective) in investigating the length of a given number's Hailstone sequence (Collatz conjecture). Implementing a recursive algorithm is probably the simplest way to calculate the length, but seemed to me like an unnecessary waste of calculation time. Many sequences overlap; take for example 3's Hailstone sequence: 3 -> 10 -> 5 -> 16 -> 8 -> 4 -> 2 -> 1 This has length 7; more specifically, it

Memoization Efficiency Problems (Collatz Hailstone Sequence)

无人久伴 提交于 2020-01-14 13:10:10
问题 I was particularly interested over the last few days (more from an algorithmic than mathematical perspective) in investigating the length of a given number's Hailstone sequence (Collatz conjecture). Implementing a recursive algorithm is probably the simplest way to calculate the length, but seemed to me like an unnecessary waste of calculation time. Many sequences overlap; take for example 3's Hailstone sequence: 3 -> 10 -> 5 -> 16 -> 8 -> 4 -> 2 -> 1 This has length 7; more specifically, it

for loop in scheme

我只是一个虾纸丫 提交于 2019-12-24 08:34:26
问题 i'm kinda of confused how i can construct a for loop in scheme. the for-loop should be implemented in Part II. where it takes a list of numbers and insert each element inside the list in Part I to find the length. I was cable to get the first element but i need a for loop or what so ever to get an output like this: '(7 10 5 16 106 37) here is my code : #lang racket ; Part I (define (sequence n) (cond [(= n 1) (list n)] [(even? n) ( cons n(sequence( / n 2)))] [(odd? n) ( cons n(sequence (+(* n

Error “No instance for (Num [t])” in Collatz function

五迷三道 提交于 2019-12-20 02:06:43
问题 I am new to Haskell, and programming in general. I am trying to define a function which generates the sequence of Collatz numbers from n . I have: collatz n = (collatz' n) : 1 where collatz' n = (takeWhile (>1) (collatz'' n)) where collatz'' n = n : collatz'' (collatz''' n) where collatz''' 1 = 1 collatz''' n = if (even n) then (div n 2) else ((3*2)+1) When I run this in GHCi, I get the error: No instance for (Num [t]) arising from the literal `2' at <interactive>:1:7 Possible fix: add an

Uva's 3n+1 problem

南楼画角 提交于 2019-12-17 20:53:20
问题 I'm solving Uva's 3n+1 problem and I don't get why the judge is rejecting my answer. The time limit hasn't been exceeded and the all test cases I've tried have run correctly so far. import java.io.*; public class NewClass{ /** * @param args the command line arguments */ public static void main(String[] args) throws IOException { int maxCounter= 0; int input; int lowerBound; int upperBound; int counter; int numberOfCycles; int maxCycles= 0; int lowerInt; BufferedReader consoleInput = new

find the max of Collatz sequence from a giving list

半腔热情 提交于 2019-12-13 02:46:23
问题 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 for example giving this list : '((1 10) (10 200) (201 210) (900 1000) and the output should be like this : ‘(20 125 89 174) i need to find the maximum length between the number 1 to 10 and then from 10 to 200 ets here is my code : #lang racket ;

Algorithm guidance with 3n+1 Conjecture

霸气de小男生 提交于 2019-12-12 19:17:43
问题 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 printed (including the 1). For a given n this is called the cycle-length of n. In the example above, the cycle length of 22 is 16. For any two numbers i and j you are to determine the maximum cycle length over all numbers between i and j. Question I