Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

/prog/ challenge #-1/12

Name: Anonymous 2021-03-15 11:30

Write a program to count the frequencies of unique words from standard input, then print them out with their frequencies, ordered most frequent first, then ordered ASCIIbetically ascending. For example, given this input:

Hax my anus anus anus
hax the planet and anus

The program should print the following:

anus 4
hax 2
and 1
my 1
planet 1
the 1


ASCII input and output since unicode was a mistake. Shortest bytecount wins. Good luck.

Name: Anonymous 2021-03-15 17:50

Haskell:
import Data.Map hiding (map)
import Data.List
import Data.Char
main = getContents >>= \x -> mapM_ (\(x, i) -> putStrLn (x ++ (' ':show i))) $ concat $ reverse $ map (sortOn fst) $ groupBy (\x -> \y -> snd x == snd y) $ sortOn snd $ toList (fromListWith (+) [(map toLower y, 1 :: Int) | y <- words x])
Edited on 15/03/2021 18:02.

Name: Anonymous 2021-03-15 20:03

Some rusty bash after >5 years of not having used Linux...

tr 'A-Z ' 'a-z\n' | sort | uniq -c | sort -k1rn,1 -k2,2 | awk '{ print $2 " " $1}'

I'm not happy with the
awk
part, I had to google it like a pajeet. I'm sure that it's possible with
cut
, but I could not get it to work in the free (as in free beer) online emulator I was using.

Name: Anonymous 2021-03-15 21:07

>>3
I'm sure that it's possible with cut, but I could not get it to work in the free (as in free beer) online emulator I was using.
https://www.gnu.org/software/coreutils/manual/html_node/cut-invocation.html
The list elements can be repeated, can overlap, and can be specified in any order; but the selected input is written in the same order that it is read, and is written exactly once.

Don't change these.
Name: Email:
Entire Thread Thread List