Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #34742
| From | Melzzzzz <mel@zzzzz.com> |
|---|---|
| Newsgroups | comp.lang.forth |
| Subject | Re: Epic failure (was Epic Fail) |
| Date | 2014-12-02 06:37 +0100 |
| Organization | albasani.net |
| Message-ID | <20141202063730.63d23f65@maxa-pc> (permalink) |
| References | (1 earlier) <m5d9cn$o3s$1@dont-email.me> <m5dufq$vcm$1@dont-email.me> <547b4ac0$0$15842$e4fe514c@dreader35.news.xs4all.nl> <m5gcc4$66b$1@dont-email.me> <20141202060029.7480750d@maxa-pc> |
On Tue, 2 Dec 2014 06:00:29 +0100
Melzzzzz <mel@zzzzz.com> wrote:
> On Mon, 01 Dec 2014 01:22:40 +0100
> Bernd Paysan <bernd.paysan@gmx.de> wrote:
>
> > Albert van der Horst wrote:
> >
> > > In article <m5dufq$vcm$1@dont-email.me>, WJ <w_a_x_man@yahoo.com>
> > > wrote:
> > >>WJ wrote:
> > >>
> > >>
> > >>I apologize creating a challenge that's far too easy.
> > >>This one is a bit harder.
> > >
> > > Apparently the challenge is to reconstruct a specification
> > > from an undocumented program in a non-Forth language.
> > > That is a far greater challenge then writing a Forth program
> > > would, but I will not waste my time with it.
> >
> > It's just by-word and prints a sorted histogram.
>
> Hm, it is not clear what string-tokenize does, that is, how is string
> tokenized.
>
>
I think following go program closely resembles what OP does and is
clear and readable.
package main
import (
"fmt"
"strings"
"sort"
"unicode"
)
func main() {
s := strings.ToLower(
`How badly did we fail? Well, out of the
Billions and Billions of cellphones which
have ever been produced, not a single one
has been programmed in Forth or uses Forth
as an operating system! 99.99% of them are
programmed in Java? Why? I mean I had a
$15 cell phone. The hardware is probably
more powerful than my old Atari ST. It has
a faster processor and more RAM. There are
only about 5 games for it, and they are all
programmed in Java. Truth be known, these
games are so slow as to be nearly
unplayable. It would be undoable to put
Llamatron on the thing, not because of the
small screen size, but because it just
couldn't use a Java library to push around a
sufficient number of sprites very well. I
know that all of you I.T. people in here are
just going to say buy a more expensive
phone, but that's not my point.`)
words := make(map[string]string)
for _,v := range strings.FieldsFunc(s,func (c rune)bool {
return !unicode.IsLetter(c) && c != '\''
}) {
words[v]+="*"
}
arr := make(Sorted,0)
for k,v := range words {
if len(v) > 1 {
arr = append(arr,F{k,v})
}
}
sort.Sort(arr)
fmt.Print(arr)
}
type F struct { k,v string }
type Sorted []F
func (this Sorted) Len() int {
return len(this)
}
func (this Sorted) Swap(i,j int) {
this[i],this[j] = this[j],this[i]
}
func (this Sorted) Less(i,j int)bool {
rc := len(this[i].v)>len(this[j].v)
if !rc {
if len(this[i].v) == len(this[j].v) {
return this[i].k < this[j].k
}
}
return rc
}
func (this Sorted) String()(rc string){
for i,v := range this {
rc += fmt.Sprintf("%05d %-20s%s\n",i,v.k,v.v)
}
return
}
Back to comp.lang.forth | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: Epic failure (was Epic Fail) "WJ" <w_a_x_man@yahoo.com> - 2014-11-29 20:13 +0000
Re: Epic failure (was Epic Fail) C G Montgomery <cgm@physics.utoledo.edu> - 2014-11-29 17:15 -0500
Re: Epic failure (was Epic Fail) Pablo Hugo Reda <pabloreda@gmail.com> - 2014-11-29 14:20 -0800
Re: Epic failure awegel@arcor.de (Alexander Wegel) - 2014-11-29 23:35 +0100
Re: Epic failure (was Epic Fail) Bernd Paysan <bernd.paysan@gmx.de> - 2014-11-30 00:31 +0100
Re: Epic failure (was Epic Fail) Julian Fondren <julian.fondren@gmail.com> - 2014-11-29 17:41 -0800
Re: Epic failure (was Epic Fail) mhx@iae.nl - 2014-11-30 00:04 -0800
Re: Epic failure (was Epic Fail) mhx@iae.nl - 2014-11-30 00:09 -0800
Re: Epic failure (was Epic Fail) Bernd Paysan <bernd.paysan@gmx.de> - 2014-11-30 17:22 +0100
Re: Epic failure (was Epic Fail) "WJ" <w_a_x_man@yahoo.com> - 2014-11-30 02:13 +0000
Re: Epic failure (was Epic Fail) Julian Fondren <julian.fondren@gmail.com> - 2014-11-29 18:55 -0800
Re: Epic failure (was Epic Fail) albert@spenarnc.xs4all.nl (Albert van der Horst) - 2014-11-30 16:50 +0000
Re: Epic failure (was Epic Fail) Bernd Paysan <bernd.paysan@gmx.de> - 2014-12-01 01:22 +0100
Re: Epic failure (was Epic Fail) Melzzzzz <mel@zzzzz.com> - 2014-12-02 06:00 +0100
Re: Epic failure (was Epic Fail) Melzzzzz <mel@zzzzz.com> - 2014-12-02 06:37 +0100
Re: Epic failure (was Epic Fail) albert@spenarnc.xs4all.nl (Albert van der Horst) - 2014-12-02 12:28 +0000
Re: Epic failure Paul Rubin <no.email@nospam.invalid> - 2014-12-02 18:03 -0800
Re: Epic failure (was Epic Fail) the_gavino_himself <visphatesjava@gmail.com> - 2014-12-05 10:10 -0800
Re: Epic failure (was Epic Fail) rickman <gnuarm@gmail.com> - 2014-12-05 16:23 -0500
Re: Epic failure (was Epic Fail) Jason Damisch <jasondamisch@yahoo.com> - 2014-12-05 13:46 -0800
Re: Epic failure (was Epic Fail) "WJ" <w_a_x_man@yahoo.com> - 2014-12-01 07:54 +0000
Re: Epic failure awegel@arcor.de (Alexander Wegel) - 2014-12-01 14:02 +0100
Re: Epic failure hughaguilar96@gmail.com - 2014-12-01 15:04 -0800
Re: Epic failure awegel@arcor.de (Alexander Wegel) - 2014-12-02 04:54 +0100
csiph-web