Why isn't [1..5] == [1,2,3,4,5]
?
Why isn't [1..5].to_a == [1,2,3,4,5]
?
How to convert from [1..5]
to [1,2,3,4,5]
?
And since Collatz orbits always decrease at even numbers, this suggests that all Collatz sequences must decrease in the long run. This probabilistic argument is widely known, but no one has been able to extend it to a complete proof of the conjecture.
The 3x+1 problem concerns an iterated function and the question of whether it always reaches 1 when starting from any positive integer. It is also known as the Collatz problem or the hailstone problem. . This leads to the sequence 3, 10, 5, 16, 4, 2, 1, 4, 2, 1, ... which indeed reaches 1.
The Riemann Hypothesis, famously called the holy grail of mathematics, is considered to be one of the toughest problems in all of mathematics.
The Collatz Conjecture is the simplest math problem no one can solve — it is easy enough for almost anyone to understand but notoriously difficult to solve. So what is the Collatz Conjecture and what makes it so difficult?
[1..5]
is an array which only has one element, the range object 1..5
[1..5].to_a
is still [1..5]
(1..5).to_a
is [1,2,3,4,5]
[1..5]
is an array with one element - a range object, all attempts to iterate through it will fail. array can have many kinds of objects in them. In my example above I treat the range as just a range and make any array from it directly.
1.9.3-p125 :008 > (1..5).to_a # Note regular parens.
=> [1, 2, 3, 4, 5]
1.9.3-p125 :009 >
To do more closely what you stated - starting with [1..5] - you could do:
1.9.3-p125 :013 > newarray = []
1.9.3-p125 :014 > [1..5][0].each {|e| newarray << e}
=> 1..5
1.9.3-p125 :015 > newarray
=> [1, 2, 3, 4, 5]
1.9.3-p125 :016 >
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With