Anonymous user
Checksumcolor: Difference between revisions
m
→{{header|zkl}}: tweak
Thundergnat (talk | contribs) m (→{{header|Perl 6}}: minor tweaks) |
m (→{{header|zkl}}: tweak) |
||
Line 268:
=={{header|zkl}}==
{{trans|OCaml}}
<lang zkl>var [const]
fcn squareDist(rgb1,rgb2){ rgb2.zipWith('-,rgb1).apply("pow",2).sum(0) }
fcn colorize(chksum){ // "check sum
k:=chksum.len()/3*3; // every three digits gets its own color
chksum[0,k].pump(String,T(Void.Read,2), fcn(r,g,b){
// find color closest to these three digits of check sum
rgb,m,colorCode := vm.arglist.apply("toInt",16), 676, "";▼
// minMaxNs returns indexes of min and max (in list of ints)
foreach cex in (colors){▼
colorRGBs.apply(squareDist.fp(_)) : (0).minMaxNs(_)[0] : colorTxt[_] :
▲ "\e[%s;1m%c%c%c\e[00m".fmt(colorCode, r,g,b)
})
.append("\e[
}</lang>
Fake "md5sum coreutils-* | zkl checksumcolor
<lang zkl>re,lines := RegExp("([A-Fa-f0-9]+)([ \t]+.+)"),
#<<<
Line 301 ⟶ 299:
}</lang>
{{out}}
<pre>Same as the OCaml entry</pre>
This is what we would do to implement "md5sum chksum.zkl | zkl chksum"
(instead of the above test code)
<lang zkl>re:=RegExp("([A-Fa-f0-9]+)([ \t]+.+)");
if(re.search(line)){
chksum,txt := re.matched[1,*];
println(colorize(chksum),txt);
} else print(line);
}</lang>
|