|
|
This thread is locked; no one can reply to it.
|
1
2
|
| powers of 2 and 3 |
|
William Labbett
Member #4,486
March 2004
|
Program Output
Quote:
4 2
The above numbers are the powers of 2 and 3 in order. Hopefully you get my The ordering starts 2, 3, 2, 2, 3 By which is meant, there's a power of 2, a power of 3, 2 powers of 2 and then a power of 3. and repeats like that. Then it's 2, 2, 3, 2, 3. Anyway, there's 2 cases where it goes 2, 2, 3, 2, 2, where the 3's are 2187 and 531441 I wonder what power of 3, is the next one in the pattern, 2, 2, 3, 2, 2 ? Just thought, that was interesting and wondering if anyone's got any thoughts on the matter ?
|
|
Dustin Dettmer
Member #3,935
October 2003
|
Sort of reminds me of prime number type patterns. I wonder if this could apply to encryption techniques. |
|
Bruce Perry
Member #270
April 2000
|
Yep, it's interesting They're not in order though. You've got 9 before 8, then 81 before 64, and it happens a number more times. -- |
|
bamccaig
Member #7,536
July 2006
|
A Perl one-liner to fix it. perl -E '$,=" ";while(<>){chomp;push @d,[split];}@d=sort {$a->[0]<=>$b->[0]} @d;say @$_ for(@d)'
-- acc.js | al4anim - Allegro 4 Animation library | Allegro.cc Mockup | Allegro.cc <code> Tag | Allegro 4 Timer Example (w/ Semaphores) | Bambot | Blog | C++ STL Container Flowchart | Castopulence Software | Check Return Values | Is This A Discussion? Flow Chart | Filesystem Hierarchy Standard | Clean Code Talks - Global State and Singletons | How To Use Header Files | GNU/Linux (Debian, Fedora, Gentoo) | rot (rot13, rot47, rotN) |
|
Evert
Member #794
November 2000
|
bamccaig said: A Perl one-liner to fix it.
sort -n. |
|
anonymous
Member #8025
November 2006
|
The first 10 ones should be 3^ 7 = 2187 3^12 = 531441 3^19 = 1162261467 3^24 = 282429536481 3^31 = 617673396283947 3^36 = 150094635296999121 3^43 = 328256967394537077627 3^48 = 79766443076872509863361 3^53 = 19383245667680019896796723 3^60 = 42391158275216203514294433201
|
|
William Labbett
Member #4,486
March 2004
|
I didn't notice I made a mistake. The program took me 5 minutes to write. Here's the code : 1#include <stdlib.h>
2#include <stdio.h>
3
4
5
6
7
8
9int power( int number, int power)
10{
11 int result = 1;
12
13 while(power > 0)
14 {
15 result *= number;
16 --power;
17 }
18
19 return result;
20}
21
22
23int main()
24{
25 int exponent;
26 int i;
27 long int powers_of_three[1000];
28 long int powers_of_two[1000];
29
30 FILE *f = fopen("twos_and_threes.txt", "w");
31
32 for(i = 0; i < 1000; ++i)
33 {
34 powers_of_three[i] = power(3, i);
35 powers_of_two[i] = power(2, i);
36 }
37
38 for(i = 0; i < 1000; ++i)
39 {
40 printf("_ _ _%4d", i);
41 }
42
43 int i2, i3;
44
45 i2 = i3 = 1;
46
47 for(i = 0; i < 10000000; ++i)
48 {
49
50
51 if( powers_of_two[i2] < i )
52 {
53 ++i2;
54 fprintf(f, "%d %d\n", powers_of_two[i2], 2);
55
56 }
57
58 if(powers_of_three[i3] < i )
59 {
60 ++i3;
61 fprintf(f, "%d %d\n", powers_of_three[i3], 3);
62 }
63
64 if(i2 == 999 || i3 == 999)
65 {
66 break;
67 }
68 }
69
70 fclose(f);
71
72 return 0;
73}
Thanks anonymouse for working those out.
|
|
Karadoc ~~
Member #2,749
September 2002
|
that's a weird way to sort them at the end.
----------- |
|
William Labbett
Member #4,486
March 2004
|
Thanks for that Karadoc. Copied and pasted.
|
|
Tobias Dammers
Member #2,604
August 2002
|
Lemme try in Haskell... module Main where main = do let merge (x:xs) (y:ys) = if x < y then x:(merge xs (y:ys)) else y:(merge (x:xs) ys) p2 = map (2 ^) [1..] p3 = map (3 ^) [1..] pm = merge p2 p3 pp = concat $ map ((++ "\n") . show) pm putStrLn pp This one spits out all the powers of two and three, in order, until you cancel out. If you want to limit the output to 100 lines, you'd change one line to: pm = take 100 $ merge p2 p3
--- |
|
William Labbett
Member #4,486
March 2004
|
Quote:
3^ 7 = 2187 So the exponents go 7 12 19 24 31 36 43 48 53 60 seems to be some kind of pattern there : +5 +7 +5 +7 +5 +7 +5 +5 +7 hhhmmmm
|
|
Matthew Leverton
Supreme Loser
January 1999
|
From where do you get your number crunching ideas? |
|
William Labbett
Member #4,486
March 2004
|
Read a book a long time ago called Fermat's Last Theorem, by Simon Singh which I borrowed from someone I know who has a degree in mathematics. I got wondering about an unsolved problem mentioned in the book, which is about whether or not there exist any odd perfect numbers. Over the years I went from one unsolved problem to another. Are there infinitely many Mersenne Primes ? There's loads of unsolved problems. My brain has evolved in a strange way consequently and I think within the context of So it all begins with books, but I think and so ultimately my ideas come from my curiousity for mathematics. It's not something I can honestly recommend since it could be seen that I've wasted a lot of time as I haven't solved any of the problems, but I've learnt a lot along the way. Whether what drives me is a love for mathematics or a desire for fame or a mixture or something else entirely I'm not sure. Hope I've answered your question. I tried my best.
|
|
Matthew Leverton
Supreme Loser
January 1999
|
Yeah, I was basically just wondering if you were actually trying to solve problems or if you just saw patterns and got curious about them. |
|
J-Gamer
Member #12,491
January 2011
|
@William: You may find this to be interesting My website: J-Games |
|
anonymous
Member #8025
November 2006
|
Apparently my earlier results are all wrong. I made a similar mistake like you did and was happy to see that the first two results matched. Such sequences happen but at different powers. See the corresponding exponents of 3 that match to the powers of 2: http://ideone.com/TGkO0 When you see a sequence where two consequtive whole parts are repeated twice, such as 8 5.04743802857 9 5.67836778214 10 6.30929753571 11 6.94022728929 then this is the pattern you are interested in. It means that 35 < 28 < 29 < 36 < 210 < 211 < 37 And since the exponent of 3 grows linearly, and 0.630929753571 * 3 = 1.892789260713 < 2, such pattern will always occur occasionally. (However, a pattern containing more than 2 powers of 2 between powers of 3 can't occur.) |
|
Arthur Kalliokoski
Member #5,540
February 2005
|
I got bored with the current project, so I thought I'd try it. It sorts on the go. 1#include <stdio.h>
2#define MAXRESULTS 120
3
4typedef struct
5{
6 unsigned long long source;
7 unsigned long long power;
8}powerrecord_t;
9
10powerrecord_t results[MAXRESULTS];
11
12int main(void)
13{
14 int i;
15
16 unsigned long long twos = 2;
17 unsigned long long threes = 3;
18
19 unsigned long long limit = 0x04000000000000000;
20
21 int powindex = 0;
22
23 int whichlimit = 0;
24
25 twos *= 2; //prime the pump
26 threes *= 3;
27
28 while(whichlimit == 0)
29 {
30 while(twos < threes)
31 {
32 if(twos > limit)
33 {
34 whichlimit = 1;
35 break;
36 }
37
38 results[powindex].source = 2;
39 results[powindex].power = twos;
40 powindex++;
41 if(powindex == MAXRESULTS)
42 {
43 whichlimit = 2;
44 break;
45 }
46 twos *= 2;
47 }
48
49 while(threes < twos)
50 {
51 if(threes > limit)
52 {
53 whichlimit = 1;
54 break;
55 }
56
57 results[powindex].source = 3;
58 results[powindex].power = threes;
59 powindex++;
60 if(powindex == MAXRESULTS)
61 {
62 whichlimit = 2;
63 break;
64 }
65 threes *= 3;
66 }
67 }
68
69 for(i=0;i<powindex;i++)
70 printf("%llu %llu\n",results[i].source,results[i].power);
71
72 if(whichlimit == 1)
73 printf("Ran into result size limit\n");
74 else if(whichlimit == 2)
75 printf("Ran into array size limit\n");
76 else
77 printf("Internal error\n");
78 return 0;
79}
I'll try it with my bignum library next. I really admire the U.S. Constitution. It's so much better than what we have now. |
|
Oscar Giner
Member #2,207
April 2002
|
Isn't that overcomplicated? Just: output:
2 - 2
3 - 3
4 - 2
8 - 2
9 - 3
16 - 2
27 - 3
32 - 2
64 - 2
81 - 3
128 - 2
243 - 3
256 - 2
512 - 2
729 - 3
1024 - 2
2048 - 2
2187 - 3
4096 - 2
6561 - 3
8192 - 2
16384 - 2
19683 - 3
32768 - 2
59049 - 3
65536 - 2
131072 - 2
177147 - 3
262144 - 2
524288 - 2
531441 - 3
1048576 - 2
1594323 - 3
2097152 - 2
4194304 - 2
4782969 - 3
8388608 - 2
14348907 - 3
16777216 - 2
33554432 - 2
-- |
|
Arthur Kalliokoski
Member #5,540
February 2005
|
I'm doing the bignum version now, the version I posted was more or less a testbed with error checking. [EDIT] I've forgotten how to use these bignums, a week ago I made a little prog for a bet to determine how far away the horizon should be for a man with his eyes 5.5 feet off the ground and it took me like two hours :\ [EDIT2] With an integer size of a relatively svelte 1032 bytes each, it ran into the limit after outputting 15.5MB of text. I put the last 5 lines into the paperclip as a zip file. I suppose I could skip printing the powers and only print which of 2 or 3 was next if anybody wants it. [EDIT4] With only 4GB of memory, I managed to coax the first 133492 results and put it in the paperclip as "t3.txt.zip". It took 4.134 seconds to calculate. I'd get a few thousand more lines if I played with the intsize and maxlimit. [EDIT5] I looked at Oscar's version again and see that he doesn't store the numbers I really admire the U.S. Constitution. It's so much better than what we have now. |
|
anonymous
Member #8025
November 2006
|
Arthur Kalliokoski said: I looked at Oscar's version again and see that he doesn't store the numbers It's simple and sweet, except there is no place to process the numbers (without storing them). For counting powers of two between powers of three, perhaps an inner loop? _2, _3 = 2,3 for i in range(100): c = 0 while _2 < _3: _2 *= 2 c += 1 print "%d powers of two in range 3^%d...3^%d" % (c, i, i+1) _3 *= 3
|
|
William Labbett
Member #4,486
March 2004
|
Sorry guys. Only just got back. The file results.txt.zip is just one long number. Shouldn't there be spaces in there. What's the file all about ?
|
|
Arthur Kalliokoski
Member #5,540
February 2005
|
William Labbett said: The file results.txt.zip is just one long number. Shouldn't there be spaces in there. It has the *nix line feed only '\n', not the DOS '\r\n'. Maybe you have an old Allegro utod.exe? Or view it with a different editor. I really admire the U.S. Constitution. It's so much better than what we have now. |
|
bamccaig
Member #7,536
July 2006
|
Perl one-liner -> LF to CRLF[1][2]: perl "-MFile::Slurp qw/edit_file/" -E "edit_file { s/([^\r])\n/$1\r\n/gm } $ARGV[0], { binmode => q{:raw} }" path\to\file
References
-- acc.js | al4anim - Allegro 4 Animation library | Allegro.cc Mockup | Allegro.cc <code> Tag | Allegro 4 Timer Example (w/ Semaphores) | Bambot | Blog | C++ STL Container Flowchart | Castopulence Software | Check Return Values | Is This A Discussion? Flow Chart | Filesystem Hierarchy Standard | Clean Code Talks - Global State and Singletons | How To Use Header Files | GNU/Linux (Debian, Fedora, Gentoo) | rot (rot13, rot47, rotN) |
|
Tobias Dammers
Member #2,604
August 2002
|
Shell one-liner: $ fromdos path/to/file Or you could do it with a tiny bit of sed, or good old tr: $ mv path/to/file path/to/file~ && tr -d '\r' <path/to/file~ >path/to/file --- |
|
Karadoc ~~
Member #2,749
September 2002
|
I like the perl one-liner things - but mostly because I think it's funny (as in humorous). Maybe I should install perl so that maybe one day I can swing across the room on a rope and miraculously solve problems. ----------- |
|
|
1
2
|