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
  • 17:28 (UTC +13:00)
View GitHub Profile
@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
#!/bin/sh
#set -x
info="Usage: anag <5-letter-word>
find 3-5 letter anagrams of a 5 letter word"
[ $1 ] || { echo "$info";exit; }
main(){
for i in 3 4 5; do
grep -h -E ^[$1]{$i}$ * \
| sort -u \
| grep -v -E "(.)(.*\1)"
@roblogic
roblogic / lisp-on-mac.md
Last active August 13, 2019 12:50
Setting up Lisp on MacOS with Atom editor (for dummies like me!)

Some up-to date notes as of Aug 2019 on setting up Common Lisp on my Macbook, using Homebrew and various Atom plugins. Because Emacs is weird and must be avoided! (me am diehard vim user - but not crazy)

0. Assumptions

  • MacOS
  • Homebrew
  • Atom

1. Setup Lisp Ecosystem

#!/bin/zsh
# using bits of https://codegolf.stackexchange.com/a/189073
# and https://codegolf.stackexchange.com/a/182568
for ((;i<$#1;i++)){
s=${1:$i:1} #current char
m=${1:$i:2} #current and next char (length 2)
m=$m:l$m:u #lower + upper cases (length 4)
for ((t=0;t<$RANDOM%5;t++)){
x+=${m:$RANDOM%4:1}
}
@roblogic
roblogic / doublet.f
Last active August 2, 2019 00:20
gfortran solution for code golf problem "Double Speak" https://codegolf.stackexchange.com/q/188988/15940
character(99)::A
read(*,'(A)')A
do i=1,len_trim(A)
write(*,'(A)',advance="no")A(i:i)//A(i:i)
enddo
end
@roblogic
roblogic / rotcol.f
Last active April 1, 2019 22:32
(Draft) Fortran solution for code golf challenge: https://codegolf.stackexchange.com/questions/182363/rotate-a-column
! source file: "rotcol.f"
! compile command:
! gfortran -std=gnu -Wextra -Wall -pedantic -ffree-form -fcheck=all -fbacktrace rotcol.f -o rotcol.app
! executable: "rotcol.app"
! read from file "rotateme.txt":
! K : column to rotate
! Z : number of rows to input
program main