Code: Select all
$ cargo build --release
...
$ time target/release/tatami_rust
Pr40000=479909
T(63405342000)=1000
real 38m13.679s
user 38m13.231s
sys 0m0.049s
Everything is i64 in this code. Might be worth tweaking that...
Code: Select all
$ cargo build --release
...
$ time target/release/tatami_rust
Pr40000=479909
T(63405342000)=1000
real 38m13.679s
user 38m13.231s
sys 0m0.049s
Of course.Most variable don't need to be 64 bits.
It's not clear to me that I have noticed any such thing.As you've noticed for this particular case, 64 bit Pi is much better than 32 bit Pi.
Code: Select all
$ gcc -Wall -O3 -o prune prune.c
prune.c: In function ‘doinit’:
prune.c:16:14: warning: overflow in conversion from ‘long long int’ to ‘long int’ changes value from ‘100000000000’ to ‘1215752192’ [-Woverflow]
#define smax 100000000000l
^~~~~~~~~~~~~
prune.c:49:10: note: in expansion of macro ‘smax’
smin=smax;
^~~~
I compared the version of limited.c available atHeater wrote: ↑Sun Dec 01, 2019 7:53 pm@ejolson,Been there, done that. When every line has changed it's hard to tell what is what. I do wish people would use git if they are going to publish different, ever changing, versions of their code.Try doing a diff between limited.c and prune.c, then comparing that to a diff between the two rusty programs.
Code: Select all
$ diff limited.c wheel.c
1c1
< /* limited.c -- Compute T(s) from Project Euler Problem 256
---
> /* wheel.c -- Compute T(s) from Project Euler Problem 256
5c5,6
< Avoid computing T(s) when s doesn't have enough factors. */
---
> Avoid computing T(s) when s doesn't have enough factors.
> More sensible computation of prime table at startup. */
21c22
< static int Pn,Tisn;
---
> static int Pn,Tisn,in;
35c36
< for(i=0;i<Pn;i++){
---
> for(i=1;i<in;i++){
37a39,42
> for(i=in;P[i]*P[i]<=p;i++){
> if(!(p%P[i])) return 0;
> }
> in=i-1;
44,45c49,50
< P[0]=2; Pn=1;
< for(p=3;Pn<Pnum;p++){
---
> P[0]=2; P[1]=3; Pn=2, in=1;
> for(p=5;Pn<Pnum;p+=2){
Code: Select all
$ diff wheel.c prune.c
1,2c1,2
< /* wheel.c -- Compute T(s) from Project Euler Problem 256
< Written November 9, 2019 by Eric Olson in K&R C for PDP-11
---
> /* prune.c -- Compute T(s) from Project Euler Problem 256
> Written November 28, 2019 by Eric Olson in K&R C for PDP-11
6c6,7
< More sensible computation of prime table at startup. */
---
> More sensible computation of prime table at startup.
> Don't check larger values of s than already found. */
15,17c16,18
< #define smax 100000000l
< #define Pnum 1300
< #define fnum 10
---
> #define smax 100000000000l
> #define Pnum 40000
> #define fnum 20
48c49
< smin=smax+2;
---
> smin=smax;
116c117
< pmax=smax/s+1;
---
> pmax=smin/s+1;
141c142
< int n=200;
---
> int n=1000;
142a144
> printf("Pr(%d)=%ld\n",Pnum,P[Pnum-1]);
Code: Select all
$ OMP_STACKSIZE=4M time ./queue-openmp
Pr(40000)=479909
T(63405342000)=1000
Lc=374
312.93user 0.05system 0:30.23elapsed 1035%CPU (0avgtext+0avgdata 151540maxresident)k
0inputs+0outputs (0major+37706minor)pagefaults 0swaps
Sounds good. As soon as the revisions are done I'll post the code.jcyr wrote: ↑Mon Dec 02, 2019 3:10 amSpot would be very interested in seeing Fido's OMP implementation.ejolson wrote: ↑Mon Dec 02, 2019 12:02 amI now have a program from Fido which runs asCode: Select all
$ OMP_STACKSIZE=4M time ./queue-openmp Pr(40000)=479909 T(63405342000)=1000 Lc=374 312.93user 0.05system 0:30.23elapsed 1035%CPU (0avgtext+0avgdata 151540maxresident)k 0inputs+0outputs (0major+37706minor)pagefaults 0swaps
Code: Select all
$ time target/release/tatami_rust
Pr40000=479909
T(63405342000)=1000
real 5m58.546s
user 5m57.922s
sys 0m0.000s
$ time ./prune
Pr(40000)=479909
T(63405342000)=1000
real 4m48.525s
user 4m48.109s
sys 0m0.016s
Code: Select all
$ time target/release/tatami_rust
Pr40000=479909
T(63405342000)=1000
real 38m22.279s
user 38m21.607s
sys 0m0.061s
$ time ./prune
Pr(40000)=479909
T(63405342000)=1000
real 21m54.700s
user 21m54.538s
sys 0m0.029s
Let's see, for the PCHeater wrote: ↑Mon Dec 02, 2019 10:06 amThis is not looking so good on the Pi:
On the x86-64 PC:On the Pi 3 B:Code: Select all
$ time target/release/tatami_rust Pr40000=479909 T(63405342000)=1000 real 5m58.546s user 5m57.922s sys 0m0.000s $ time ./prune Pr(40000)=479909 T(63405342000)=1000 real 4m48.525s user 4m48.109s sys 0m0.016s
Code: Select all
$ time target/release/tatami_rust Pr40000=479909 T(63405342000)=1000 real 38m22.279s user 38m21.607s sys 0m0.061s Pr(40000)=479909 T(63405342000)=1000 $ time ./prune real 21m54.700s user 21m54.538s sys 0m0.029s
Maybe a dog treat -- if Fido hasn't polished off the lot.
Maybe it is time to make a new chart showing where things are. To do this I would need your latest code for solving T(s)=200. After that, what do you think about making a new T(s)=1000 chart?
I'm all for it.Maybe it is time to make a new chart showing where things are.
I'm on the case. Might take a day or two...To do this I would need your latest code for solving T(s)=200.
Of course.After that, what do you think about making a new T(s)=1000 chart?
Cough.Any program that has been organized and carefully commented for literate clarity would likely lead to a greater understanding of what makes a suitable first programming language for beginners.
Not much point at all really. I have some excuses for wasting my time on it though. I have been learning Rust. In that respect I am a beginner. They claim it is a "systems programming language" that can be used where one might use C or C++. What better way to explore that claim than implementing something like ejolson's C solution in Rust? In my latest iteration of the solution I have been getting to grips with Rust's module system, which turns out to be not entirely obvious. I have also introduced some variable life time annotations, again a new concept and not entirely obvious to use. In short it's a learning exercise.Not sure I understand the point of translating the same few algorithms (which rely on the same underlying principles) to different programming languages? Fun for a while, but quickly gets old...
I'm inclined to agree. Unlike our previous challenges this Tatami thing is not very accessible for mere mortals. Not me anyway.The Tatami problem is not a programming problem. It's more a mathematics or logic problem. The notion that something complicated can be made easily understood with a few comments, or many for that matter, seems a little far fetched and well beyond the scope of what beginners need. A beginner would focus on the syntax and semantics of a language, not the complexities of combinatorial algorithms.
That is in fact the entire point of this threadUnless of course the only point is accumulating cabbages.
While cabbage is good, it is also true that a bit of mathematics is needed to determine which rooms are impossible to auspiciously tile. Is that mathematics difficult to work out? I don't really know, because I didn't work it out myself. I drew pictures on paper for about an hour until I found a way to tile 6x10 and 8x10 rooms and thought I understood why the same approach didn't work for a 7x10 room. Then I read Dean Hickerson's note linked to in the postjcyr wrote: ↑Tue Dec 03, 2019 4:33 amThe Tatami problem is not a programming problem. It's more a mathematics or logic problem. The notion that something complicated can be made easily understood with a few comments, or many for that matter, seems a little far fetched and well beyond the scope of what beginners need. A beginner should focus on the syntax and semantics of a language, not the complexities of combinatorial algorithms.
Unless of course the only point is accumulating cabbages.
I was looking at the list of suggested programming projects
Fido has been busy trying to get some more cabbages to grow in the snow. This task would appear difficult due to the lack of new tatami-challenge submissions. Fortunately there are no deadlines. In fact, programs which compute really big Fibonacci numbers and programs which find anagrams in the insane British dictionary are also welcome. In all cases, the corresponding charts will be updated, but only in the case of finding rectangles of the same area which do not admit tatami tilings will cabbage be awarded.
Could it be that this 1985 article is the well-spoken start of the liberation-through-computer-literacy movement? I wonder if today Orson has a Pi.Orson Card wrote:The latest fashion in computer theory says that home computers don't have to be programmable anymore. Computer users just want software they can buy and run--they don't want to develop their own programs.
Well, the people who say that are the same people who sneer at BASIC because it's an "unstructured" language--you can do unpretty things with BASIC. You can get a 0 in neatness. What they don't realize is that the computer is supposed to make us free. Like the VCR, which lets us determine our own viewing schedule and even make our own TV programs, the computer is not in my home so that I can have only the programs that some company thinks at least 100,000 people will buy. There are sometimes things that only one person will buy--me. And I, for one, will own a computer that lets me create that program.
Personally I recommend closing Windows with the arrival of winter.
Code: Select all
prune (.c vs .rs)
On the x86-64 PC
----------------
gcc -march=native -mtune=native 4m49s
rustc 4m58s
On the Pi 3B (64 bit)
---------------------
gcc -march=native -mtune=native 21m55s
rustc 26m11s
Sorry, I said the wrong thing above. I meant "arithmetic overflow checking". I fixed it.I thought that was Rust's raison d'être ?
Code: Select all
$ time ./prune
Pr(40000)=479909
T(63405342000)=1000
real 4m43.437s
user 4m43.203s
sys 0m0.016s
$ time target/release/tatami_rust
T(63405342000)=1000
real 4m43.769s
user 4m43.406s
sys 0m0.000s
I've got some good news and some bad news. The good news is that the snow had melted and I'm starting to see what looks like a crop of cabbages outside; the bad news is that code may not earn many cabbages in the runtime category.Heater wrote: ↑Thu Dec 05, 2019 9:59 amYay!Code: Select all
$ time ./prune Pr(40000)=479909 T(63405342000)=1000 real 4m43.437s user 4m43.203s sys 0m0.016s $ time target/release/tatami_rust T(63405342000)=1000 real 4m43.769s user 4m43.406s sys 0m0.000s
Code: Select all
$ time target/release/tatami_rust
T(63405342000)=1000
real 24m46.845s
user 24m46.676s
sys 0m0.026s
$ time ./prune
Pr(40000)=479909
T(63405342000)=1000
real 21m55.181s
user 21m54.967s
sys 0m0.017s
It appears Orson is a science-fiction writer who published the book Ender's Game about the same time as writing that article for Ahoy! magazine. According to Wikipedia he is the only author to win the two top American prizes in science fiction literature consecutive years. Additional information is available at