Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #21459
| From | "WJ" <w_a_x_man@yahoo.com> |
|---|---|
| Newsgroups | comp.lang.forth |
| Subject | Re: if i learn forth, will I be able to solve 99%programming problems? |
| Date | 2013-04-06 12:58 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <kjp64s$opo$1@dont-email.me> (permalink) |
| References | <8d7ada1a-cda9-4a6d-aaf7-ebc1ae6b95af@googlegroups.com> <ki4agk$7ko$1@dont-email.me> |
WJ wrote:
> Ruby is a high-level language, suitable for high-level tasks.
> This program counts how many distinct words are found in
> "Moby Dick" and finds the most common word.
>
> table = {} ; table.default = 0
> IO.read("moby10b.txt").scan( /[a-z]+/i ).each{|s| table[s] += 1} ;
> p table.size, table.max_by{|k,v| v}
Here's a Tcl version.
package require fileutil
set table [dict create]
::fileutil::foreachLine myline "moby10b.txt" {
foreach word [regexp -nocase -all -inline {[a-z]+} $myline] {
dict incr table $word } }
set maxi 0
dict for {k v} $table {
if {$v > $maxi} { set word $k ; set maxi $v } }
puts [format "%d\n%s %d" [dict size $table] $word $maxi]
Follow this link for a very nice Tcl/Tk program that displays a rotating
polyhedron:
http://wiki.tcl.tk/14283
Back to comp.lang.forth | Previous | Next | Find similar
Re: if i learn forth, will I be able to solve 99%programming problems? "WJ" <w_a_x_man@yahoo.com> - 2013-04-06 12:58 +0000
csiph-web