User CPFAQMembers ListCalendarToday's PostsSearch





Prova Gratis 30gg l'hosting fooweb
Reply
 
LinkBack Thread Tools Display Modes
 
Old 24-12-07, 02:49 AM
Marcel Hendrix
 
Posts: n/a
Default Ramanujan's Taxi

"Ramanujans bemerkenswerte Taxi Nummer 1729 und schnelle Forth Lösungen."

Alle 893 Lösungen die ein 32-bit Forth findet: eine Secunde (iForth 2.x).

-marcel

== ========
( *
* LANGUAGE : ANS Forth with extensions
* PROJECT : Forth Environments
* DESCRIPTION : Ramanujan Taxi-number puzzle in VD
* CATEGORY : Game
* AUTHOR : Marcel Hendrix
* LAST CHANGE : December 24, 2007, Marcel Hendrix
* )

ANEW -cubes

0 [IF]
Try: FIND-CUBES ok
FORTH> find-cubes
found: 12 1, matching: 10 9, num = 1
found: 16 2, matching: 15 9, num = 2
found: 24 2, matching: 20 18, num = 3
found: 27 10, matching: 24 19, num = 4
found: 32 4, matching: 30 18, num = 5
found: 34 2, matching: 33 15, num = 6
found: 39 17, matching: 36 26, num = 7
found: 48 4, matching: 40 36, num = 8
found: 51 12, matching: 43 38, num = 9
found: 48 6, matching: 45 27, num = 10
0.003 seconds elapsed. ok
[THEN]

\ #1290 find all 893 solutions that fit in 32-bits
#52 VALUE #cubes

: CUBES, #cubes 0 DO I I * I * , LOOP ;

CREATE cubes CUBES,

: cubed ( ix -- u ) CELLS cubes + @ ;

: TEST-CUBES? ( sum i j -- bool )
0 LOCALS| test j i sum |
BEGIN
i #cubes 1- >= j 1 <= OR IF FALSE EXIT ENDIF
i 1+ cubed j 1- cubed + TO test
test sum = IF CR ." found: " i 1+ 4 .R j 1- 4 .R TRUE EXIT ENDIF
test sum > IF -1 +TO j
ELSE 1 +TO i
ENDIF
AGAIN ;

: FIND-CUBES ( -- )
0 LOCALS| num |
TIMER-RESET
#cubes 1 ?DO
I 1 ?DO
J cubed I cubed + J I
TEST-CUBES? IF ." , matching: " J 4 .R I 4 .R
1 +TO num ." , num = " num .
LEAVE
ENDIF
LOOP
LOOP
CR .ELAPSED ;

: ABOUT CR ." Try: FIND-CUBES" ;

ABOUT

(* End of Source *)

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
 
Old 24-12-07, 10:34 PM
Anton Ertl
 
Posts: n/a
Default Re: Ramanujan's Taxi

>: TEST-CUBES? ( sum i j -- bool )
> 0 LOCALS| test j i sum |
> BEGIN
> i #cubes 1- >= j 1 <= OR IF FALSE EXIT ENDIF
> i 1+ cubed j 1- cubed + TO test
> test sum = IF CR ." found: " i 1+ 4 .R j 1- 4 .R TRUE EXIT ENDIF
> test sum > IF -1 +TO j
> ELSE 1 +TO i
> ENDIF
> AGAIN ;
>
>: FIND-CUBES ( -- )
> 0 LOCALS| num |
> TIMER-RESET
> #cubes 1 ?DO
> I 1 ?DO
> J cubed I cubed + J I
> TEST-CUBES? IF ." , matching: " J 4 .R I 4 .R
> 1 +TO num ." , num = " num .
> LEAVE
> ENDIF
> LOOP
> LOOP
> CR .ELAPSED ;


Warum ist das LEAVE hier korrekt?

Es folgt eine aequivalente, etwas verbesserte Loesung, besonders was
TEST-CUBES? betrifft.

Vorteile:
+ Nicht soviele 1+ und 1-.
+ Funktioniert auch fuer etwas groessere Zahlen auf 32-Bit-Systemen
+ Informativere Ausgabe
+ Kein +TO
+ Wenigstens eines von den

Nachteil:
- Funktioniert nur mit Gforth (wegen Locals-Definition innerhalb von BEGIN)


1508 VALUE #cubes

: CUBES, #cubes 0 DO I I * I * , LOOP ;

CREATE cubes CUBES,

: cubed ( ix -- u ) CELLS cubes + @ ;

: .pair ( i j -- )
4 .r ." ^3 +" 4 .r ." ^3" ;

: TEST-CUBES? ( sum i j -- bool )
>r >r { sum } r> 1+ r> 1-

BEGIN { i j }
i #cubes < j 0 > and WHILE
i cubed j cubed + { test }
test sum = IF CR sum 12 u.r ." = " j i .pair TRUE EXIT ENDIF
test sum u> IF
i j 1-
ELSE
i 1+ j
ENDIF
REPEAT
FALSE ;



: FIND-CUBES ( -- )
0 { num }
#cubes 1 ?DO
I 1 ?DO
J cubed I cubed + J I
TEST-CUBES? IF ." = " i j .pair
num 1+ TO num ." , num = " num .
LEAVE
ENDIF
LOOP
LOOP
CR ;

FIND-CUBES

- anton
--
M. Anton Ertl Some things have to be seen to be believed
anton@mips.complang.tuwien.ac.at Most things have to be believed to be seen
http://www.complang.tuwien.ac.at/anton/home.html
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Try the foonews Toolbar!!!
 
Old 25-12-07, 12:25 AM
Marcel Hendrix
 
Posts: n/a
Default Re: Ramanujan's Taxi

anton@mips.complang.tuwien.ac.at (Anton Ertl) writes Re: Ramanujan's Taxi
[..]
>>: FIND-CUBES ( -- )
>> 0 LOCALS| num |
>> TIMER-RESET
>> #cubes 1 ?DO
>> I 1 ?DO
>> J cubed I cubed + J I
>> TEST-CUBES? IF ." , matching: " J 4 .R I 4 .R
>> 1 +TO num ." , num = " num .
>> LEAVE
>> ENDIF
>> LOOP
>> LOOP
>> CR .ELAPSED ;


> Warum ist das LEAVE hier korrekt?


Wenn ich richtig verstanden habe fragt die Spezifikation nach zwei Loesungen,
nicht nach Ramanujan triples, quadruples oder quintuples.

> Es folgt eine aequivalente, etwas verbesserte Loesung, besonders was
> TEST-CUBES? betrifft.


> Vorteile:
> + Nicht soviele 1+ und 1-.
> + Funktioniert auch fuer etwas groessere Zahlen auf 32-Bit-Systemen


Wieso geht das, 1508^3 ist doch negativ (-865678784)?

[..]

-marcel


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
 
Old 25-12-07, 12:19 PM
Marcel Hendrix
 
Posts: n/a
Default Re: Ramanujan's Taxi

mhx@iae.nl (Marcel Hendrix) wrote Re: Ramanujan's Taxi
> anton@mips.complang.tuwien.ac.at (Anton Ertl) writes Re: Ramanujan's Taxi

[..]
>> + Funktioniert auch fuer etwas groessere Zahlen auf 32-Bit-Systemen


> Wieso geht das, 1508^3 ist doch negativ (-865678784)?


Entschuldigung, ich hatte die Aenderung von "<" nach "U<" uebersehen.

Die Suche nach alle Ramanujan Sextuples waere vielleicht eine schoenere
Aufgabe ( http://www.durangobill.com/Ramanujan.html ). Was fuer gForth64?

-marcel

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
 
Old 25-12-07, 01:09 PM
Anton Ertl
 
Posts: n/a
Default Re: Ramanujan's Taxi

mhx@iae.nl (Marcel Hendrix) writes:
>anton@mips.complang.tuwien.ac.at (Anton Ertl) writes Re: Ramanujan's Taxi
>[..]
>>>: FIND-CUBES ( -- )
>>> 0 LOCALS| num |
>>> TIMER-RESET
>>> #cubes 1 ?DO
>>> I 1 ?DO
>>> J cubed I cubed + J I
>>> TEST-CUBES? IF ." , matching: " J 4 .R I 4 .R
>>> 1 +TO num ." , num = " num .
>>> LEAVE
>>> ENDIF
>>> LOOP
>>> LOOP
>>> CR .ELAPSED ;

>
>> Warum ist das LEAVE hier korrekt?

>
>Wenn ich richtig verstanden habe fragt die Spezifikation nach zwei Loesungen,
>nicht nach Ramanujan triples, quadruples oder quintuples.


Wenn ich das Programm richtig verstanden habe, sorgt das TRUE EXIT in
TEST-CUBES? dafuer, dass nicht noch geschaut wird, ob das Paar
vielleicht auch ein Tripel ist. Und das LEAVE sorgt dafuer, dass fuer
ein I nur ein Paar gefunden wird, und ist daher falsch.

Tatsaechlich werden ohne LEAVE deutlich mehr Loesungen gefunden, und
zwar werden mit #CUBES=1290 2310 Loesungen mit 2298 verschiedenen
Summen gefunden (die anderen 12 kommen offenbar von Tripeln
o.ae. her).

Es gibt einen weiteren Fehler: bei einem Tripel werden u.U. (ohne
LEAVE garantiert) zwei Loesungen ausgegeben, nicht eine (was
wahrscheinlich am logischsten ist), und nicht drei (was auch noch mehr
Sinn ergibt als zwei).

>> Es folgt eine aequivalente, etwas verbesserte Loesung, besonders was
>> TEST-CUBES? betrifft.

>
>> Vorteile:
>> + Nicht soviele 1+ und 1-.
>> + Funktioniert auch fuer etwas groessere Zahlen auf 32-Bit-Systemen

>
>Wieso geht das, 1508^3 ist doch negativ (-865678784)?


Unsigned-Zahlen sind nicht negativ.

Allerdings kann man nicht bis 1625 (floor(max-u^(1/3))) gehen, weil
bei dem Programm Summen vorkommen koennen, die groesser sind als
#cubes^3.

Wobei bis 1625 dieselbe Zahl an Loesungen, und allem Anschein nach
auch dieselben Loesungen rauskommen wie auf einem 64-bit-System, nur
die Summe wird bei manchen Loesungen falsch ausgegeben; dass es
funktioniert, ist aber wohl eher Glueckssache.

Ich habe die Gforth-spezifischen Teile wieder portabel gemacht, um
einige Benchmarks laufen zu lassen (Programm siehe unten); auf einem
3GHz Xeon 5160:

Marcel's urspruengliches Programm:

time iforth 'include marcel-ramanujan.fs bye'
real 0m23.363s
user 0m1.112s
sys 0m0.104s

Meine Variante davon (noch mit LEAVE):
time iforth 'include /nfs/unsafe/httpd/ftp/pub/forth/anslocal.fs include ramanujans-taxi.fs bye'
real 0m25.215s
user 0m0.672s
sys 0m0.016s

Offenbar ist pures ANS Forth schneller als die "Extensions":-)

time vfxlin 'include ramanujans-taxi.fs bye'
real 0m0.795s
user 0m0.720s
sys 0m0.076s

time ~/gforth-amd64/gforth-fast ramanujans-taxi.fs -e bye
real 0m4.528s
user 0m4.408s
sys 0m0.012s

In der CPU-Zeit ist iForth diesmal schneller, aber bei der I/O sind
VFX und Gforth ueberlegen.

Als naechstes werde ich wohl einen anderen, besseren Loesungsansatz
implementieren. Hier jedenfalls das portable Programm ohne LEAVE:

1290 VALUE #cubes

: CUBES, #cubes 0 DO I I * I * , LOOP ;

CREATE cubes CUBES,

: cubed ( ix -- u ) CELLS cubes + @ ;

: .pair ( i j -- )
4 .r ." ^3 +" 4 .r ." ^3" ;

: TEST-CUBES? ( sum i j -- bool )
>r 1+ r> 1- { sum i j }

BEGIN
i #cubes < j 0 > and WHILE
i cubed j cubed + ( test )
dup sum = IF
drop CR sum 12 u.r ." = " j i .pair TRUE EXIT ENDIF
sum u> IF
j 1- to j
ELSE
i 1+ to i
ENDIF
REPEAT
FALSE ;



: FIND-CUBES ( -- )
0 { num }
#cubes 1 ?DO
I 1 ?DO
J cubed I cubed + J I
TEST-CUBES? IF ." = " i j .pair
num 1+ TO num ." , num = " num .
ENDIF
LOOP
LOOP
CR ;

FIND-CUBES

- anton
--
M. Anton Ertl Some things have to be seen to be believed
anton@mips.complang.tuwien.ac.at Most things have to be believed to be seen
http://www.complang.tuwien.ac.at/anton/home.html
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
 
Old 25-12-07, 02:45 PM
Anton Ertl
 
Posts: n/a
Default Re: Ramanujan's Taxi

mhx@iae.nl (Marcel Hendrix) writes:
>Die Suche nach alle Ramanujan Sextuples waere vielleicht eine schoenere
>Aufgabe ( http://www.durangobill.com/Ramanujan.html ). Was fuer gForth64?


Durango Bill scheint das ganze gut im Griff zu haben, auch wenn er die
falsche Programmiersprache benutzt:-).

Oje, jetzt habe ich mir das Programm angeschaut. Er benutzt definitiv
die falsche Programmiersprache; noch nicht einmal C99 mit seinen long
longs; stattdessen wurstelt er mit ints und doubles herum. Wenn ich
mir sein MakeCube anschaue, muesste 64-bit Gforth das schon wegblasen.
Allerdings will ich nicht soviel Zeit dafuer verwenden, wie wohl
noetig waere, andere Dinge sind mir wichtiger.

- anton
--
M. Anton Ertl Some things have to be seen to be believed
anton@mips.complang.tuwien.ac.at Most things have to be believed to be seen
http://www.complang.tuwien.ac.at/anton/home.html
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
 
Old 25-12-07, 02:53 PM
Anton Ertl
 
Posts: n/a
Default Re: Ramanujan's Taxi

anton@mips.complang.tuwien.ac.at (Anton Ertl) writes:
>Als naechstes werde ich wohl einen anderen, besseren Loesungsansatz
>implementieren.


Davor habe ich mir noch angeschaut, wie man Tripel ausgeben kann. Das
ist mit einer einfachen Aenderung in TEST-CUBES? moeglich, und dadurch
wird diese Definition auch sauberer (keine EXITs). Laenger braucht's
auch nicht (mit vfxlin). Natuerlich kriegt man fuer jedes Tripel
immer noch auch noch irgendwann ein Paar hinterher, das Problem ist
damit nicht behoben. Beispiel-Ausgabe eines Tripels:

87539319 = 423^3 + 228^3 = 87539319 = 436^3 + 167^3 = 414^3 + 255^3, num = 481

Ja, man koennte die Ausgabe noch schoener machen, aber jetzt wende ich
mich lieber dem besseren Loesungsansatz zu. Hier ist das geaenderte
TEST-CUBES?:

: TEST-CUBES? ( sum i j -- bool )
>r 1+ r> 1- { sum i j } 0

BEGIN
i #cubes < j 0 > and WHILE
i cubed j cubed + ( test )
dup sum = IF
sum 12 u.r ." = " j i .pair ." = " >r 1+ r> endif
sum u> IF
j 1- to j
ELSE
i 1+ to i
ENDIF
REPEAT ;

- anton
--
M. Anton Ertl Some things have to be seen to be believed
anton@mips.complang.tuwien.ac.at Most things have to be believed to be seen
http://www.complang.tuwien.ac.at/anton/home.html
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
 
Old 25-12-07, 04:44 PM
Anton Ertl
 
Posts: n/a
Default Re: Ramanujan's Taxi

anton@mips.complang.tuwien.ac.at (Anton Ertl) writes:
>Als naechstes werde ich wohl einen anderen, besseren Loesungsansatz
>implementieren.


Also, dann, hier ist er: Wir verwenden einfache eine Tabelle aller
Summen I^3+J^3. Wenn eine Summe ein zweites mal vorkommt, haben wir
eine Loesung gefunden. Das folgende Program implementiert die Tabelle
mit Hilfe von Gforth's TABLE, daher ist es nicht portabel, und auch
nicht berauschend schnell, aber bei 1290 als Eingabe immer noch
mehrmals so schnell wie die portable Version von Marcels Programm (auf
Gforth aehnlich schnell wie das andere Programm auf vfxlin, mit ein
bisschen Tricksen sogar noch schneller). Es braucht auch eine
betraechtliche Menge Speicher (bei 1290 als Eingabe 26MB dictionary
auf einem 32-bit System allein fuer die Tabelle mit 827816 Elementen),
aber das koennen wir uns heutzutage ja leisten.

Ein Vorteil des Programms ist, dass es viel offensichtlicher ist, dass
es korrekt ist; und tatsaechlich liefert es bei der Eingabe 1290 als
Ergebnis 2298 Zahlen, waehrend man die doppelten Zahlen bei meiner
Korrektur von Marcels Programm erst nachtreaeglich herausfiltern muss.
Weiters nennt es noch zusaetzliche Loesungen fuer die gleiche Zahl,
ohne sie zu zaehlen. Beispielausgaben:

....
1944219375 = 1167^3 + 708^3 = 1240^3 + 335^3
1958102848 = 1023^3 + 961^3 = 1240^3 + 372^3
Another solution for 1915865217: 1242^3 + 9^3
....
2298 numbers

Zur Geschwindigkeit:

1.51user 0.10system 0:01.63elapsed vfxlin 'include ramanujans-taxi.fs bye'
1.51user 0.06system 0:01.58elapsed gforth-fast -m 1G -e "1290 include rama-taxi.fs cr bye"
1.01user 0.07system 0:01.08elapsed gforth-fast -m 1G -e ": x 20 to hashbits hashdouble ; x 1290 include rama-taxi.fs cr bye"

Verbesserungsmoeglichkeiten:

- Das Programm portabel machen. Eine einfache Variante waere, eine
WORDLIST statt der TABLE zu verwenden, die Zahl in einen String zu
verwandeln (damit die case insensitivity nicht stoert) und das
NEXTNAME CREATE durch ['] CREATE EXECUTE-PARSING zu ersetzen. Da
wuerde sich dann zeigen, welches Forth-System die effizienteste
Dictionary-Implementierung hat. Das mache ich vielleicht.

- Eine eigene Tabellen-Datenstruktur implementieren, die effizienter
ist. Eventuell koennte man die so organisieren, dass eine sortierte
Ausgabe der Zahlen moeglich ist; dann koennte man die ausgegebenen
Loesungen wirklich sinnvoll durchnummerieren, und die Ausgabe von
Tripeln etc. in einer Zeile durchfuehren (statt ueber die Ausgabe
verteilt wie jetzt).

- Speichersparen. Fuer laengere Suchen, wenn einem der Speicher doch
ausgehen wuerde: Blockweises Abarbeiten der Summen: Zuerst alle von
0..10^12, dann von 10^12..8*10^12, dann 8*10^12..27*10^12, ...

Die letzten beiden Schritte mache ich wohl nicht.

- anton

Hier ist das Gforth-Programm:

\ Ramanujan's Taxi

\ print integer solutions to the equation I^3+J^3 = K^3+L^3

\ usage: gforth -m 1G -e "1290 include rama-taxi.fs bye"
\ to print all solutions, where I, J, K, L < 1290

\ for more information read VD 3+4/2007 or
\ http://www.durangobill.com/Ramanujan.html

table constant cube-sums

variable solutions 0 solutions !

: cubed ( n1 -- n2 )
dup dup * * ;

variable tmp

: insert-sum ( n1 n2 -- )
get-current >r
cube-sums set-current tmp 1 cells nextname create
r> set-current
0 , 2, ;

: .sum ( -- )
tmp @ 12 u.r ;

: .pair ( n1 n2 -- )
4 u.r ." ^3 + " 4 u.r ." ^3" ;

: found-solution ( n1 n2 xt -- )
cr execute >r
r@ @ if ( n1 n2 )
." Another solution for " .sum ." : "
else
.sum ." = " r@ cell+ 2@ .pair ." = "
1 solutions +!
endif
.pair
1 r> +! ;

: check-taxi ( n1 n2 -- )
over cubed over cubed + tmp !
tmp 1 cells cube-sums search-wordlist if ( n1 n2 xt )
found-solution
else ( n1 n2 )
insert-sum
endif ;

: rama-taxis ( n -- )
1 u+do
i 1 u+do
i j check-taxi
loop
loop ;

( n ) rama-taxis cr solutions @ . .( numbers)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
 
Old 25-12-07, 05:48 PM
Anton Ertl
 
Posts: n/a
Default Re: Ramanujan's Taxi

anton@mips.complang.tuwien.ac.at (Anton Ertl) writes:
>Verbesserungsmoeglichkeiten:
>
>- Das Programm portabel machen. Eine einfache Variante waere, eine
> WORDLIST statt der TABLE zu verwenden, die Zahl in einen String zu
> verwandeln (damit die case insensitivity nicht stoert) und das
> NEXTNAME CREATE durch ['] CREATE EXECUTE-PARSING zu ersetzen. Da
> wuerde sich dann zeigen, welches Forth-System die effizienteste
> Dictionary-Implementierung hat. Das mache ich vielleicht.


Ok, das war einfach; und es funktioniert auch auf allen
Forth-Systemen, die ich getestet habe, bis zu einem gewissen Punkt.
Nur leider geht bei iForth und VFX geht das Dictionary aus, und ich
weiss bei diesen Systemen nicht, wie ich das beheben kann. Naja, bei
Gforth und BigForth geht's jedenfalls:

2.96user 0.12system 0:03.31elapsed gforth-fast -m 1G -e "include /nfs/a5/anton/gforth/compat/execute-parsing.fs 1290 include standard-taxi.fs cr bye"
2.25user 0.08system 0:02.33elapsed gforth-fast -m 1G -e "1290 include standard-taxi.fs cr bye"
10.60user 0.07system 0:10.68elapsed bigforth -d 100M -e "include /nfs/a5/anton/gforth/compat/execute-parsing.fs 1290 include standard-taxi.fs cr bye"

Wer's selbst ausprobieren will, execute-parsing.fs gibt's in

<http://www.complang.tuwien.ac.at/forth/compat.zip>

- anton

\ Ramanujan's Taxi

\ print integer solutions to the equation I^3+J^3 = K^3+L^3

\ usage: gforth -m 1G -e "1290 include rama-taxi.fs bye"
\ to print all solutions, where I, J, K, L < 1290

\ for more information read VD 3+4/2007 or
\ http://www.durangobill.com/Ramanujan.html

\ The program uses the following words
\ from CORE :
\ Constant Variable ! : dup * ; >r 2@ ['] Create r> , @ ." cr execute r@ IF
\ ELSE cell+ +! THEN over + <# #s #> 2dup 2! i j LOOP .
\ from CORE-EXT :
\ u.r ?DO .(
\ from BLOCK-EXT :
\ \
\ from DOUBLE :
\ 2Variable
\ from FILE :
\ (
\ from SEARCH :
\ wordlist get-current set-current search-wordlist
\ from X:required :
\ include
\ from non-ANS :
\ execute-parsing

\ You can get a standard implementation of EXECUTE-PARSING from
\ <http://www.complang.tuwien.ac.at/forth/compat.zip>

wordlist constant cube-sums

variable solutions 0 solutions !

: cubed ( n1 -- n2 )
dup dup * * ;

variable sum
2variable sum-string

: insert-sum ( n1 n2 -- )
get-current >r
cube-sums set-current sum-string 2@ ['] create execute-parsing
r> set-current
0 , , , ;

: .sum ( -- )
sum @ 12 u.r ;

: .pair ( n1 n2 -- )
4 u.r ." ^3 + " 4 u.r ." ^3" ;

: found-solution ( n1 n2 xt -- )
cr execute >r
r@ @ if ( n1 n2 )
." Another solution for " .sum ." : "
else
.sum ." = " r@ cell+ 2@ .pair ." = "
1 solutions +!
then
.pair
1 r> +! ;

: check-taxi ( n1 n2 -- )
over cubed over cubed + dup sum !
( sum ) 0 <# #s #> 2dup sum-string 2!
cube-sums search-wordlist if ( n1 n2 xt )
found-solution
else ( n1 n2 )
insert-sum
then ;

: rama-taxis ( n -- )
1 ?do
i 1 ?do
i j check-taxi
loop
loop ;

( n ) rama-taxis cr solutions @ . .( numbers)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
 
Old 26-12-07, 12:52 AM
Marcel Hendrix
 
Posts: n/a
Default Re: Ramanujan's Taxi

anton@mips.complang.tuwien.ac.at (Anton Ertl) writes Re: Ramanujan's Taxi
[..]
> Marcel's urspruengliches Programm:


> time iforth 'include marcel-ramanujan.fs bye'
> real 0m23.363s
> user 0m1.112s
> sys 0m0.104s


Wo kommt diese 'real' Zahl her?
Unter Linux x86_64 seh ich nur 1.2, nicht 23.3 Sekunden.
Wahrscheinlich ein positives Effekt von Hanno Schwalm's letzter patch.

Ich werde mir die alternative Loesungen mal in Ruhe ansehen. Gutes
Material!

Ich habe eForth64 versucht, aber die ist hier doch noch gut
zweimal traeger als iForth.

-marcel

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



 RSS Feeds - Archive - Top




All times are GMT +1. The time now is 12:04 AM. Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0 Forum style by ForumMonkeys.com.