Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #11531
| From | mhx@iae.nl (Marcel Hendrix) |
|---|---|
| Subject | Re: Google CodeJam? |
| Newsgroups | comp.lang.forth |
| Message-ID | <16121713998435@frunobulax.edu> (permalink) |
| Date | 2012-04-22 18:23 +0200 |
| References | <1kiyc5r.cu8iaa1g5nh99N%awegel@arcor.de> |
| Organization | Wanadoo |
awegel@arcor.de (Alex Wegel) writes Re: Google CodeJam?
[..]
> After 1 hour and 15 minutes, i got this (ugly but working) solution (with the
> sample data coming from the file "alien-sample"):
It took me somewhat longer because I started on the wrong foot (generating
all possible strings :-) and encountered 'performance problems.'
-marcel
-- ---------------------------------
'z' 'a' - 1+ =: CMAXI
#15 =: LMAXI
#5000 =: DMAXI
0 VALUE L
0 VALUE D
0 VALUE N
0 VALUE #matches
CREATE clists LMAXI CMAXI * CHARS ALLOT
CREATE dict LMAXI DMAXI * CHARS ALLOT
: clear-clists ( -- ) clists LMAXI CMAXI * CHARS ERASE ;
: cl-row ( row# -- addr ) CMAXI * CHARS clists + ;
: dict-row ( row# -- addr ) LMAXI * CHARS dict + ;
: char! ( addr char -- ) 'a' - CHARS + 1 SWAP C! ;
: char? ( addr char -- ) 'a' - CHARS + C@ ;
: next-line ( -- c-addr u ) REFILL 0= IF QUIT ENDIF ;
: GET-L,D,N ( -- ) next-line 0 WORD COUNT EVALUATE TO N TO D TO L ;
: create-dictword ( index -- ) next-line SOURCE ROT dict-row PACK DROP SOURCE >IN ! DROP ;
: BUILD-DICT ( -- ) D 0 ?DO I create-dictword LOOP ;
: next-char ( -- char )
SOURCE >IN @ <= IF DROP 0 EXIT ENDIF
( addr) >IN @ + C@ 1 >IN +! ;
: collect-chars ( addr -- )
>R BEGIN next-char DUP ')' <>
WHILE R@ SWAP char!
REPEAT DROP R> DROP ;
: create-clists ( -- )
clear-clists
L 0 ?DO I cl-row next-char DUP '(' = IF DROP collect-chars ELSE char! ENDIF LOOP ;
: cl-test? ( char pos -- TRUE=match ) cl-row SWAP char? ;
: $possible? ( c-addr u -- n ) 0 LOCAL #ok 0 ?DO C@+ I cl-test? +TO #ok LOOP DROP #ok ;
: matches ( -- ) D 0 ?DO I dict-row COUNT $possible? L = IF 1 +TO #matches ENDIF LOOP ;
: one-case ( -- ) next-line create-clists matches ;
: CASES ( -- ) N 0 ?DO CLEAR #matches one-case CR ." Case #" I 1+ 0 .R SPACE #matches . LOOP ;
: MATCH ( -- ) GET-L,D,N BUILD-DICT CASES ;
-- Output -----------------------------------------------
Case #1 1
Case #2 0
Case #3 1
Case #4 6
Case #5 8
Case #6 1
Case #7 8
Case #8 1
Case #9 9
Case #10 0
Back to comp.lang.forth | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Google CodeJam? Ian Osgood <iano@quirkster.com> - 2012-04-11 16:23 -0700
Re: Google CodeJam? Hugh Aguilar <hughaguilar96@yahoo.com> - 2012-04-12 00:43 -0700
Re: Google CodeJam? hughaguilar96@yahoo.com - 2012-04-21 15:13 -0700
Re: Google CodeJam? Bernd Paysan <bernd.paysan@gmx.de> - 2012-04-22 02:19 +0200
Re: Google CodeJam? "WJ" <w_a_x_man@yahoo.com> - 2012-04-22 04:03 +0000
Re: Google CodeJam? Hugh Aguilar <hughaguilar96@yahoo.com> - 2012-04-22 23:08 -0700
Re: Google CodeJam? Hugh Aguilar <hughaguilar96@yahoo.com> - 2012-04-22 23:17 -0700
Re: Google CodeJam? "WJ" <w_a_x_man@yahoo.com> - 2012-04-23 19:27 +0000
Re: Google CodeJam? Hugh Aguilar <hughaguilar96@yahoo.com> - 2012-04-23 22:08 -0700
Re: Google CodeJam? "WJ" <w_a_x_man@yahoo.com> - 2012-04-24 08:30 +0000
Re: Google CodeJam? Hugh Aguilar <hughaguilar96@yahoo.com> - 2012-04-24 23:00 -0700
Re: Google CodeJam? "WJ" <w_a_x_man@yahoo.com> - 2012-04-26 09:19 +0000
Re: Google CodeJam? Hugh Aguilar <hughaguilar96@yahoo.com> - 2012-04-26 03:17 -0700
Re: Google CodeJam? vandys@vsta.org - 2012-04-26 16:45 +0000
Re: Google CodeJam? Paul Rubin <no.email@nospam.invalid> - 2012-04-26 10:47 -0700
Re: Google CodeJam? Paul Rubin <no.email@nospam.invalid> - 2012-04-27 02:26 -0700
Re: Google CodeJam? vandys@vsta.org - 2012-04-27 16:37 +0000
Re: Google CodeJam? Paul Rubin <no.email@nospam.invalid> - 2012-04-27 10:17 -0700
Re: Google CodeJam? vandys@vsta.org - 2012-04-27 18:15 +0000
Re: Google CodeJam? Rugxulo <rugxulo@gmail.com> - 2012-04-26 16:00 -0700
Re: Google CodeJam? awegel@arcor.de (Alex Wegel) - 2012-04-22 12:12 +0200
Re: Google CodeJam? awegel@arcor.de (Alex Wegel) - 2012-04-22 14:11 +0200
Re: Google CodeJam? awegel@arcor.de (Alex Wegel) - 2012-04-22 14:17 +0200
Re: Google CodeJam? awegel@arcor.de (Alex Wegel) - 2012-04-25 14:25 +0200
Re: Google CodeJam? mhx@iae.nl (Marcel Hendrix) - 2012-04-22 18:23 +0200
Re: Google CodeJam? awegel@arcor.de (Alex Wegel) - 2012-04-22 22:24 +0200
Re: Google CodeJam? mhx@iae.nl (Marcel Hendrix) - 2012-04-23 20:59 +0200
Re: Google CodeJam? Paul Rubin <no.email@nospam.invalid> - 2012-04-23 13:56 -0700
Re: Google CodeJam? mhx@iae.nl (Marcel Hendrix) - 2012-04-22 18:29 +0200
Re: Google CodeJam? awegel@arcor.de (Alex Wegel) - 2012-04-22 21:36 +0200
Re: Google CodeJam? Bernd Paysan <bernd.paysan@gmx.de> - 2012-04-22 23:08 +0200
Re: Google CodeJam? Hugh Aguilar <hughaguilar96@yahoo.com> - 2012-04-22 23:06 -0700
Re: Google CodeJam? awegel@arcor.de (Alex Wegel) - 2012-04-23 23:19 +0200
Re: Google CodeJam? Hugh Aguilar <hughaguilar96@yahoo.com> - 2012-04-23 22:35 -0700
Re: Google CodeJam? awegel@arcor.de (Alex Wegel) - 2012-04-25 01:59 +0200
Re: Google CodeJam? Hugh Aguilar <hughaguilar96@yahoo.com> - 2012-04-24 22:16 -0700
Re: Google CodeJam? awegel@arcor.de (Alex Wegel) - 2012-04-25 14:25 +0200
Re: Google CodeJam? Hugh Aguilar <hughaguilar96@yahoo.com> - 2012-04-25 11:58 -0700
Re: Google CodeJam? awegel@arcor.de (Alex Wegel) - 2012-04-26 00:23 +0200
Re: Google CodeJam? Hugh Aguilar <hughaguilar96@yahoo.com> - 2012-04-25 11:58 -0700
Re: Google CodeJam? awegel@arcor.de (Alex Wegel) - 2012-04-26 00:23 +0200
Re: Google CodeJam? Hugh Aguilar <hughaguilar96@yahoo.com> - 2012-04-25 11:58 -0700
Re: Google CodeJam? awegel@arcor.de (Alex Wegel) - 2012-04-26 00:23 +0200
Re: Google CodeJam? Albert van der Horst <albert@spenarnc.xs4all.nl> - 2012-04-26 12:36 +0000
Re: Google CodeJam? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-04-25 13:39 +0000
Re: Google CodeJam? Hugh Aguilar <hughaguilar96@yahoo.com> - 2012-04-25 10:05 -0700
Re: Google CodeJam? anton@mips.complang.tuwien.ac.at (Anton Ertl) - 2012-04-26 16:30 +0000
Re: Google CodeJam? Bernd Paysan <bernd.paysan@gmx.de> - 2012-04-27 15:21 +0200
Re: Google CodeJam? Paul Rubin <no.email@nospam.invalid> - 2012-04-24 00:51 -0700
Re: Google CodeJam? awegel@arcor.de (Alex Wegel) - 2012-04-25 01:59 +0200
Re: Google CodeJam? awegel@arcor.de (Alex Wegel) - 2012-04-25 01:59 +0200
Re: Google CodeJam? awegel@arcor.de (Alex Wegel) - 2012-04-27 14:15 +0200
Re: Google CodeJam? hughaguilar96@yahoo.com - 2012-04-30 23:54 -0700
Re: Google CodeJam? awegel@arcor.de (Alex Wegel) - 2012-05-02 01:44 +0200
Re: Google CodeJam? Hugh Aguilar <hughaguilar96@yahoo.com> - 2012-05-01 20:45 -0700
Re: Google CodeJam? awegel@arcor.de (Alex Wegel) - 2012-05-02 23:38 +0200
Re: Google CodeJam? Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2012-04-24 12:50 +0100
Re: Google CodeJam? Paul Rubin <no.email@nospam.invalid> - 2012-04-24 08:22 -0700
Re: Google CodeJam? mhx@iae.nl (Marcel Hendrix) - 2012-04-24 22:28 +0200
Re: Google CodeJam? Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2012-04-25 09:50 +0100
Re: Google CodeJam? awegel@arcor.de (Alex Wegel) - 2012-04-25 01:59 +0200
Re: Google CodeJam? Gerry Jackson <gerry@jackson9000.fsnet.co.uk> - 2012-04-25 09:49 +0100
Re: Google CodeJam? awegel@arcor.de (Alex Wegel) - 2012-04-27 18:28 +0200
Re: Google CodeJam? Bruno Gauthier <bgauthier@free.fr> - 2012-05-01 17:59 +0200
Re: Google CodeJam? awegel@arcor.de (Alex Wegel) - 2012-05-01 19:12 +0200
Re: Google CodeJam? Bruno Gauthier <bgauthier@free.fr> - 2012-05-01 20:39 +0200
Re: Google CodeJam? mhx@iae.nl - 2012-05-01 16:00 -0700
Re: Google CodeJam? awegel@arcor.de (Alex Wegel) - 2012-05-02 02:29 +0200
Re: Google CodeJam? Paul Rubin <no.email@nospam.invalid> - 2012-05-01 19:18 -0700
Re: Google CodeJam? awegel@arcor.de (Alex Wegel) - 2012-05-02 05:14 +0200
Re: Google CodeJam? awegel@arcor.de (Alex Wegel) - 2012-05-02 01:44 +0200
csiph-web