Skip to content

Instantly share code, notes, and snippets.

Avatar

Justin Meiners justinmeiners

View GitHub Profile
View Age of empires II AI Scripting
; The official HD AI
; An Artificial Intelligence Script written by Archon and Promiskuitiv
; Get in contact with Promiskuitiv by sending a mail to neuernamae@web.de
; List of taunts it reacts to:
; Standard taunts.
; 33 - Stop slinging resources. If slinging is requested early and is immediately canceled it may mess up the strategy.
; 38 - Sling Resources. Human player only, stops any unit production except for civilian units.
View foldBinary.swift
func foldBinary<T>(_ list: [T], operation: (T, T) -> T) -> T? {
if let initial = list.first {
return list.dropFirst().reduce(initial, operation)
} else {
return nil
}
}
View bionomial_choices.cl
; https://en.wikiversity.org/wiki/Binomial_coefficients
(defun arrangements (n k)
(if (= n 0)
(list nil)
(append
(when (< k n)
(mapcar (lambda (tail)
(cons 0 tail))
(arrangements (- n 1) k)))
View mode.cpp
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
template<typename I>
std::pair< typename std::iterator_traits<I>::value_type, size_t> mode(I start, I end) {
typedef typename std::iterator_traits<I>::value_type V;
if (start == end) {
View numbers.cl
(defun digits-to-val (digits)
(reduce (lambda (acc x)
(+ (* 10 acc) x)) digits))
(defun val-to-digits (x)
(if (< x 10)
(list (mod x 10))
(cons (mod x 10)
(val-to-digits (floor x 10)))))
@justinmeiners
justinmeiners / sicm-mit-scheme.Dockerfile
Last active Nov 26, 2020
MIT Scheme + Structure and Interpretation of Classical Mechanics libraries (scmutils).
View sicm-mit-scheme.Dockerfile
# Dockerfile
# MIT Scheme + Structure and Interpretation of Classical Mechanics libraries (scmutils).
# For REPL. Launch with -it for a tty.
# For script. docker run -v ${PWD}/scripts:/scripts scm --quiet --load /scripts/test.scm
FROM alpine:3.12.1
RUN apk add --no-cache \
build-base \
linux-headers \
View compact-duplicates.cl
(defun compact-duplicates (vector cmp)
(prog ((i 1)
(j 1)
(N (length vector))
(x (aref vector 0)))
loop
(if (not (funcall cmp (aref vector i) x))
(progn
(setf x (aref vector i))
View my-sin.cl
; my own sin and cos functions using taylor seris
(defun eval-poly (coef x)
; horners method
(prog* ((i (- (length coef) 1))
(acc (aref coef i)))
accum
(decf i)
(if (< i 0) (return acc))
(setf acc (+ (aref coef i) (* x acc)))
View integer_sqrt.cl
; code translated from
; https://en.wikipedia.org/wiki/Integer_square_root
; note that theirs actually has an off by one error
(defun integer-sqrt (n)
(prog ((shift 2) (result 0))
(declare (fixnum n shift result))
(if (< n 2) (return n))
shifting
(if (not (= (ash n (- shift)) 0))
View grouping.cl
(defun group-adjacent (list &key (test #'eql))
((
(lambda (group x)
(if (or (funcall test (car group) x) (funcall test x (car group)))
(progn
(push group result)
(list x))
(cons x group)))
(cdr list)