Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
40
Task/Letter-frequency/8th/letter-frequency.8th
Normal file
40
Task/Letter-frequency/8th/letter-frequency.8th
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
needs map/iter
|
||||
|
||||
8 var, numtasks
|
||||
var tasks
|
||||
|
||||
0 args "Give filename as param" thrownull
|
||||
f:slurp >s s:len numtasks @ n:/ n:ceil 1 a:close s:/ a:len numtasks ! constant work
|
||||
|
||||
m:new constant result
|
||||
|
||||
: print-character-count \ m s -- m
|
||||
swap over m:@ rot s:size 1 n:= over -1 s:@ nip 31 n:< and if
|
||||
-1 s:@ nip "<%d>" s:strfmt
|
||||
else
|
||||
"'%s'" s:strfmt
|
||||
then
|
||||
"%s: %d\n" s:strfmt . ;
|
||||
|
||||
: print-results
|
||||
tasks @ a:len ( a:pop t:result nip ( result -rot m:[]! drop ) m:each drop ) swap times drop
|
||||
result ( nip array? if ' n:+ 0 a:reduce then ) m:map
|
||||
m:keys ' s:cmp a:sort ' print-character-count m:iter drop ;
|
||||
|
||||
: task \ slice --
|
||||
"" s:/ ' noop a:group
|
||||
( nip a:len nip ) m:map ;
|
||||
|
||||
: start-tasks
|
||||
a:new
|
||||
( work a:pop nip 1 ' task t:task-n a:push ) numtasks @ times
|
||||
tasks ! ;
|
||||
|
||||
: wait-tasks
|
||||
tasks @ t:wait ;
|
||||
|
||||
: app:main
|
||||
start-tasks
|
||||
wait-tasks
|
||||
print-results
|
||||
bye ;
|
||||
Loading…
Add table
Add a link
Reference in a new issue