Skip to content

Instantly share code, notes, and snippets.

@pedroarthur
Created February 4, 2023 22:28
Show Gist options
  • Save pedroarthur/a5417b9543fe923435bc4c399ebf3d5e to your computer and use it in GitHub Desktop.
Save pedroarthur/a5417b9543fe923435bc4c399ebf3d5e to your computer and use it in GitHub Desktop.
stupid, untested, probably with presentation errors solution to https://www.hackerrank.com/contests/pycode2015/challenges/dictionary-assignment
#!/bin/bash
split () { grep -o .; }
remove_spaces () { grep -vP '[[:space:]]+'; }
count () { sort | uniq -c; }
read -r _ # just ignore and halt on EoF
while read -r sentence
do
echo "$sentence" | split | remove_spaces | count | while read -r count char
do
echo "Letter $char appears $count time/s"
done
echo
done
#!/bin/bash
bash tst.sh <<EoF
100
asdsa
qwewq
o rato roeu a roupa do rei de roma
EoF
#!/bin/bash
grep -o . | grep -vP '[[:space:]]+' | sort | uniq -c | while read -r count char
do
echo "Letter $char appears $count time/s"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment