Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Mathman1@comcast.net

Pages: [1]
1
QB64 Discussion / Re: Collatz Conjecture
« on: July 07, 2020, 01:47:11 pm »
The book is The Secret Life of Numbers : 50 Easy Pieces on How Mathematicians Work and Think by George G. Szpiro, Copyright 2006. George Szpiro had a previous book Kempler's Conjecture as mention on the back cover.

2
QB64 Discussion / Re: Collatz Conjecture
« on: July 07, 2020, 12:05:34 pm »
I am new here. I found this item in the book, The Secret Life of Numbers, Chapter 6 of 50 chapters so there may be more programming examples to come. Please move this to Programs if more appropriate.

3
QB64 Discussion / Collatz Conjecture
« on: July 07, 2020, 11:08:33 am »
I specifically downloaded QB64 to study (play with) Collatz Conjecture (Explained in Wikipedia). QB64 is very flexible and powerful. I wish QB64 had a scrollable output screen but applaud all its other capabilities. You enter the number under the unsigned integer max (18446744073709551615) (somewhat less or you will error immediately) and you will progress through the Collatz procedure. If the output page was scrollable, each operation would be printed on one line. Since it appears the scrollable feature is not available, I print out the operation number, the resulting number, and the resulting number length and some spaces. I do not know how to use the MOD function for the odd/even test so I divide and multiply by 2 and test for equivalency with the original number. If at any time the next result is going to go above the unsigned integer max, I print error and carriage return but still continue. I do 50 operations at a time and when the series finishes, I print end. My series completion number agrees with the Wikipedia example of maximum completion numbers. QB64 is cool!

Code: QB64: [Select]
  1. m~&& = 18446744073709551615 / 3
  2. 1 INPUT "number: ", a~&&: IF a~&& < 1 THEN 1
  3. n = 0: e = 0
  4. 2 PRINT a~&&; LEN(STR$(a~&&)) - 1;: IF e = 50 THEN INPUT s: e = 0
  5. b~&& = a~&& / 2
  6. c~&& = b~&& * 2
  7. IF a~&& >= m~&& AND c~&& <> a~&& THEN PRINT: PRINT "Error"
  8. IF c~&& = a~&& THEN PRINT " E, ";: a~&& = a~&& / 2: ELSE PRINT " O, ";: a~&& = a~&& * 3 + 1
  9. n = n + 1: e = e + 1: IF a~&& <> 1 THEN GOTO 2
  10. PRINT "1  1  END "; n: GOTO 1

Pages: [1]