Skip to content

Instantly share code, notes, and snippets.

View roblogic's full-sized avatar
💭
probably playing code golf

Rob Papesch roblogic

💭
probably playing code golf
  • Auckland, NZL
  • 20:52 (UTC +12:00)
View GitHub Profile
((!$1))&&<<<"Congratulations on your new baby! :D"&&exit
y=$[$1<0?2:2*$1] a=${(l:y:: $:)} b=${(l:y+1::-:)}
(($1>0))&&echo "$a\n${a//$/|}"
echo "$b\n${b//-/~}\n$b"
43232122 Cossack dancer
___
(_*_)
\(o_O)
(] [)>
(" ")
while read w; do
i=
for ((n=1;i++<#w;n++))[[ $w[i] != $w[i+1] ]]&&printf $n$w[i]&&n=0
echo
done < <(echo "heeeello\nwoooorld")
setopt FORCE_FLOAT
m=$1 n=$1 a=$#
for x ((t+=x))&&m=$[x>m?x:m]&&n=$[x<n?x:n]
s=$[2*(a>2?(t-m-n)/(a-2):t/a)]
<<<$[(s^0+(s-s^0>.5?1:0))/2]
@roblogic
roblogic / btoz85
Last active May 28, 2020 03:23
Z85 encoding implemented in Zsh.. Input: binary string (length 32). Output: Z85 ascii-encoded string (length 5). Spec: https://rfc.zeromq.org/spec:32/Z85/
#!/bin/zsh
# Version 0.00.01 - bare bones only
# Binary to Ascii conversion, using Z85 encoding algorithm
# Similar to Ascii85, few different characters, doesn't use ascii code table
# https://www.johndcook.com/blog/2019/03/05/base85-encoding/
# https://rfc.zeromq.org/spec:32/Z85/
# Example: (input must be 32 characters)
# input 01001101011000010110111000100000
# base85 24 73 80 78 61
@roblogic
roblogic / btoa.zsh
Last active September 9, 2019 00:51
btoa implemented in Zsh, with bc for tricky base conversion. Input: binary string (length 32). Output: Ascii85 encoded string (length 5)
#!/bin/sh
# Version 0.00.01 - bare bones only
# Binary to Ascii conversion, using Ascii85 encoding algorithm
# https://en.wikipedia.org/wiki/Ascii85
# http://www.tenminutetutor.com/data-formats/binary-encoding/ascii85-encoding/
# Example: (input must be 32 characters)
# input 01001101011000010110111000100000
# output 9jqo^
@roblogic
roblogic / fizbuz.zsh
Created August 28, 2019 15:23
Code golf, canonical FizzBuzz implementation in Zsh (66 bytes) https://codegolf.stackexchange.com/a/190994/15940
for ((;i++<100;)){w=
((i%3))||w=Fizz;((i%5))||w+=Buzz
<<<${w:-$i}}
@roblogic
roblogic / stopwatch.zsh
Created August 26, 2019 12:42
console stopwatch in zsh. raw (ungolfed) solution to https://codegolf.stackexchange.com/q/108468/15940
#!/bin/zsh
u(){ echo $[`gdate +%s%N`/1000]; }
echo "begin"; read -r
a=`u`;a=${a:0:10}
go(){
while :;{q=`u`;
t=$[${q:0:10}-a]
s=`printf %02d $[t%60]`
m=`printf %02d $[(t%3600-s)/60]`
echo "\r$m:$s.${q:10:2}\c"
r()printf ${(#)$((13+$1+(##$X-$1)%26))}
for X (${(s::)1})case $X {[A-Z])r 52;;[a-z])r 84;;*)printf $X}
@roblogic
roblogic / scrabble-words-2char.md
Last active August 25, 2019 11:16
printing all 2-letter scrabble words, using zsh https://codegolf.stackexchange.com/a/190647/15940

Zsh, 175 bytes

This solution uses a 125-char string, where the lowercase letters serve as delimiters and the first letter of the following sequence of capital letters.

We iterate over the letters of $L. If the current letter $X is lowercase by ascii comparison, set $W to $X. Otherwise, print $W concatenated with $X to make the current word.

[Try it Online!][1]

L=aABDEGHILMNRSTWXYbAEIOYdEOeDFHLMNRSTXfAEgOhAEIMOiDFNSTjOkAIlAIOmAEIMOUYnAEOUoDEFHIMNPRSWXYpAEIqIrEsHIOtAIOuHMNPSTwEOxIUyAEOzA