Discussion about math, puzzles, games and fun. Useful symbols: ÷ × ½ √ ∞ ≠ ≤ ≥ ≈ ⇒ ± ∈ Δ θ ∴ ∑ ∫ π -¹ ² ³ °

You are not logged in.

- Topics: Active | Unanswered

**wintersolstice****Real Member**- Registered: 2009-06-06
- Posts: 123

I've been studying these numbers for some time (though not that much) I am atm only looking by exhaustion techniques aided only by spreadsheet formulae

apart from the trivial number trap of

I only know of two cycles and have so far only tested up to 12!the two cycles are

5365

7034

6056

6736

5785

10474

5493

11565

4451

4537

3394

9925

10426

693

8685

14621

2558

3989

9442

10600

37

1369

4930

3301

1090

8200

6724

5065

6725

5114

2797

10138

1446

2312

673

and

7450

7976

12017

690

8136

7857

9333

9738

10853

2874

6260

7444

7412

5620

3536

2521

1066

4456

5072

7684

12832

1809

405

41

1681

6817

4913

2570

5525

3650

3796

10585

7251

7785

13154

3878

7528

6409

4177

7610

5876

9140

9881

16165

7947

8450

9556

12161

4163

5650

5636

4432

2960

4441

3617

1585

there could be others.

Definition:

Step 1. You take a number and check the parity (state of being odd or even) of its digits,

Step 2a if it has an even number of digits then leave it alone

Step 2b if it has an odd number of digits put a zero at the front (left hand side) btw this won't change the value!

Step 3 now that the number has an even number of digits split it up in to sets of two

Step 4a if any of the sets has a zero as the left digit remove the zero so it becomes single digit number

Step 4b if the left hand digit is non-zero leave it as a two digit number

Step 5 this list of 1 and 2 digit number are "intervals, square the "intervals" and write them dowm

step 6 add the squares together to make a new number

Step 7 go back to Step 1 with this new number.

If the number iterates to 1 it is "Super Happy"

e.g. here are a set of number and there "intervals

123456 - 12,34,56

12345 - 1,23,45

120345 - 12,3,45

123045 - 12,30,45

hopefully that makes sense

apart from the trivial cases: 1 and the powers of 10 I haven't found any yet!

Why did the chicken cross the Mobius Band?

To get to the other ...um...!!!

Offline

**wintersolstice****Real Member**- Registered: 2009-06-06
- Posts: 123

I've just found 4 Super Happy Numbers

1030

1826

3010

2618

and another cycle!

2228

1268

4768

6833

5713

3418

1480

6596

13441

2838

2228

1268

4768

6833

5713

3418

1480

6596

13441

2838

Edit: 608 and 806 are Super happy!

*Last edited by wintersolstice (2012-01-20 10:33:45)*

Why did the chicken cross the Mobius Band?

To get to the other ...um...!!!

Offline

**phrontister****Real Member**- From: The Land of Tomorrow
- Registered: 2009-07-12
- Posts: 4,374

Hi wintersolstice,

I've just found 4 Super Happy Numbers

1030

1826

3010

2618

If I understand the problem correctly, numbers that have an even number of digits (Step 2a) are invalid...which would count those four numbers out.

And if that rule also applies to cycles, that would invalidate the cycles you found (I think).

I found 635 Super Happy Numbers below 10,000,000.

are the first 100 of them.

I haven't looked for any cycles.

*Last edited by phrontister (2012-01-31 00:54:20)*

"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

Offline

**phrontister****Real Member**- From: The Land of Tomorrow
- Registered: 2009-07-12
- Posts: 4,374

Hi wintersolstice,

I couldn't find any cycles if step 2a applies. I forget what number I tested up to, but I think it was 100,000 or so.

However, I found 125 cycles (including your three...2228, 5365 & 7450) for numbers under 10000 if step 2a doesn't apply.

they are.

I used a search depth of 100, but the deepest was 56 for #41.

1233 & 8833 only needed a depth of 1.

I also tried increasing the search depth to 1000, but that didn't find any more cycles.

*Last edited by phrontister (2012-02-01 00:52:23)*

"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

Offline

**wintersolstice****Real Member**- Registered: 2009-06-06
- Posts: 123

You've slightly misunderstood step 2a it doesn't mean "even digits are invalid" I'll reword it

Step 2 if the number has an even number of digits go straight to step 3, otherwise add a "0" at the beginning (so there are an even number of digits) then go to step 3

does that make sense?:D

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

and you've made a massive mistake with cycles! Shuffling them about like this

1,2,3,4,5 and 2,3,4,5,1 and 3,4,5,1,2 etc are not not classed as new cycles:D different order but the same numbers

so your 41 cycle is identical to my second cycle have a look it's the same numbers just shuffled about and 37 is part of my first cycle so thats also been counted

I think you need to filter out duplicates because the same cycle reordered doesn't count as different

btw "super happy numbers" were my own invention:D whether they've been studied I don't know

*Last edited by wintersolstice (2012-02-01 08:59:06)*

Why did the chicken cross the Mobius Band?

To get to the other ...um...!!!

Offline

**phrontister****Real Member**- From: The Land of Tomorrow
- Registered: 2009-07-12
- Posts: 4,374

Hi wintersolstice,

Looks like I've misunderstood a couple of things...I'll check them out and get back to you.

I've found 12 different cycles, with each cycle starting with its lowest number:

Have to go...back later.

*Last edited by phrontister (2012-02-01 12:50:51)*

"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

Offline

**phrontister****Real Member**- From: The Land of Tomorrow
- Registered: 2009-07-12
- Posts: 4,374

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)*

Offline

**wintersolstice****Real Member**- Registered: 2009-06-06
- Posts: 123

phrontister wrote:

Hi wintersolstice

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.

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...!!!

Offline

**phrontister****Real Member**- From: The Land of Tomorrow
- Registered: 2009-07-12
- Posts: 4,374

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)*

Offline

**wintersolstice****Real Member**- Registered: 2009-06-06
- Posts: 123

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...!!!

Offline

**phrontister****Real Member**- From: The Land of Tomorrow
- Registered: 2009-07-12
- Posts: 4,374

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)*

Offline

**phrontister****Real Member**- From: The Land of Tomorrow
- Registered: 2009-07-12
- Posts: 4,374

Hi wintersolstice,

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)*

Offline

**gAr****Member**- Registered: 2011-01-09
- Posts: 3,479

Hi,

I found 24718 such numbers below 10 000 000

Here are the first 10 and last 10:

10

100

103

301

367

608

806

1000

1030

1826

9996183

9996217

9997037

9997637

9998002

9998316

9998361

9998790

9999087

9999737

I used C and gcc.

"Believe nothing, no matter where you read it, or who said it, no matter if I have said it, unless it agrees with your own reason and your own common sense" - Buddha?

"Data! Data! Data!" he cried impatiently. "I can't make bricks without clay."

Offline

**phrontister****Real Member**- From: The Land of Tomorrow
- Registered: 2009-07-12
- Posts: 4,374

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)*

Offline

**gAr****Member**- Registered: 2011-01-09
- Posts: 3,479

Hi phrontister,

Okay, I haven't tried BASIC.

The C program took 42.817 seconds to get the output, but it can be made faster with optimization.

I printed to the terminal and saved it to a file using "redirection"

"Believe nothing, no matter where you read it, or who said it, no matter if I have said it, unless it agrees with your own reason and your own common sense" - Buddha?

"Data! Data! Data!" he cried impatiently. "I can't make bricks without clay."

Offline

**phrontister****Real Member**- From: The Land of Tomorrow
- Registered: 2009-07-12
- Posts: 4,374

Hi gAr,

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.

Offline

**gAr****Member**- Registered: 2011-01-09
- Posts: 3,479

Hi phrontister,

Yeah, sure, here's the code.

```
#include <stdio.h>
int countDigits(long n)
{
int cnt = 0;
while(n)
{
n /= 10;
cnt++;
}
return cnt;
}
int shn(long n)
{
long orig = n, cycle = 50, temp = 0;
int dgtcnt;
while(cycle)
{
dgtcnt = countDigits(n);
while(!(dgtcnt == 0 || dgtcnt == -1))
{
temp += (n%100)*(n%100);
n /= 100;
dgtcnt -= 2;
}
n = temp;
temp = 0;
if (n == orig)
{
return 0;
}
if (n == 1)
{
printf("%ld\t\t%ld\n", orig, 50-cycle);
return 1;
}
cycle--;
}
return 0;
}
int main()
{
long i;
for(i=2;i<10000000;i++)
{
shn(i);
}
return 0;
}
```

If you know one procedural language, you can easily learn another without much effort!

"Believe nothing, no matter where you read it, or who said it, no matter if I have said it, unless it agrees with your own reason and your own common sense" - Buddha?

"Data! Data! Data!" he cried impatiently. "I can't make bricks without clay."

Offline

**phrontister****Real Member**- From: The Land of Tomorrow
- Registered: 2009-07-12
- Posts: 4,374

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!

Offline

**gAr****Member**- Registered: 2011-01-09
- Posts: 3,479

Hi phrontister,

You're welcome. Have a good night.

If you like syntax of BASIC, you may also like python. Start with v2.7

Also, it's a lot easier than C. You need not worry about data types, and has a lot of useful packages.

I use C only when there's a need for speed, when it contains lot of function calls and loops, since python's not a compiled language.

"Data! Data! Data!" he cried impatiently. "I can't make bricks without clay."

Offline

**GrimReaper****Banned**- Registered: 2012-02-08
- Posts: 10

gAr

BASIC is Much better than python python is Kinda Hard to Learn.

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 104,764

Hi;

Not really, python is easy too.

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.**

**Online**

**GrimReaper****Banned**- Registered: 2012-02-08
- Posts: 10

Your Joking of Course!!

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 104,764

No, BASIC is pretty much dead.

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.**

**Online**

**GrimReaper****Banned**- Registered: 2012-02-08
- Posts: 10

Ha Ha Ha Loads of Normal Peopl Use it...Do you av a Problem with that ?

Offline

**bobbym****Administrator**- From: Bumpkinland
- Registered: 2009-04-12
- Posts: 104,764

Hi GiB;

Of course not.

**In mathematics, you don't understand things. You just get used to them.****If it ain't broke, fix it until it is.**

**Online**