Basic computer programming

okeefe4prez

Well-Known Member
Any of you dudes know anything about programming? My kid asked me what the hardest math question ever is and I told him it is the 3n+1 problem (I don't know if this is true, I just saw it in Popular Mechanics). We ran through how to do it (if number is odd, multiply it by 3n+1, if even divide by 2, repeat) and eventually every positive integer hits a 4, 2, 1 infinite loop (3(1)+1 = 4 /2 = 2 /2 = 1). Kid went berserk when he saw the infinite loop and was trying to test all sorts of numbers from supper until he went to bed. I was hoping he'd forget about it by this morning, but nope. Anyway, I was thinking we should write a program that can test numbers so he can feel like he's working on it and stop stressing over it. Seems like it would be a fairly simple program. Does anyone have a recommendation for a simple language to write it in where I can get all the crap needed to do it for free? I know nothing about programming.
 
Any of you dudes know anything about programming? My kid asked me what the hardest math question ever is and I told him it is the 3n+1 problem (I don't know if this is true, I just saw it in Popular Mechanics). We ran through how to do it (if number is odd, multiply it by 3n+1, if even divide by 2, repeat) and eventually every positive integer hits a 4, 2, 1 infinite loop (3(1)+1 = 4 /2 = 2 /2 = 1). Kid went berserk when he saw the infinite loop and was trying to test all sorts of numbers from supper until he went to bed. I was hoping he'd forget about it by this morning, but nope. Anyway, I was thinking we should write a program that can test numbers so he can feel like he's working on it and stop stressing over it. Seems like it would be a fairly simple program. Does anyone have a recommendation for a simple language to write it in where I can get all the crap needed to do it for free? I know nothing about programming.
First, I know nothing about programming outside VB for Excel.

Second, 3n+1 is fascinating.

This is the best video I've ever seen about it, your kid seems way smarter than everyone on this board so I'm assuming it's not above his level.

Also, here's an online calculator that shows the proofs of any number you put into it, but it doesn't give the satisfaction of writing a program. It shouldn't be too hard to write something up, I've seen examples in Excel but VB and macros, etc are ridiculously inefficient.
 
Any of you dudes know anything about programming? My kid asked me what the hardest math question ever is and I told him it is the 3n+1 problem (I don't know if this is true, I just saw it in Popular Mechanics).
Does your son know and do some computer programming??

I would think Visual Basic 6 or Basis for Apple, which ever operating system you use, would be one of the easiest languages for someone to learn and use. VB has been around a very long time so there would be a lot of resources online and perhaps free books and free VB software you could get your hands on.

Fortran is a language meant for mathematical calculations and it is very old but I am not sure it works on modern personal computers. It was more used years ago on mainframe computers which I studied the language on in 1970. WOW, keypunch cards, crazy.

The 3n+1 or Collatz conjecture basically has two functional math/logic tests and parts to do in each iteration. The first test is do determine if the beginning/or resultant numbers which could be saved as variable = n are even or odd and the second test is to always check the resultant numbers to see if they equal 1, which would end the program. So the computer program can first test the starting/resultant number to see if it = 1 and if it does display a message about the program is done. If the starting number is not = 1 then your evaluation routine will need to determine if the starting/resultant number is even or odd.

In VB and many other programming languages there is an INT integer function that you can test with. You could store your current starting/resultant number in variable = n. You could divide n by 2 and test with the INT function if the answer is an integer. So of course an odd whole number integer divided by 2 does not equal an INT so the function returns an answer of False while n = an even integer answer then divided by 2 will have the INT function resolve to TRUE.

If INT = False then perform the 3n+1 calculation to determine your next answer for n

If n = 1 then display message blah blah blah then exit the loop or program else do the below loop

If INT(n/2) = TRUE then do new n value = n/2 else if FALSE then new n value = 3n+1
repeat loop

of course the above type of logic would need more checks etc and also a way to increment the starting integer by 1 each time it needed to test a larger starting integer.

But if a program like this ran from 1 to 1,000,000 and each loop eventually evaluated to n=1 then I suppose you could use the logic that the conjecture is true for all integers to infinity.

I wonder if there are other mathematical principles besides testing and re-testing this conjecture that would tell us that whatever positive integer you start with this set of operations will eventually give a result of the integer 1.
 
First, I know nothing about programming outside VB for Excel.

Second, 3n+1 is fascinating.

This is the best video I've ever seen about it, your kid seems way smarter than everyone on this board so I'm assuming it's not above his level.

Also, here's an online calculator that shows the proofs of any number you put into it, but it doesn't give the satisfaction of writing a program. It shouldn't be too hard to write something up, I've seen examples in Excel but VB and macros, etc are ridiculously inefficient.
Welp, we watched that video and the good news is when the guy said they brute forced it up to whatever quintillion or whatever it was and haven't found an exception my son was satisfied, but then when the dude was talking about log and log log and log log log my boy decided he wants to fucking learn that. Jesus.
 
Does your son know and do some computer programming??

I would think Visual Basic 6 or Basis for Apple, which ever operating system you use, would be one of the easiest languages for someone to learn and use. VB has been around a very long time so there would be a lot of resources online and perhaps free books and free VB software you could get your hands on.

Fortran is a language meant for mathematical calculations and it is very old but I am not sure it works on modern personal computers. It was more used years ago on mainframe computers which I studied the language on in 1970. WOW, keypunch cards, crazy.

The 3n+1 or Collatz conjecture basically has two functional math/logic tests and parts to do in each iteration. The first test is do determine if the beginning/or resultant numbers which could be saved as variable = n are even or odd and the second test is to always check the resultant numbers to see if they equal 1, which would end the program. So the computer program can first test the starting/resultant number to see if it = 1 and if it does display a message about the program is done. If the starting number is not = 1 then your evaluation routine will need to determine if the starting/resultant number is even or odd.

In VB and many other programming languages there is an INT integer function that you can test with. You could store your current starting/resultant number in variable = n. You could divide n by 2 and test with the INT function if the answer is an integer. So of course an odd whole number integer divided by 2 does not equal an INT so the function returns an answer of False while n = an even integer answer then divided by 2 will have the INT function resolve to TRUE.

If INT = False then perform the 3n+1 calculation to determine your next answer for n

If n = 1 then display message blah blah blah then exit the loop or program else do the below loop

If INT(n/2) = TRUE then do new n value = n/2 else if FALSE then new n value = 3n+1
repeat loop

of course the above type of logic would need more checks etc and also a way to increment the starting integer by 1 each time it needed to test a larger starting integer.

But if a program like this ran from 1 to 1,000,000 and each loop eventually evaluated to n=1 then I suppose you could use the logic that the conjecture is true for all integers to infinity.

I wonder if there are other mathematical principles besides testing and re-testing this conjecture that would tell us that whatever positive integer you start with this set of operations will eventually give a result of the integer 1.

Yeah, he doesn't know shit about programming. My wife was an Oracle SQL programmer for a few years after college and when I broached the possibility of writing a program she started shaking and said she never wants to see a line of source code ever again. Hopefully my boy is satisfied that this has been tested well beyond the point where he can test it.

I think the problem with using other mathematical principles is they can get to "near certainty" but because the number set is obviously infinite they can't prove it because an exception that creates a loop or a continually rising set with no sequential fall could theoretically exist. They said in the video Fry linked that a number that creates a loop would likely need at least 168 billion digits.
 
Welp, we watched that video and the good news is when the guy said they brute forced it up to whatever quintillion or whatever it was and haven't found an exception my son was satisfied, but then when the dude was talking about log and log log and log log log my boy decided he wants to fucking learn that. Jesus.

Your son has a lot of curiosity which is good. And you have the internet to help him find out what logarithms are etc etc. And there are a couple of you tube videos explaining logs with a really cute young lady who is nicely dressed and professional but who none the less is nice to watch explain math.
 
If it's purely about math, Wolfram Alpha can help explain tons of algorithms, solve equations, etc. https://www.wolframalpha.com/

Here's a few languages geared towards math specifically as well: https://mathblog.com/10-great-programming-languages-for-mathematics/ I'll admit I don't know much about any of these.

If your son is looking to learn a useful programming language for more than math that he can use later in life, I'd suggest the following:

1. Python - Can be used to build entire apps or simply for scripting. Hugely supported across the public cloud. There are multiple frameworks he can use, but most Python folks I've worked with prefer Django: https://www.djangoproject.com/

2. Javascript - As much as I hate JS, it's huge and isn't going anywhere. There are a ton of different frameworks, so you may have to do some research on what the latest hot one is, but I know VueJS, Angular, and React have been popular.

3. Java - I despise Oracle, but Java is still heavily used.

4. From what I understand, Go is pretty easy to learn, but I haven't used it.

5. C/C++ is great if you're building libraries, embedded apps, or native apps (think MS Word, Chrome, game servers, etc.)

6. C# (you'd think this would be a continuation of C/C++, but you'd be wrong) - This is Microsoft's .NET programming language. Widely used and powerful, if you're in a Windows environment.

Back when I went to school, I had to learn COBOL, SQL, and C++, none of which I use today.

Oh, also good to learn BASH scripting on Linux. You'd be amazed what you can accomplish through some basic scripting skills.

Have you son setup a github account to store his source code, branches, etc. Makes it easy to do version control and track bugs.

Hope this helps.
 
Good news. My son believes that this problem will not be solvable and has given up. He's now infatuated with fusion.
 
Good for your son for thinking of fusion. As of about Dec. 12th, there is a lot of news about fusion for future energy usage. It'll be a while before it's economically usable, but looks promising. Also, it's clean. It'll probably replace electric cars in the not so near future, which looks to be a good thing. There are a number of articles as of Dec. 12th. I just picked one out.

 

Latest posts

Top