Skip to content

Instantly share code, notes, and snippets.

View lispm's full-sized avatar

Rainer Joswig lispm

  • Germany
View GitHub Profile
; https://leetcode.com/problems/fair-candy-swap/
(defun candy-swap (a b &aux (sa (reduce #'+ a)) (sb (reduce #'+ b)))
(mapc (lambda (x &aux (y (+ x (/ (- sb sa) 2))))
(when (member y b)
(return-from candy-swap (values x y))))
a))
@lispm
lispm / queens.lisp
Last active February 3, 2020 17:58
;;; Paper: https://arxiv.org/pdf/2001.02491.pdf
;;; Code: https://github.com/cvlab-epfl/n-queens-benchmark
;;; Lisp Code: https://github.com/cvlab-epfl/n-queens-benchmark/blob/master/code/queens.lisp
;;; Changes/extensions to the original Common Lisp code: Rainer Joswig, joswig@lisp.de, 2020
;; * using bitvectors is faster than 'boolean' arrays (which typically aren't supported in CL)
;;; In Common Lisp
;;; * use Quicklisp
;;; * compile and load this file
@lispm
lispm / mi.lisp
Last active August 13, 2019 12:50
;;; https://www.quora.com/Do-C-developers-find-multiple-inheritance-a-useful-feature-Do-Java-developers-ever-find-themselves-wishing-Java-supported-it/answer/Mario-Galindo-Queralt
; Common Lisp: Rainer Joswig, joswig@lisp.de, 2019
;;; ======================================================
;;; Features
(defclass walk ()
@lispm
lispm / insults.lisp
Created November 14, 2018 19:42
Shakesperian insults by Jerry Maguire in Lisp
;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Author: joswig@lisp.de; Coding: latin-1; Base: 10; Readtable: CL -*-
; Shakesperian insults by Jerry Maguire
; Lisp code: Rainer Joswig, 2018, joswig@lisp.de
(defparameter *insult-data*
#(#("artless" "bawdy" "beslubbering" "bootless" "churlish" "cockered" "clouted"
"craven" "currish" "dankish" "dissembling" "droning" "errant" "fawning"
"fobbing" "froward" "frothy" "gleeking" "goatish" "gorbellied"
"impertinent" "infectious" "jarring" "loggerheaded" "lumpish" "mammering"
; https://codereview.stackexchange.com/questions/215682/occurrences-frequency-count-exercise-3-ch-3-in-ansi-common-lisp/215711?noredirect=1#comment417480_215711
(defun occurrences (list)
(let ((ht (make-hash-table)))
(let ((holder nil))
(dolist (x list)
(if (not (member x holder :test #'eq))
(progn
(push x holder)
; https://github.com/netb258/clj-maze/blob/master/src/maze/core.clj
; CL version, by Rainer Joswig, joswig@lisp.de, 2019
; changes
; maze is a 2d array, contents are symbols/numbers
; pass directions as symbols
; use paths as position histories
@lispm
lispm / make.lisp
Last active February 4, 2019 09:31
(defun make (pts &key closed)
(let ((n (length pts)))
(if (< n 4) (error "must have at least 4 pts."))
(let ((apts (make-dfloat-array n)))
(loop
for p in pts
for i from 0
do
(destructuring-bind (x y)
p
; linear-search returns the position of item in the list
(defun linear-search (list item &aux (pos 0))
(dolist (e list nil)
(if (eql e item)
(return pos)
(incf pos))))
(defun linear-search (list item &aux (pos 0))
; adapted from https://groups.google.com/d/msg/comp.lang.lisp/TsmbsOK32DM/9Q7prvFV9YsJ , Pascal Costanza
;;;; checking CLOS slot writes at runtime for the correct type
;;; LispWorks
(defclass slot-writes-checking-class (standard-class)
())
(defmethod validate-superclass
@lispm
lispm / earliest EMACS.text
Last active September 11, 2018 18:22
GLS in 2007 about the earliest EMACS development
<GLS is Guy Steele, RMS is Richard Stallman, DLW is Dan Weinreb, Moon is David Moon, Ed is Ed
Schwalenberg, CBF is Charles Frankston, EAK is Earl Killian, ECC is Gene Cicarelli,
RMF is Bob Frankston, and JLK is John Kulp.>
---
I think all of us have been relying on our memories, which can
fail in various ways. Last time around I checked my file folder
of notes about Emacs, which has some useful information, but
not a lot about who did what. Now I have some more information