Skip to content

Instantly share code, notes, and snippets.

@roblogic
Created November 7, 2022 19:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roblogic/f90d0b7988ce4a52cb6b785c9f20af33 to your computer and use it in GitHub Desktop.
Save roblogic/f90d0b7988ce4a52cb6b785c9f20af33 to your computer and use it in GitHub Desktop.
interim solution for code golf q https://codegolf.stackexchange.com/questions/25416/
#!/bin/zsh
setopt extendedglob
s=0
f(){
q=(${(s: :)${1//(#s)d/1d}//[^0-9]/ })
for i ({1..$q[1]})((s+=RANDOM%q[2]+1))
<<<$[s+q[3]]
}
f d1
f d6
f d1+3
f d20+3
f 2d504+4
f 16d6
f 2d1
f 2d6+2
f d01
f d01+0
f 01d01+01
f 3d20+10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment