Re: Super Happy Numbers

Hi wintersolstice

Ok...I think I've got the idea now re the steps.

I've trimmed them down a bit to make it easier for me to read (I hope I haven't changed any rules by doing that!)....

Step 1. If n has an odd number of digits, add leading zero to n.Step 2. Split n into sets ("intervals") of 2-digit numbers.Step 3. Remove any leading zeros from the intervals.Step 4. Square the intervals.Step 5. Sum the squares.Step 6. Repeat from Step 1, using this sum.If the number iterates to 1 it is "Super Happy"

Using an iteration limit of 10, I found 244 Super Happy Numbers below 100,000:-

Increasing the number of iterations to 50 produced no more answers.

btw what method are you using how did you work them out so fast?

I wrote a program in BASIC using the LibertyBASIC software program, testing all numbers below 100,000 against the rules.

Running time to find those 244 numbers was about 90 seconds, which would be pretty slow compared to other languages and programs like Mathematica - none of which I know.

I'm sure a good BASIC programmer would do better (I just potter around), and running it through a compiler would improve the speed too.

Last edited by phrontister (2012-02-01 21:59:43)

"The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do." - Ted Nelson

Re: Super Happy Numbers

I wrote a program in BASIC using the LibertyBASIC software program, testing all numbers below 100,000 against the rules.

Running time to find those 244 numbers was about 90 seconds, which would be pretty slow compared to other languages and programs like Mathematica - none of which I know.

I'm sure a good BASIC programmer would do better (I just potter around), and running it through a compiler would improve the speed too.

well I know absolutly nothing about programming whatsoever:(:( but have longed to learn how to do it. this is just one of hundreds of things I can't do because I don't even know the basics of pogramming:(

can you offer any help? (anything would be appreciated:D)

I had the idea of extending to "n-Hyper Happy numbers" aswell

Why did the chicken cross the Mobius Band? To get to the other ...um...!!!

Re: Super Happy Numbers

Sorry, but I'm really not the one to ask about programming.

I bought a Sharp PC1500A hand-held computer years ago just as a hobby thing. Nothing fancy (no games or apps, except very basic ones)...mainly number manipulation to help me solve tricky (for me) maths puzzles (but not too advanced, because I flunked high school). Its language is BASIC, which I learnt from the user manual and by trial and error...but only ever just enough to get by.

I sometimes still use it, but for my PC I use LibertyBASIC. There is a scaled-down freeware version of it on the net called JustBASIC (google it), which you could download and install if you want. If you do, here's my program for the "Super Happy Numbers" part of your puzzle:

Just highlight my program, copy it and paste it into JustBASIC. Press the blue 'Run' arrow to start, and in the popup window enter the largest number you want to test and the number of iterations (ie, search depth) you want it to perform.

If you want to understand my program you'll have to do some learning. JustBASIC has a tutorial and quite good help files that should get you through...but it will take a while to get there.

For the cycles part of your puzzle I run a separate BASIC program that has just a few small changes from the SHNumbers program, but I want to refine it a bit before posting it. Also, I had to copy/paste the results into Excel to sort it and assess the outcome because I was running short of time, and it was quicker for me to use Excel for that bit than to work out what code to write.

BASIC may or may not be the way to go for you...depending on what it is you want to do. All programming languages have their good and bad points and application strengths and weaknesses (etc, etc), and I can't advise you on that score because I just don't know enough about it. I don't know if there's any info here on MIF that could help you, but if not, there's scads of it on the web.

Btw, what are "n-Hyper Happy numbers"?

Last edited by phrontister (2012-02-03 10:55:42)

"The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do." - Ted Nelson

Re: Super Happy Numbers

well I'll try and find some info on "JustBasic" (never heard of it!LOL) it doesn't matter that you can't help very much:D

btw a "n-Hyper Happy number" is a generalisation I invented just after the "Super Happy numbers" basically you break the number down into intervals of "n" (normal happy numbers n=1, super happy numbers n=2) you would need to add zeros to the beginning of a number (if necessary) to make sure it has a number of digits which is a multiple of "n" the same rules apply:D

Why did the chicken cross the Mobius Band? To get to the other ...um...!!!

Re: Super Happy Numbers

I've made a couple of changes to the program in my last post, and I've updated that post.

1. I added an option to enter an iteration number of your choice. 2. After the program has run you're now given an option to run further tests, which saves having to run a new program each time.

Also, I've finished refining the cycles program, and here it is...

It doesn't filter out duplicates, so that would have to be done by hand (eg, in Excel, which is what I used). I still haven't figured out an automated way for my program to do that, but my initial thought is that it would be very tricky and time-consuming to work out and so I might let that go.

What I did in Excel:- Copied the LibertyBASIC output into Excel in separate columns (had to copy/paste cycles individually).- Sorted each one from low to high with 'MultiSort' (a macro I downloaded from here that sorts multiple columns individually).- Sorted the columns from low to high with Excel's Sort function and manually deleted all duplicates.

That then left me the results shown in post #6.

Last edited by phrontister (2012-02-03 12:26:28)

"The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do." - Ted Nelson

Re: Super Happy Numbers

After I'd said that running the program through a compiler would improve the speed I thought I might as well try it.

So I ran it in QB64 (a freeware BASIC compiler), which blitzed through it in less than an 11th of the original time! That 90 seconds I quoted in post #7 shrank to just 8 seconds.

I'll only be using QB64 for programs where I want to shorten the running time, though, because it doesn't have debugging capabilities...which would make it difficult to iron out programming errors, particularly in complex programs.

A couple of other downsides to QB64 are:- it only prints the result as an image (like some other compilers do) - which makes using the output rather difficult - but I fixed that by printing the result to a text file; and- it is compatible with QBASIC but not LiberyBASIC, which means I had to change some code...but not much.

Last edited by phrontister (2012-02-06 05:13:08)

"The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do." - Ted Nelson

Re: Super Happy Numbers

Hi gAr,

I also found 24718, without the 'trivial' 1...which I think is a SHN because it satisfies all the rules.

My program (LibertyBASIC + QB64) took 299 seconds to find them. How does your C + gcc speed compare? I have no idea about other languages than BASIC regarding their efficiency, capabilities and speed etc.

Before I found QB64 I installed GLBCC, which is a gcc specifically for LibertyBASIC. However, although it seemed to install ok (I followed the installation instructions to the letter) I can't get it to open any of my .bas programs, no matter what I try. Repeating the installation didn't work either...so I gave up on it.

Does your gcc print results as a copyable text file or as an image?

Last edited by phrontister (2012-02-06 23:14:32)

"The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do." - Ted Nelson

Re: Super Happy Numbers

As each solution was found I printed it directly to a file on my desktop, but at the same time I also got it to display on QB64's output screen so that I could check progress.

Would you mind posting your code? I'd be interested to see if your speed gain is due to your better code and/or C vs BASIC. Probably both!

I can't promise to make sense of your C code, but I am hopeful (maybe too optimistically) because someone once gave me some C code for a program I'd written in BASIC, and I was able to adapt and improve my program from that.

My BASIC code is in post #9.

"The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do." - Ted Nelson

Re: Super Happy Numbers

Thanks for that, gAr.

I'll look at that more closely when I get some more time...getting ready for bed soon.

I've always been disappointed with the lack of digit and string manipulation and checking functions in BASIC, and as my main use for writing code is to solve puzzles I've been wondering if I should try learning another language that would suit that purpose better.

Do you think that C would be a good choice for puzzle solving? Or some other language maybe? I don't want to depart too much from what I already know and to have to spend a lot of time in learning something that's very different from BASIC...if I can get away with it!

"The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do." - Ted Nelson