aboutsummaryrefslogtreecommitdiff
path: root/games
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2016-07-08 01:10:26 +1200
committerTom Ryder <tom@sanctum.geek.nz>2016-07-08 01:10:26 +1200
commitbb37acd5e63fe6512f61e158dfb89dececaf86f9 (patch)
tree908f0bd0962791565dbd61ec679b40c460622722 /games
parentMake murl(1) into plain POSIX sh script (diff)
downloaddotfiles-bb37acd5e63fe6512f61e158dfb89dececaf86f9.tar.gz
dotfiles-bb37acd5e63fe6512f61e158dfb89dececaf86f9.zip
Add hku and syl to games
Very ugly, and no manual pages yet.
Diffstat (limited to 'games')
-rwxr-xr-xgames/hku16
-rwxr-xr-xgames/syl18
2 files changed, 34 insertions, 0 deletions
diff --git a/games/hku b/games/hku
new file mode 100755
index 00000000..029b41c6
--- /dev/null
+++ b/games/hku
@@ -0,0 +1,16 @@
+#!/usr/bin/env bash
+hash syl || exit
+declare -a lsts ws
+lsts=(5 7 5)
+for ((lc=0;lc<${#lsts[@]};lc++)) ; do
+ ws=()
+ for ((sc=0;sc<lsts[lc];)) ; do
+ read -r wr
+ sy=$(syl "$wr")
+ ((sy<=lsts[lc]-sc)) || continue
+ ws[${#ws[@]}]=$wr
+ ((sc+=sy))
+ done
+ printf '%s\n' "${ws[*]}"
+done < <(shuf /usr/share/dict/words |
+ grep -v \'s\$)
diff --git a/games/syl b/games/syl
new file mode 100755
index 00000000..85f68625
--- /dev/null
+++ b/games/syl
@@ -0,0 +1,18 @@
+#!/usr/bin/env bash
+word=$1
+syls=0
+vs=0
+for ((i=0;i<${#word};i++)); do
+ if [[ ${word:i:1} == [aeiouy] ]] ; then
+ ((vs!=1)) && ((syls++))
+ ((vs++))
+ else
+ ((vs=0))
+ fi
+done
+case $word in
+ *[aeiou][^aeiou]e|*ed)
+ ((syls > 1)) && ((syls--))
+ ;;
+esac
+printf '%u\n' "$syls"