Nп/п : 69 из 100
 От   : Marcel Hendrix                      2:5075/128        29 сен 23 12:56:26
 К    : Marcel Hendrix                                        29 сен 23 22:58:03
 Тема : Re: Simple Forth programs
----------------------------------------------------------------------------------
                                                                                 
@MSGID:
<790b5095-79fe-4012-8fee-e2d1cb33f7a3n@googlegroups.com> fe64ddf5
@REPLY:
<84586256-f364-4dcd-9b34-ef354fcd834dn@googlegroups.com> c337d04d
@REPLYADDR Marcel Hendrix <mhx@iae.nl>
@REPLYTO 2:5075/128 Marcel Hendrix
@CHRS: CP866 2
@RFC: 1 0
@RFC-References:
<55f30e3c-a6fe-428c-a95f-02bacf08c1een@googlegroups.com> <dbfca034-8ca9-4a9b-b563-3fa9da176386n@googlegroups.com>
<51074ba9-ac74-49aa-8f12-28668d28171fn@googlegroups.com> <8f99b90f-7f00-4544-8fa6-d258ee6f4ef2n@googlegroups.com>
<84586256-f364-4dcd-9b34-ef354fcd834dn@googlegroups.com>
@RFC-Message-ID:
<790b5095-79fe-4012-8fee-e2d1cb33f7a3n@googlegroups.com>
@TZUTC: -0700
@PID: G2/1.0
@TID: FIDOGATE-5.12-ge4e8b94
(*
 * LANGUAGE    : ANS Forth with extensions
 * PROJECT     : Forth Environments
 * DESCRIPTION : game
 * CATEGORY    : Google CodeJam
 * AUTHOR      : Marcel Hendrix
 * LAST CHANGE : May 1, 2012, Marcel Hendrix
 *)



NEEDS -miscutil

REVISION -all-your-base "--- ___________________ Version 0.00 ---"

PRIVATES

DOC
(*
Problem

In A.D. 2100, aliens came to Earth. They wrote a message in a cryptic
language, and next to it they wrote a series of symbols. We`ve come
to the conclusion that the symbols indicate a number: the number of
seconds before war begins!

Unfortunately we have no idea what each symbol means. We`ve decided
that each symbol indicates one digit, but we aren`t sure what each
digit means or what base the aliens are using. For example, if they
wrote "ab2ac999", they could have meant "31536000" in base 10
-- exactly one year -- or they could have meant "12314555" in
base 6 -- 398951 seconds, or about four and a half days. We are
sure of three things: the number is positive; like us, the aliens
will never start a number with a zero; and they aren`t using unary
(base 1).

Your job is to determine the minimum possible number of seconds
before war begins.

Input

The first line of input contains a single integer, T. T test cases
follow. Each test case is a string on a line by itself. The line
will contain only characters in the `a`to `z` and `0` to `9`
ranges (with no spaces and no punctuation), representing the
message the aliens left us. The test cases are independent,
and can be in differentbases with the symbols meaning different
things.

Output

For each test case, output a line in the following format: Case #X: V
Where X is the case number (starting from 1) and V is the minimum number
of seconds before war begins.

Limits

1 = T = 100 The answer will never exceed 1018


Small dataset

1 = the length of each line < 10

Large dataset

1 = the length of each line < 61


Input
 3
 11001001
 cats
 zig

Output
 Case #1: 201
 Case #2: 75
 Case #3: 11

*)
ENDDOC

0 VALUE benching
0 VALUE hi
CREATE d #36 CHARS ALLOT

: wipe  ( -- )  d #36 CHARS ERASE  CLEAR hi ;
: +dig  ( -- )  d hi + C! 1 +TO hi ;

: >dig? ( char -- char bool )
hi
BEGIN  DUP
WHILE  1- 2DUP d + C@ = IF  NIP TRUE EXIT  ENDIF
REPEAT DROP FALSE ;

: twiddle ( addr -- ) DUP >R  C@   R@ CHAR+ C@   R@ C!  R> CHAR+ C! ;

: pars ( c-addr u -- )
BOUNDS DO  I C@ >dig? IF  DROP  ELSE  +dig  ENDIF  LOOP
d twiddle  hi 2 MAX TO hi ;

: dig> ( n -- char ) DUP 9 > IF  7 +  ENDIF `0` + ;

: eval ( c-addr u -- d )
2DUP pars 2DUP BOUNDS DO  I C@ >dig? DROP dig> I C!  LOOP
hi BASE !  0. 2SWAP >NUMBER 2DROP  DECIMAL ;

: next-line  ( -- c-addr u )  REFILL 0= IF  QUIT  ENDIF BL WORD COUNT ;
 : .. ( d case -- ) benching IF 3DROP EXIT ENDIF CR ." Case #"
1 .R ." : " 1 UD.R ;
: AYB ( -- )
TIMER-RESET
next-line EVALUATE 0 ?DO  next-line eval I 1+ .. wipe  LOOP
CR .ELAPSED ;

:ABOUTCR ." Try AYB -- followed by the input" ;

0 [IF] ( 120/1 ms w/o output )

AYB
100
11001001
cats
zig
howareyou
gentlemen
allyour
baseare
belongto
us
hahaha
102345678
111111111
z
abcdefghi
tbto4ot
tcu
p59pp5i5a
45iui6i1f
opppaapoa
i2jv7
mggi2i2gn
1xxf3ppxa
wbv9b9bjp
ggydgy
8585885gg
wllwliw4l
vzyvzon2y
x1xfldrdl
drtpzco
i5xfx
qdjj3ajaj
3333
sgkaaggsg
osjoojjjo
sam
ytytswyvs
k11dgzz4
p9bbb
hnhnn11n1
33bb33333
g636nxgbn
1v4gj5
bvbb5bb7b
mnmnmmmmn
0bzqozzop
guuugg
6oo2kk3yj
igsb7rirb
g7e30e0g0
vr0b2
u
nil4n45n4
8rhdd
nnhuunv2h
fzfxnyfx
ddcvvcvvd
0170cc0yk
frr
00unxwjsk
ffuuhf44f
d4dcc4kcz
7j66j6676
rri2
1js11jm1s
8grqgq68m
0hsjv1ggg
d
us7ytusfy
csnnsc
7
u52
d05d5d05d
ptmp
x0g
yveesyvvy
izvvitvtz
127j5s9m
txx2t22x2
jkykjkyjy
22yy2
l
xymymxxex
t88r5dt0k
8sxx6400o
iiixp
mk
bbo22b2bo
i3ffbvffb
mloz5z
39wmzvj
xbvxy9yyx
9oc2g24o
mmtytomtt
e
sus
p2c
aae0qbveq
maqm02qoo
coefo1ojc
cz

[ELSE] ( 120/1 ms w/o output )

AYB
100
11001001
cats
zig
howareyou
gentlemen
allyour
baseare
belongto
us
hahaha
102345678
111111111
z
abcdefghi
1023456789
abcdefghijklmno
pqrstuvwxyz
nowiknowmyabcs
nexttimewontyou
singwithme
wealsowouldhave
acceptednexttime
wontyouplaywithme
theleftmostdigit
isaonethenyoucount
upfromthere
donotforgetthatthe
resultscangetvery
bigsobecareful
goreadthelarge
inputforyearof
codejaminthefinal
fromlastyear
butremember
thecakeisalie
bbabbbbaaaaababbabbababbaabbbabaabbbabbaabaaaaaaaaaaaaaaaaaa
cabcccbcccbacbabbbaacabacaccacbcacaaab
dbdcaacdbccdadccbdbcbaaaaaaaaa
dbdecadeaaaaaaaaaaaaaaaaaa
bbdddaccccfdfffdaedcfdee
bfdfaeedagfeeddaaebfdb
gheafffdbgehdbaaaaaa
gfifidhbeagdgicfcab
baaaaaaaaaaaaaaaaaa
bkiedeikkebaigaieb
fekkehkdfheehdife
bggmimkaekmaahfgb
gfnmibedgfmjmgii
cedmfconbinibegk
noalgldkhgeaaaa
fpqghedfkemkkgp
cmahnhaeppialnk
beophokododmjpb
mecqfaaaaaaaaa
01234456789012345
abcdefghijklmno
soh4zzb
guu
5ccpp5acaiaipa
mnti3i3kik3
66
i4777
7gg2sg2sn
8x8x8xx8xece8cxx
44aaaaa4qqaqsqa4
0k00hh
33338c8y939
1444lmkskl1
0uuu0uu0uxxx0uxux0u0
zsssg
ii5di
jjj5d0j990
ueu
sgk9aggsgss
a8tauu80ttuu
d69h9
hwenwwnjw
ndd0
88
hnhnn11n11
rjjrrrrrjr
7oeq7e7
881j1i
20v4vv24bb7
hgghvhhgwwvh
pijjjth
kj7
o326223ov6
psq12z2q2
ccbwcwwwwbwwwwbbcbbb
eiedjj1ddev
ejegstggwed
ff9f
nnhuunv2h2h4
k333k3k3
uumuumummmmumummmmuu
ag7pa
y
8uonnff
aaa66a6a6aa66aaaaaaaa6aa666a6aa

[THEN]

.ABOUT -all-your-base CR
DEPRIVE

                              (* End of Source *)
--- G2/1.0
 * Origin: usenet.network (2:5075/128)
SEEN-BY: 5001/100 5005/49 5015/255 5019/40 5020/715
848 1042 4441 12000
SEEN-BY: 5030/49 1081 5058/104 5075/128
@PATH: 5075/128 5020/1042 4441



   GoldED+ VK   │                                                 │   09:55:30    
                                                                                
В этой области больше нет сообщений.

Остаться здесь
Перейти к списку сообщений
Перейти к списку эх