Shop OBEX P1 Docs P2 Docs Learn Events
The Collatz Conjecture Is a Simple Problem That Mathematicians Can't Solve - Page 5 — Parallax Forums

The Collatz Conjecture Is a Simple Problem That Mathematicians Can't Solve

12357

Comments

  • Heater.Heater. Posts: 21,230
    Wait a minute: ...let's say, you have the number 12 which can be devided by 2 to reach an answer of 1.""

    12, 6, 3, 1.5

    Oops.

    Let's start with 16. Or any power of 2.
  • Ron CzapalaRon Czapala Posts: 2,418
    edited 2016-08-16 17:23
    I'm not familiar with node.js but there is something in Windows called Window Script Host which lets you run vbscript or Jscript (MS javascript) and
    also allows you to utilize the FileSystemObject so your script code can create, write, delete, etc files.

    This script file is called Collatz.wsf and when I double click it, it creates a file called C:\Collatz.txt containing a one million line text file
    with the number of steps for each number

    It runs slower than javascript on a web page but lets you create an output file (18.6 MB)

    (Revised to display file size)
    <job id="js">
    <script language="JScript">
      var filespec = "C:\\Collatz.txt"
      var fso = new ActiveXObject("Scripting.FileSystemObject");
      var ts = fso.CreateTextFile(filespec, true);
      var WshShell = WScript.CreateObject("WScript.Shell");
    
      var maxsteps = 0;
      var maxval = 0;
    
      var x = 1;
      var n;
      var steps;
    
    // 20 second popup
      WshShell.Popup("Please wait - Creating " + filespec, 20, "Working...");
    
      while (x < 1000001) {
        steps = 0;
        n = x;
        while (n > 1) {
            if (n & 1)
                n = 3*n + 1;
            else
                n = n / 2;
            steps += 1;
        }
        if (steps > maxsteps) {
          maxsteps = steps;
          maxval = x;
        }
        ts.WriteLine(x + " - " + steps + " steps");
        x += 1;
      }
      var f = fso.GetFile(filespec);
      var sz = f.size;
    
      WScript.Echo("Max: " + maxval + " - " + maxsteps + " steps.", "\nFile size = " + sz + " bytes")
      ts.Close();
    </script>
    </job>
    
  • I believe this is the episode, it was well done so as even layman like me could get a grasp on it. Me to it is all forgotten now.
    I might just buy this episode, to expand the space between the ears one in a while.




    http://www.pbs.org/video/1512280538/
  • Heater.Heater. Posts: 21,230
    @Ron, never heard of Window Script Host. Seems to work.

    @MikeDYur

    Great, i'll check the vid sometime. I'm done for theoretical physics vids for today though.
  • Ron CzapalaRon Czapala Posts: 2,418
    edited 2016-08-16 18:41
    Heater. wrote: »
    @Ron, never heard of Window Script Host. Seems to work.
    .

    You may have heard of PowerShell but I really haven't used it much.

    Here are some useful links regarding MS scripting tools, etc

    https://technet.microsoft.com/en-us/scriptcenter/bb410849.aspx

    https://blogs.technet.microsoft.com/heyscriptingguy/

    https://technet.microsoft.com/en-us/scriptcenter/dd823314

    https://msdn.microsoft.com/library/98591fh7.aspx

    Also: Scripting for HTML Applications (HTAs)
    https://technet.microsoft.com/en-us/scriptcenter/dd742317.aspx

    I have .hta files that create an instance of InternetExplorer, browse to web pages, parse the Document Object Model (DOM), web-scrape data from the page and move between pages.
    Of course you have to study the HTML source to know what document objects you need to use - it can get tricky if the developers change their HTML alot...

    In particular I have one that goes to the TV Guide web site/TV listings page and grabs and reformats the listing data and advances to the next day to create a seven day guide...

    Here is the one for this week -> http://ronczap.home.insightbb.com/TVSched.htm - look nothing like the original TY Guide web pages...


  • Heater.Heater. Posts: 21,230
    Thanks for the tips Ron. Might prove useful one day. As it stands I'm not really into the idea of learning any more platform specific things than I have to.

    I made my Parallax Forums web scraping in node.js. No need to fire up a browser. Of course that was just before they changed the forum software and it's been broken ever since :(
  • Ron CzapalaRon Czapala Posts: 2,418
    edited 2016-08-16 19:05
    Heater. wrote: »
    Thanks for the tips Ron. Might prove useful one day. As it stands I'm not really into the idea of learning any more platform specific things than I have to.

    I made my Parallax Forums web scraping in node.js. No need to fire up a browser. Of course that was just before they changed the forum software and it's been broken ever since :(

    I know what you mean about learning new tools, etc :crazy:

    I have wondered about other method/ways to web-scrape - may have to study node.js after all...
  • Heater. wrote: »

    Thanks! Looks Greek to me - learning curve ahead!

  • Heater. wrote: »
    Wait a minute: ...let's say, you have the number 12 which can be devided by 2 to reach an answer of 1.""

    12, 6, 3, 1.5

    Oops.

    Let's start with 16. Or any power of 2.


    Wasn't thinking. :lol:
  • I have both of these installed, haven't a clue what to do with it. If it's something easy I don't want to read a book on the subject. I'm quessing I use it like a DOS window and point to the js file from there.


    Ron, got your first html working, cool. And in only one debug session, typed in from a screenshhot. The second I copied and pasted, went through and done the spacing, easier. Now to figure the js thing out.



    https://nodejs.org/en/js

    https://github.com/nodejs/nodechakracore

    https://github.com/nodejs/node-chakracore/releases
  • Heater.Heater. Posts: 21,230
    I run node programs from the command line with "node myprog.js".

    The command line could be in a DOS box, a cygwin terminal or the terminal built into the Visual Studio Code editor.

    VS Code is highly recommended for working with Javascript. Use the eslint plug-in to pick up sill errors as you type.
  • MikeDYurMikeDYur Posts: 2,176
    edited 2016-08-16 20:41
    Thanks Heater, sounds like I need more stuff, it will be interesting though.
  • 1 412 987 847 : an even 1000 iterations
  • MikeDYurMikeDYur Posts: 2,176
    edited 2016-08-17 00:28
    1 412 987 847 : an even 1000 iterations



    Congratulations Tom,

    That will be a reference for the Propeller. I got sidetracked here. My documentation stated 9600 baud max for the Parallax LCD, my programs from 2013 use 19200, and you through me with the use of FullDuplexSerial to run it, looking back all I used is Serial LCD by Jon Williams and Jeff Martin. Than new code being posted got me sidetracked. I have it running now, going to put it on a separate power supply. This is going to be awesome.

    Mike


    P.S. Also I was setting up a DS1302 time stamp.
  • Tom's code running.
    2048 x 1152 - 707K
  • Another great display idea for standalone Prop projects is one of the small cheap LCD TFT rearview monitors sold on eBay. Some are only $16 and they work great with Chip's TV_Text. You get 14 lines of 40 characters, in color. The interface between your board and the monitor is just two wires, video and ground. Lazy Dave loves that. :)
  • tomcrawfordtomcrawford Posts: 1,126
    edited 2016-08-17 17:24
    Okay, I think this is pretty close to as good as you can do with a propellor. At 80 MHz, it takes about 16-17 seconds to do the first million.

    I use 6 PASM cogs to check values, one PASM cog to issue numbers, and the spin cog to start the others and talk to a Parallax lcd.

    The calculator cogs are idle typically 2-6 uSec (maybe 5%) before the boss cog issues a new value.

    Edit: Sorry, I initially posted the wrong version.
  • Okay, I think this is pretty close to as good as you can do with a propellor. At 80 MHz, it takes about 16-17 seconds to do the first million.

    I use 6 PASM cogs to check values, one PASM cog to issue numbers, and the spin cog to start the others and talk to a Parallax lcd.

    The calculator cogs are idle typically 2-6 uSec (maybe 5%) before the boss cog issues a new value.

    Edit: Sorry, I initially posted the wrong version.

  • Heater.Heater. Posts: 21,230
    What actually are we trying to do here?

    We already know the Collatz conjecture has been checked for huge numbers.

    Our Propeller code does not even come close to what has been done.

    So I guess we are left with showing off programming tricks or creating some kind of benchmark algorithm.

    The latter may be useful in language comparison.



  • MikeDYurMikeDYur Posts: 2,176
    edited 2016-08-17 18:30
    Heater. wrote: »
    What actually are we trying to do here?

    It feels like reel science, or just putting the Propeller through some paces.
    You guy's with your multiple platforms and fancy programming languages.
    :o

    @Tom, I came this close to asking you to explain the screen on your MultiCogLcdOnly.spin,
    I didn't understand your previous post, no need to now with your new version. Glad you gave me a reason to put the prop on a separate power supply, I neglected to last night, and its like been on for a week now.
    This new one looks pretty neat.

    MikeY
    1064 x 340 - 385K
  • Here's something to gnaw on.

    Physicists Maybe, Just Maybe, Confirm the Possible Discovery of 5th Force of Nature

    http://www.universetoday.com/130333/physicists-maybe-just-maybe-confirm-possible-discovery-5th-force-nature/amp
  • tomcrawfordtomcrawford Posts: 1,126
    edited 2016-08-17 20:08
    Heater. wrote: »
    What actually are we trying to do here?

    We already know the Collatz conjecture has been checked for huge numbers.

    Our Propeller code does not even come close to what has been done.

    You are absolutely correct, of course.

    It amuses me to try to get the propellor to go as fast as I can.
    And I flatter myself that the code I posted may someday be looked at by someone as an example of PASM code.
    Finally, a busy cog is a happy cog.

    tc
  • Heater.Heater. Posts: 21,230
    edited 2016-08-17 20:14
    Yeah. Maybe.

    I won't believe in any such force till it hits me in the face! I mean, give me a break, I haven't gotten my head around electromagnetism and Maxwell's equations yet. Never mind relativity and the gravity wave thing.

    Now, more seriously. The whole idea of the scientific method is to question everything and not accept things until experiment shows them to be so.

    OK. Like the idea.

    But it leads to a problem:

    I can do simple experiments, in the comfort of my own home, that demonstrate Newtonian mechanics. Force = Mass * Acceleration. And such. I have done experiments, in school and university, that demonstrate the wave nature of light. Or the particle nature of light. Depending what you do. I have measured the charge on an electron. Which is a pretty amazing thing to do.

    So far so good.

    BUT, not having a particle accelerator to hand. Or a Large Hadron Collider. Or a Hubble Space Telescope, etc. I have to trust that whoever has such things and made whatever observations is telling me a true story.

    Worse still, I have to trust that the theoretical physics guys are arriving at correct predictions from those observations I cannot make for myself.

    Bottom line is the old expression: "If you cannot measure it, it does not exist".

    If we take that "you" to mean actually you, personally. Then you have to doubt everything anyone says. Until you can prove it for yourself. Which is mostly impossible.
  • Tom, It looks like the LCD overflowed this morning, the first pic is from last night, it achieved that number pretty quick.
    One more day before I give Duane's version the kid test, if I know the nine year old, she will stay busy trying to prove it wrong.
    2048 x 1152 - 444K
    2048 x 1152 - 542K
  • MikeDYurMikeDYur Posts: 2,176
    edited 2016-08-18 14:20
    User Name wrote: »
    Another great display idea for standalone Prop projects is one of the small cheap LCD TFT rearview monitors sold on eBay. Some are only $16 and they work great with Chip's TV_Text. You get 14 lines of 40 characters, in color. The interface between your board and the monitor is just two wires, video and ground. Lazy Dave loves that. :)

    Also there's electronics surplus stores that carry twenty dollar TV displays pulled from ATM machines. Built like a tank, but watch out and don't touch the back while powered. I haven't touched the high voltage circuitry myself, but I imagine it would wake you up. Beware of unscrupulous dealers who try to sell you the rest of the machine.
    2048 x 1152 - 703K
  • MikeDYur wrote: »
    Tom, It looks like the LCD overflowed this morning, the first pic is from last night, it achieved that number pretty quick.
    One more day before I give Duane's version the kid test, if I know the nine year old, she will stay busy trying to prove it wrong.

    Yeah, I stole the binary to decimal display method from full duplex serial. I looked at it to see how it worked and thought "that's neat, how they process negative numbers", never once thinking that applies to you, too, bub. Anyway, when the seed goes from $7FFF_FFFF to $8000_0000 it does what? As far as the display method is concerned, it goes negative. So I will fix it so it doesn't know about negative numbers.

    Nine years old, by the way, might be old enough to understand Duane's spin program. Anyway, have fun with the grandkids.

  • MikeDYurMikeDYur Posts: 2,176
    edited 2016-08-26 19:47
    Thanks Tom, Ahh.. if I show her programmg she will want one of my prop's, thinking. .
    I like this display, and I agree with other people that at least a two line display should have been included on the PPDB at some point. Its easy enough to hook up though, I cut a block of wood and put a slot in at an angle, with some stick on rubber feet, keeps it readable.
    Here's a little program if you want to keep a Propeller on your desk, it seems to work pretty well. I only have one of these so it doesn't get used in a permanent project. Glad to see they are still available.



    https://www.parallax.com/product/27979
  • Here's a pic of that.
    2048 x 1152 - 637K
Sign In or Register to comment.