Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.forth > #11177 > unrolled thread

Google CodeJam?

Started byIan Osgood <iano@quirkster.com>
First post2012-04-11 16:23 -0700
Last post2012-05-02 01:44 +0200
Articles 11 on this page of 71 — 15 participants

Back to article view | Back to comp.lang.forth


Contents

  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

Page 4 of 4 — ← Prev page 1 2 3 [4]


#11586

Fromawegel@arcor.de (Alex Wegel)
Date2012-04-25 01:59 +0200
Message-ID<1kj2qlu.101gnw41xan160N%awegel@arcor.de>
In reply to#11563
Gerry Jackson <gerry@jackson9000.fsnet.co.uk> wrote:

> Results for the large file - do others agree?

I ran it myself, and checked the output - it was correct (after deleting
the input which had got echoed into the output).

So - you won on program size, memory usage and probably on
clarity/simplicity/straightforwardness.

It took >10 sec utime to process the large example, though ;-)

Cheers,
Alex

[toc] | [prev] | [next] | [standalone]


#11601

FromGerry Jackson <gerry@jackson9000.fsnet.co.uk>
Date2012-04-25 09:49 +0100
Message-ID<jn8dq8$c49$1@dont-email.me>
In reply to#11586
On 25/04/2012 00:59, Alex Wegel wrote:
> Gerry Jackson<gerry@jackson9000.fsnet.co.uk>  wrote:
>
>> Results for the large file - do others agree?
>
> I ran it myself, and checked the output - it was correct (after deleting
> the input which had got echoed into the output).
>
> So - you won on program size, memory usage and probably on
> clarity/simplicity/straightforwardness.
>

Kind of you to say so but the control was a bit too complex for my liking.

> It took>10 sec utime to process the large example, though ;-)
>

Yes it was bound to be much slower as it does no pre-processing of the 
patterns, your approach is much better for efficiency.

Out of interest I coded up a version using regular expressions. While it 
took much less coding time, running it on the large data file took about 
13 times longer on GForthcompared to my previous solution. That's the 
price of generality.

-- 
Gerry

[toc] | [prev] | [next] | [standalone]


#11690

Fromawegel@arcor.de (Alex Wegel)
Date2012-04-27 18:28 +0200
Message-ID<1kj82qn.q3w9xufmwf25N%awegel@arcor.de>
In reply to#11177
Ian Osgood <iano@quirkster.com> wrote:

> Four years, and never a Forth entry. Anyone want to put Forth on the
> scoreboard this year? Registration is open and the qualification round
> is on Friday.
> 
> http://code.google.com/codejam/

I tried another one of the examples for practicing - im still way too
slow. Fortunately, i wouldn't feel like going on a trip to NY anyway ;-)

The example i tried was "all your base..", the logical sequel to the
alien example :-)

http://code.google.com/codejam/contest/189252/dashboard#s=p0

It took me about 1:30 hrs to come up with a fully correct solution
(guess what - it's ugly).

In case someone wants to try too, i don't post my solution or further
discussions (i.e. any spoilers) yet.

Cheers,
Alex

[toc] | [prev] | [next] | [standalone]


#11802

FromBruno Gauthier <bgauthier@free.fr>
Date2012-05-01 17:59 +0200
Message-ID<4fa0086f$0$13198$426a34cc@news.free.fr>
In reply to#11690
Le 27/04/2012 18:28, Alex Wegel a écrit :
> Ian Osgood<iano@quirkster.com>  wrote:
>
>> Four years, and never a Forth entry. Anyone want to put Forth on the
>> scoreboard this year? Registration is open and the qualification round
>> is on Friday.
>>
>> http://code.google.com/codejam/
>
> I tried another one of the examples for practicing - im still way too
> slow. Fortunately, i wouldn't feel like going on a trip to NY anyway ;-)
>
> The example i tried was "all your base..", the logical sequel to the
> alien example :-)
>
> http://code.google.com/codejam/contest/189252/dashboard#s=p0
>
> It took me about 1:30 hrs to come up with a fully correct solution
> (guess what - it's ugly).
>
> In case someone wants to try too, i don't post my solution or further
> discussions (i.e. any spoilers) yet.
>
> Cheers,
> Alex

hi Alex,
sticked with a bug severals days, here my solution.
curious to see your.
Bruno

   \ AllYourBase     bruno gauthier
   decimal
   create in$ maxstring allot create inner1$ maxstring allot
   create inner2$ maxstring allot create out$ maxstring allot
   create tvals 64 allot create Single-Char-I/O-Buffer  0 C,  align
   10 constant NL
   variable ifh variable ofh variable #ib
   0 value T 0 value highestindex 0 value basetested

: Fill-tvals
    '1' tvals c! '0' tvals 1+ c!
    10 2  do '0' i + tvals i + c! loop
    26 0  do 'A' i + tvals i + 10 + c! loop
;
   fill-tvals

: CHECKED ( f -- )  ABORT" File Access Error. " ;


: read-char ( file -- char|f )

         Single-Char-I/O-Buffer 1 ROT READ-FILE CHECKED

         IF  Single-Char-I/O-Buffer C@  ELSE  -1  THEN
;

: next-word->in$ ( -- )
         begin
                 ifh @ read-char
                 NL <>
         while
                 Single-Char-I/O-Buffer c@ dup dup
                 '0' '9' between swap 'a' 'z' between or
                 if in$ C+place
                 else drop
                 then
         repeat
;

: parse-headline ( -- ) next-word->in$ in$ count evaluate to T ;
: open-files ( -- )
         bl word count r/o open-file throw ifh !
         bl word count 2dup file-status nip 0=
         if 2dup delete-file drop
         then r/w create-file throw ofh !
;
: inits ( -- )
         0 to highestindex 0 to basetested
         in$ maxstring erase out$ maxstring erase inner1$ maxstring erase
         inner2$ maxstring erase
         next-word->in$ in$ count 2dup upper inner1$ place
;
: available-chars ( -- )
         inner1$ count 2dup bounds
    do
         2dup i c@ scan drop i = if  i c@ inner2$ c+place then
    loop
         2drop
;
: chars-exchanges ( -- )
         in$ count nip 0
    do
         inner2$ dup 1+ swap
         count in$ count drop i + c@ scan drop swap -
         dup highestindex max to highestindex
         tvals + c@ out$ C+place
    loop
;
: .outputs ( i -- )
         in$ maxstring erase
         cr s" Case #" in$ place
         1+ 0 <# #s #> in$ +place s" : " in$ +place
         <# #s #> in$ +place in$ count type
         crlf$ count in$ +place in$ count ofh @ write-file drop
;

: allyourbase (  -- )
         cls open-files parse-headline
         T 0
   do

         inits available-chars chars-exchanges

         highestindex 1+ 2 max to basetested
         out$ count basetested base-tonum
         i .outputs
   loop
   ofh @ close-file drop
   ifh @ close-file drop
;

   \ allyourbase A-small-practice.IN A-small-practice.OUT
   allyourbase A-large-practice.IN A-large-practice.OUT


[toc] | [prev] | [next] | [standalone]


#11803

Fromawegel@arcor.de (Alex Wegel)
Date2012-05-01 19:12 +0200
Message-ID<1kjfias.1ufinpsn9bnoiN%awegel@arcor.de>
In reply to#11802
Bruno Gauthier <bgauthier@free.fr> wrote:

> Le 27/04/2012 18:28, Alex Wegel a écrit :
> > Ian Osgood<iano@quirkster.com>  wrote:
> >
> >> Four years, and never a Forth entry. Anyone want to put Forth on the
> >> scoreboard this year? Registration is open and the qualification round
> >> is on Friday.
> >>
> >> http://code.google.com/codejam/
> >
> > I tried another one of the examples for practicing - im still way too
> > slow. Fortunately, i wouldn't feel like going on a trip to NY anyway ;-)
> >
> > The example i tried was "all your base..", the logical sequel to the
> > alien example :-)
> >
> > http://code.google.com/codejam/contest/189252/dashboard#s=p0
> >
> > It took me about 1:30 hrs to come up with a fully correct solution
> > (guess what - it's ugly).
> >
> > In case someone wants to try too, i don't post my solution or further
> > discussions (i.e. any spoilers) yet.
> >
> > Cheers,
> > Alex
> 
> hi Alex,
> sticked with a bug severals days, here my solution.
> curious to see your.
> Bruno

As i said, it's another ugly solution - my "philosophy" was to leave
everything out that wasn't really needed for the question. (This way,
there's also less space for bugs to hide.)

I didn't put comments into the code (quel surprise!), but the basic
concept is: The alien digits are already ordered (1,0,2,3,4,5,...), so
it's easy to build a table for translating them. After the table has
been built, the alien number-base is known, and i can feed the
transliterated alien numeral to forth to get the numerical value.

The program uses stdin (run in a pipe), so if your forth doesn't have
that, you just need a replacement for getl, to get a line (e.g. based on
refill).

Here it comes - cheers,
Alex

#! /usr/local/bin/gforth-fast
0 value hi
create d 36 allot
: wipe d 36 erase 0 to hi ;
: +dig d hi + c! 1 hi + to hi ;
: >dig?
  hi begin dup while
    1 - 2dup d + c@ = if nip true exit then
  repeat drop false ;
: twiddle dup >r c@ r@ char+ c@ r@ c! r> char+ c! ;
: pars
  bounds do
    i c@ >dig? if drop else +dig then
  loop d twiddle hi 2 max to hi ;
: dig> dup 9 > if 7 + then [char] 0 + ;
: eval
  2dup pars 2dup bounds do i c@ >dig? drop dig> i c! loop
  hi base ! s>unumber? drop decimal ;
: getl pad dup 64 stdin read-line throw drop ;
: .. ." Case #" 1 .r ." : " 1 ud.r cr ;
: app getl evaluate 0 do getl eval i 1+ .. wipe loop ;
' noop is bootmessage
app bye

[toc] | [prev] | [next] | [standalone]


#11805

FromBruno Gauthier <bgauthier@free.fr>
Date2012-05-01 20:39 +0200
Message-ID<4fa02dd4$0$6139$426a34cc@news.free.fr>
In reply to#11803
Le 01/05/2012 19:12, Alex Wegel a écrit :

>
> As i said, it's another ugly solution - my "philosophy" was to leave
> everything out that wasn't really needed for the question. (This way,
> there's also less space for bugs to hide.)
>
> I didn't put comments into the code (quel surprise!), but the basic
> concept is: The alien digits are already ordered (1,0,2,3,4,5,...), so
> it's easy to build a table for translating them. After the table has
> been built, the alien number-base is known, and i can feed the
> transliterated alien numeral to forth to get the numerical value.

> The program uses stdin (run in a pipe), so if your forth doesn't have
> that, you just need a replacement for getl, to get a line (e.g. based on
> refill).
>
> Here it comes - cheers,
> Alex
>
> #! /usr/local/bin/gforth-fast
> 0 value hi
> create d 36 allot
> : wipe d 36 erase 0 to hi ;
> : +dig d hi + c! 1 hi + to hi ;
> :>dig?
>    hi begin dup while
>      1 - 2dup d + c@ = if nip true exit then
>    repeat drop false ;
> : twiddle dup>r c@ r@ char+ c@ r@ c! r>  char+ c! ;
> : pars
>    bounds do
>      i c@>dig? if drop else +dig then
>    loop d twiddle hi 2 max to hi ;
> : dig>  dup 9>  if 7 + then [char] 0 + ;
> : eval
>    2dup pars 2dup bounds do i c@>dig? drop dig>  i c! loop
>    hi base ! s>unumber? drop decimal ;
> : getl pad dup 64 stdin read-line throw drop ;
> : .. ." Case #" 1 .r ." : " 1 ud.r cr ;
> : app getl evaluate 0 do getl eval i 1+ .. wipe loop ;
> ' noop is bootmessage
> app bye

while have to study it :)
thanks for your post
bruno

[toc] | [prev] | [next] | [standalone]


#11809

Frommhx@iae.nl
Date2012-05-01 16:00 -0700
Message-ID<12594856.946.1335913218889.JavaMail.geo-discussion-forums@vbep19>
In reply to#11803
awe..cor.de (Alex Wegel) writes Re: Google CodeJam?

> As i said, it's another ugly solution - my "philosophy" was to leave
> everything out that wasn't really needed for the question. (This way,
> there's also less space for bugs to hide.)

> I didn't put comments into the code (quel surprise!), but the basic
> concept is: The alien digits are already ordered (1,0,2,3,4,5,...), so
> it's easy to build a table for translating them. After the table has
> been built, the alien number-base is known, and i can feed the
> transliterated alien numeral to forth to get the numerical value.

So why not add the above small explanation and some stack comments 
to your code? I almost suspect that you deliberately deleted them :-)

Just a observation: your program works with iForth when I use the 
standard >NUMBER and REFILL words. The runtime for the large example
is dominated by I/O time: 1 ms without output and 120 ms with writing
of the data to file.

-marcel

[toc] | [prev] | [next] | [standalone]


#11813

Fromawegel@arcor.de (Alex Wegel)
Date2012-05-02 02:29 +0200
Message-ID<1kjg26l.vedef462zqbhN%awegel@arcor.de>
In reply to#11809
<..x.nl> wrote:

> awe..cor.de (Alex Wegel) writes Re: Google CodeJam?
> 
> > As i said, it's another ugly solution - my "philosophy" was to leave
> > everything out that wasn't really needed for the question. (This way,
> > there's also less space for bugs to hide.)
> 
> > I didn't put comments into the code (quel surprise!), but the basic
> > concept is: The alien digits are already ordered (1,0,2,3,4,5,...), so
> > it's easy to build a table for translating them. After the table has
> > been built, the alien number-base is known, and i can feed the
> > transliterated alien numeral to forth to get the numerical value.
> 
> So why not add the above small explanation and some stack comments 
> to your code? I almost suspect that you deliberately deleted them :-)

Actually i think i had 2 of them at some point in time, but that was
about it, and then they went stale. They not so interesting anyway :-)
See:

#! /usr/local/bin/gforth-fast
0 value hi                           \ highest digit-value found so far
create d 36 allot            \ digit string containing all alien digits
: wipe ( ) d 36 erase 0 to hi ;                          \ housekeeping
: +dig ( c) d hi + c! 1 hi + to hi ;     \ add newly learned digit to d
: >dig? ( c -- +n true|c false)                    \ lookup alien digit
  hi begin dup while
    1 - 2dup d + c@ = if nip true exit then
  repeat drop false ;
: twiddle ( ca) dup >r c@ r@ char+ c@ r@ c! r> char+ c! ; \ exch 2 bytes
: pars ( ca u)    \ read alien numeral to determine digits & number base
  bounds do
    i c@ >dig? if drop else +dig then
  loop d twiddle hi 2 max to hi ;
: dig> (+n--c) dup 9 > if 7 + then [char] 0 + ;  \ convert 1 dig to text
: eval ( ca u)                            \ evaluate alien number string
  2dup pars 2dup bounds do i c@ >dig? drop dig> i c! loop
  hi base ! s>unumber? drop decimal ;
: getl pad dup 64 stdin read-line throw drop ;
: .. ." Case #" 1 .r ." : " 1 ud.r cr ;
: app getl evaluate 0 do getl eval i 1+ .. wipe loop ;
' noop is bootmessage
app bye

Main thing to remember when reading the source is that in bottom up
programming, the top is down.

> Just a observation: your program works with iForth when I use the 
> standard >NUMBER

Yes, i should have used that one.

> and REFILL words.

Also yes, this time there were no overlong input lines, so this would do
the job too.
My defense is that what i posted is the original - the first working
version, so changing these would be part of some clean-up to come.
(I fathom that using SCAN in >dig? and maybe getting rid of hi as a
value could also get on the todo-list).

> The runtime for the large example
> is dominated by I/O time: 1 ms without output and 120 ms with writing
> of the data to file.

Well - strictly speaking, the 4 minutes(?) granted by the codejam rules
are way too much time, considering some of the attack-dates ;-)

Cheers,
Alex

[toc] | [prev] | [next] | [standalone]


#11814

FromPaul Rubin <no.email@nospam.invalid>
Date2012-05-01 19:18 -0700
Message-ID<7x7gwv4973.fsf@ruckus.brouhaha.com>
In reply to#11803
awegel@arcor.de (Alex Wegel) writes:
> I didn't put comments into the code (quel surprise!), but the basic
> concept is: The alien digits are already ordered (1,0,2,3,4,5,...), so

It was a pretty easy problem (I used Python) and my test output
looks ok to me, but the upload says my answer was incorrect.
Did you get 290762935202 for case #35 and 10^18 for case #36?

Did they really expect people to complete this task in 4 minutes?  I
guess that's doable if absolutely nothing goes wrong.  Make a small
mistake or two and you're sunk.  I didn't time myself but I probably
took between 5 and 10 minutes.

I should try doing some of these in C, which should be more directly
comparable to Forth.  I had trouble attempting using Forth because of
the complexity of doing anything with strings or files.  In languages
like Python, this stuff is too easy because the built-in libraries do
all the work.

[toc] | [prev] | [next] | [standalone]


#11816

Fromawegel@arcor.de (Alex Wegel)
Date2012-05-02 05:14 +0200
Message-ID<1kjga2l.zruhly1b5ytt7N%awegel@arcor.de>
In reply to#11814
Paul Rubin <no.email@nospam.invalid> wrote:

> awegel@arcor.de (Alex Wegel) writes:
> > I didn't put comments into the code (quel surprise!), but the basic
> > concept is: The alien digits are already ordered (1,0,2,3,4,5,...), so
> 
> It was a pretty easy problem (I used Python) and my test output
> looks ok to me, but the upload says my answer was incorrect.
> Did you get 290762935202 for case #35 and 10^18 for case #36?

Case #1: 201
Case #2: 75
Case #3: 11
Case #4: 17419143
Case #5: 1801622
Case #6: 47225
Case #7: 17273
Case #8: 866022
Case #9: 2
Case #10: 42
Case #11: 44317196
Case #12: 511
Case #13: 1
Case #14: 44317196
Case #15: 1023456789
Case #16: 29480883458974409
Case #17: 26432593615
Case #18: 35180798355218
Case #19: 102334506713879
Case #20: 398821148
Case #21: 102345156378290
Case #22: 1002342562744892
Case #23: 674293938766347782
Case #24: 4256386811230819
Case #25: 515096463571317029
Case #26: 3589692911
Case #27: 102034056733893387
Case #28: 187812613000849559
Case #29: 108686242308947
Case #30: 2616885866937
Case #31: 35181782102483
Case #32: 674303048939557361
Case #33: 102345678950
Case #34: 64897047
Case #35: 290762935202
Case #36: 1000000000000000000
Case #37: 575985757797280145
Case #38: 319635304277606399
Case #39: 316555023193359374
Case #40: 921615989741647091
Case #41: 23219822358886405
Case #42: 11986027137890515
Case #43: 153855365171289881
Case #44: 262144
Case #45: 244593359538403
Case #46: 3005211782346
Case #47: 1859030134286095
Case #48: 211967741386084
Case #49: 4256889290508007
Case #50: 23551152047651
Case #51: 23551946083611
Case #52: 102343256672849
Case #53: 23550744836764
Case #54: 14018075135
Case #55: 10234456789102345
Case #56: 29480883458974409
Case #57: 50069
Case #58: 4
Case #59: 1244777988
Case #60: 64881574
Case #61: 3
Case #62: 107
Case #63: 398819
Case #64: 1145122416
Case #65: 1342284513
Case #66: 287
Case #67: 12194234
Case #68: 60589237
Case #69: 1177315138
Case #70: 83
Case #71: 115
Case #72: 2430248
Case #73: 5
Case #74: 10843881
Case #75: 53409068
Case #76: 302
Case #77: 431345
Case #78: 29
Case #79: 3
Case #80: 22094
Case #81: 637
Case #82: 4825
Case #83: 1315
Case #84: 64776197
Case #85: 4297977
Case #86: 17194
Case #87: 11
Case #88: 2163798
Case #89: 1802680
Case #90: 1664354412
Case #91: 62874659
Case #92: 290313057
Case #93: 13
Case #94: 427257653
Case #95: 138
Case #96: 893251
Case #97: 301
Case #98: 1
Case #99: 17349
Case #100: 1924398475

> Did they really expect people to complete this task in 4 minutes?  I
> guess that's doable if absolutely nothing goes wrong.  Make a small
> mistake or two and you're sunk.  I didn't time myself but I probably
> took between 5 and 10 minutes.

I would have failed there too (both times), but with re-reading, and
properly understanding the given limits *before* trying with the real
data (i.e. before the 4- or 8-min timer would have started), i would
have had a better chance (because that's what i stumbled over twice:
first buffer size, then number precision).

> I should try doing some of these in C, which should be more directly
> comparable to Forth.  I had trouble attempting using Forth because of
> the complexity of doing anything with strings or files. In languages
> like Python, this stuff is too easy because the built-in libraries do
> all the work.

Well - the first example almost being a regexp was an especially fitting
case for string-heavy languages, but even there, i'd say that forth had
it's strengths, and if it's just by encouraging to not regard the input
as strings, but as something a little bit simpler, in the limits of the
posed question.

Cheers,
Alex

[toc] | [prev] | [next] | [standalone]


#11810

Fromawegel@arcor.de (Alex Wegel)
Date2012-05-02 01:44 +0200
Message-ID<1kjftlb.1ci48xe8k0zd9N%awegel@arcor.de>
In reply to#11802
After adding the following words...

256 constant maxstring
: between 1+ within ;
: C+place ( c saddr) dup >r count dup >r + c! r> 1+ r> c! ;
: upper bounds ?do i c@ toupper i c! loop ;
create crlf$ 1 c, 10 c, align
: cls cr cr cr cr ;
: base-tonum base ! s>unumber? 0= throw decimal ;

...and "0 in$ c!" somewhere before the call to parse-headline (because
allot didn't clear memory, and your inits word is only called later), it
worked:-)

Most of all i like that there's a lot of variety in the style of the
solutions shown in this thread, even though the two CodeJam questions
were of a real simple nature.

Unfortunately, nobody of us could understand the aliens or stop their
attack in time.

Cheers, Alex

[toc] | [prev] | [standalone]


Page 4 of 4 — ← Prev page 1 2 3 [4]

Back to top | Article view | comp.lang.forth


csiph-web