4 ms·
For comparison, here the answer from Bing AI Here are the rewrites in Perl, Perl 6, J and Haskell: Perl: > perl -e 'while(<>){$a{$F[1]}++}for(sort{$a{$b}<=>$
by poulpy123 4y ago
For comparison, here the answer from Bing AI
Here are the rewrites in Perl, Perl 6, J and Haskell:
Perl:
> perl -e 'while(<>){$a{$F[1]}++}for(sort{$a{$b}<=>$a{$a}}keys%a){print"$a{$_} $_\n"}' <(history)
Perl 6:
> my %h; for lines() { %h{.[1]}++; }; for %h.sort(-*.value) { .say }' <(history)
J:
> echo 'history' | jconsole -e '10 {. /:~ [: >: [: +/"1 [: =/ [: ;: [: >: [: ;: [: cut ;._2 ] ] ] ] ]'
Haskell:
> import Data.List
> import Data.Ord
> import System.Process
> main = do
h <- readProcess "history" [] []
let l = map (head . tail . words) $ lines h
mapM_ print $ take 10 $ sortBy (flip $ comparing snd) $ map (\x -> (head x, length x)) $ group $ sort l
- poulpy123 4y agoand answers by phind # Perl perl -e 'print sort { $b <=> $a } map { /^.\s(.)$/; \$1 } <>' <(history | awk '{a[\$2]++}END{for(i in a){print a[i] " " i}}') # Perl 6 (Raku) perl6 -e 'lines().map({m/^.\s(.)$/; \$0}).sort({-$^a}).say()' <(history | awk '{a[\$2]++}END{for(i in a){print a[i] " " i}}') # J history | awk '{a[\$2]++}END{for(i in a){print a[i] " " i}}' | jconsole -je 'echo/:~1!:1]fread''''' # Haskell ghc -e 'interact $ unlines . take 10 . reverse . sort . lines' <(history | awk '{a[\$2]++}END{for(i in a){print a[i] " " i}}')
- poulpy123 4y agoI was able to try the perl versions and only the chatgpt is working (I have no experience in perl to check myself)