This is an example list of useful tab
programs.
count(@)
max([ count(@), @ ])~1
[ @~1 : sort([ count(@), @ ])[-3,-1] ]
Or:
sort([ count.@, @ ])[-3,-1] .. second.seq.@
freq={ @ -> sum.1 : :[grep(@,"[A-Za-z0-9]+")] }, second.max.flip.freq
freq={ @ -> sum.1 : :[bytes.@] }, [ string.array.@~1, @~0 : (sort.flip.freq)[-10,-1] ]
freq={ count.@ -> sum.1 : :[grep(@,"[A-Za-z0-9]+")] }, sort.freq
:[grep(@,"[A-Za-z0-9]+")] .. { count.@ -> sum.1 } .. sort.@
def f first.@,
def s second.@,
:[grep(@,"[A-Za-z0-9]+")] .. { count.@ -> sum.1, {tolower.@} } .. sort.[ f.@, f.s.@, join(f.s.s.@, ",")]
:[grep(@,"[A-Za-z0-9]+")] .. ?[ (tolower.first.@) == "the", second.@ : pairs.@ ]
merge.flatten.[ [ uniques.tolower.@ : grep(@, "[A-Za-z0-9]+") ] ]
def pad (if(count.@ == 1, "0", ""), @);
cut(@, "\t") .. [ `${$0}-${ pad($1) }-${ pad($2) }`, $(3,-1) ]
sample(4, @)
sum([ count(@) == 0 : sample(4, @) ]) > 0
file.txt
one hundred times and output the histogram of number of empty lines:def empties sum.[ count(@) == 0 : sample(4, @) ],
{ empties.open."file.txt" -> sum.1 : count(100) }
count(0.0, 2*pi(), pi()/8) .. [ sin.@, cos.@ ]
For the next few examples let’s use an input file that looks something like this:
1948 12 11 24
1948 12 12 19
1948 12 13 -74
1948 12 14 -56
The first three fields are the year, month and day. The fourth field is the daily max temperature in units of 0.1 degrees Celcius.
def [year, month, day, temp real.@],
{ year.@ -> avg.temp.@ : cut(@,"\t") }
data={ def [year, _, _, temp real.@], t=temp.@, year.@ -> avg.t, sort.t : cut(@,"\t") },
[ @~0, @~1~0, @~1~1~0.5 : sort.data ]
sort.{ 100*int.(real.cut(@,"\t",3))/100 -> sum.1 }
temps=[. real.cut(@,"\t",3) .],
u=mean.temps, s=stddev.temps, a=min.temps, b=max.temps,
sort.{ bucket(@~0, a, b, 5) -> sum.@~1, sum.@~2 :
:seq([ @, 1, 0 : temps ], [ normal(u,s), 0, 1 : count.count.temps ]) }
def [ year uint.@, _, _, temp real.@ ],
temps=[. uint.@~0, real.@~3 : cut(@,"\t") .],
def [ year, t ],
sd=stddev.[ t.@ : temps],
{ year.@ -> sum.1 : [/ t(@) > 3*sd : temps] }
y_n={ uint.cut(@,"\t",0) -> sum.1 },
u=mean.second.y_n, sd=stddev.second.y_n,
?[ abs(@~1 - u) > sd, @~0 : y_n ]
t={ def [ year uint.@, month uint.@, day, temp real.@ ], month.@ -> map(year.@, sort.temp.@) : cut(@,"\t") }~9~1998,
mean.t, t~0.5
t={ def [ year uint.@, month uint.@, day, temp real.@ ], month.@ -> map(year.@, sort.temp.@) : cut(@,"\t") }~9,
mean.t~1998, t~1998~0.5,
mean.flatten.second.t, (sort.flatten.second.t)~0.5
def [ year uint.@, month uint.@, day, temp real.@ ],
sort.map.?[ (month.@) == 9, year.@, avg.temp.@ : cut(@,"\t") ]
gnuplot -p -e "plot '-' with lines"
to see a graphdef [ year uint.@, month uint.@, day, temp real.@ ],
t=sort.map.?[ (month.@) == 9, year.@, avg.temp.@ : cut(@,"\t") ],
sort.{ @~(-1)~0 -> avg.second.seq.@ : ngrams(seq.t, 10) }
def [ year uint.@, month uint.@, day, temp real.@ ],
sort.{ t=(temp.@)/10, month.@ -> avg(t - box(day(@) == "1", t)~0) : cut(@,"\t") }
[ join(recut(@, " *\\| *")[1,-2], "\t") : skip(grepif(@, "^\\| "), 1) ]
regex = '"([^"]+)" *: *([0-9.]+)|"([^"]+)"',
def split ?[ count.@, @ : grep(@, regex) ],
[ map(stripe(pairs.split.@, 2))~"response" ]
{ grep(@, "//([^/]*)/")~0 -> sum.1 }
regex = "[?&]([^&]+)=([^&]+)";
def urlgetparams map.stripe(pairs.[@ : grep(@, regex) ], 2);
[ urlgetparams.@ ]
regex = "[?&]([^&]+)=([^&]+)";
def urlgetparams map.stripe(pairs.[@ : grep(@, regex) ], 2);
:[ first.urlgetparams.@ ] .. second.max.flip.{ @ -> sum.1 }
def urlgetparams map.[ try take.@, take.@ : explode.seq.recut(@, "[?&=]")[1,-1] ];
second.max.flip.{ @ -> sum.1 : :[ first.urlgetparams.@ ] }
:[ first.url_getparam.@ ] .. second.max.flip.{ @ -> sum.1 }
[ seq(@, "") ]
[ join(head(@, 2), "\t") : explode.@ ]
explode.@ .. [ count.while.[ @ != "", @ ] ]
Or also:
unflatten.[ @ == "", @ ] .. [ count.[/ @ != ""] ]
uniq
:x=peek.pairs.@, glue(first.first.x, ?[ $0 != $1, $1 : second.x ])
def fac << $0 * $1 : 1, count.@ >>, fac.12
<< lsh(@~0, 2) | 1 : 0, count.32 >>
<< a=@~0~0, b=@~0~1, tuple(b, a + b) : tuple(0, 1), count.10 >>~1
tail
:def tail << @~1 : peek.ngrams.@ >>, tail(@, 10)
def step [ t=string.@, case(t; 'XXX','.'; 'X..','.'; '...','.'; 'X') : ngrams(seq.bytes.@,3) ];
def rule110 << join('.', step.@~0, '', '.') : @~0, count.@~1 >>;
rule110('..........XX..........', 8)