Skip to content

Instantly share code, notes, and snippets.

View shortsightedsid's full-sized avatar

Sid Heroor shortsightedsid

View GitHub Profile
@shortsightedsid
shortsightedsid / garland.lisp
Last active August 29, 2015 14:24
Garland Word length calculator in Common Lisp
;; See https://www.reddit.com/r/dailyprogrammer/comments/3d4fwj/20150713_challenge_223_easy_garland_words/
;;
;; A Garland word is one that starts and ends with the same N letters in the same order,
;; for some N greater than 0, but less than the length of the word.
;; Eg. onion -> 2
;; ceramic -> 1
;; programmer -> 0
;; alfalfa -> 4
@shortsightedsid
shortsightedsid / eel-of-fortune.lisp
Created July 20, 2015 06:14
Find Problem words that can be offensive when playing "EEL of Fortune"
;; Solution for Reddit Daily Programmer problem -
;; https://www.reddit.com/r/dailyprogrammer/comments/3ddpms/20150715_challenge_223_intermediate_eel_of_fortune/
;; Elegant but incorrent solution -
;;
;; This is almost right except for the case when
;; checking for snond as a subword of mispronounced.
;; The naive understanding is that it should return t. However,
;; when looking at the sequence at which letters are called out
;; in EEL of Fortune, one never sees snond. Instead we see
@shortsightedsid
shortsightedsid / magic-squares.lisp
Created April 10, 2016 14:18
Check if a 2D Vector is a Magic Square
;;; Magic Squares - https://www.reddit.com/r/dailyprogrammer/comments/4dccix/20160404_challenge_261_easy_verifying_3x3_magic/
(defun magic-square? (square)
(let* ((dims (array-dimensions square))
(size (car dims)))
(if (and (typep square 'simple-array)
(eq 2 (array-rank square))
(eq size (cadr dims)))
(loop for i from 0 below size
for j from 0 below size
;; CL-PDF Hello World
;;
;; Use ASDF to load the CL-PDF library
;;
(asdf:operate 'asdf:load-op 'cl-pdf)
;;
;; Function to generate a Hello World pdf file.
;; On calling this function, you should see a pdf file
@shortsightedsid
shortsightedsid / multiplication-tables.lisp
Last active March 24, 2019 19:00
Print Multiplication Tables
;; Print Multiplication Tables
;;
;; This demonstrates CL's format function and it's ability
;; to print out Roman Numerals, Numbers in Words etc..
;;
;; Unlikely to be ever used!
(defun multiplication-table (number)
(loop for i from 1 below 12
do (format t "~10<~@r~;times~> ~:d = ~r~%" i number (* i number))
@shortsightedsid
shortsightedsid / list-shuffler.lisp
Last active February 18, 2020 12:39
Shuffle a list
;; Easy Daily Programmer https://www.reddit.com/r/dailyprogrammer/comments/3e0hmh/20150720_challenge_224_easy_shuffling_a_list/
(defun list-shuffler-recursive (input-list &optional accumulator)
"Shuffle a list using tail call recursion."
(if (eq input-list nil)
accumulator
(progn
(rotatef (car input-list)
(nth (random (length input-list)) input-list))
(list-shuffler-recursive (cdr input-list)
@shortsightedsid
shortsightedsid / cl-udpip.lisp
Created October 27, 2014 22:01
Short guide to UDP/IP Client/Server programming in Common Lisp using usockets
; Short guide to UDP/IP Client/Server programming in Common Lisp using usockets
;
; The main reason for this guide is because there are very few examples that
; explain how to get started with socket programming with Common Lisp that I
; could understand.
; After working on a short example on TCP, I found the
; need for a UDP tutorial. So, here goes.
; As usual, we will use quicklisp to load usocket.
@shortsightedsid
shortsightedsid / cl-tcpip.lisp
Last active January 15, 2024 02:36
Short guide to TCP/IP Client/Server programming in Common Lisp using usockets
; Short guide to TCP/IP Client/Server programming in Common Lisp using usockets
;
; The main reason for this guide is because there are very few examples that
; explain how to get started with socket programming with Common Lisp that I
; could understand. After spending a day trying, I finally came up with a small
; bit of code that makes it easy to understand the basics. I've written this
; primarily for myself, but should help others get started as well.
; As usual, we will use quicklisp to load usocket.