This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun add-to-counter (counter carry zero op &key (test #'eq)) | |
(dotimes (i (length counter)) | |
(if (funcall test (aref counter i) zero) | |
(progn (setf (aref counter i) carry) | |
(setf carry zero)) | |
(progn | |
(setf carry (funcall op (aref counter i) carry)) | |
(setf (aref counter i) zero)) | |
)) | |
carry) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Darwin | |
enum CatError: Error { | |
case open(path: String) | |
} | |
func parsePosixCommands(_ args: [String]) -> ([String], [String]) { | |
let endOfOptions = args.firstIndex { $0 == "--" } ?? args.count | |
let certainArguments = args.suffix(from: endOfOptions) | |
var toConsider = args.prefix(upTo: endOfOptions) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static func mean<S: Sequence, T>( | |
of sequence: S, | |
oneScalar: T, | |
scale: (T, S.Element) -> S.Element | |
) -> S.Element? where S.Element: AdditiveArithmetic, T: FloatingPoint { | |
var it = sequence.makeIterator() | |
guard let initial = it.next() else { | |
return nil |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct BinaryCounter { | |
private init() {} | |
static func add<C: MutableCollection>( | |
counter: inout C, | |
x: C.Element, | |
zero: C.Element, | |
operation op: (C.Element, C.Element) -> C.Element | |
) -> C.Element where C.Element: Equatable { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension Sequence where Element == Float { | |
// average is a vector space operation | |
func average() -> Element { | |
let one = Float(1.0) | |
var mean = Element.zero | |
var n = Float(0.0) | |
for x in self { | |
n += one |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// this shows the preprocessor you can use to detect whether to try pledge or not | |
// | |
#ifdef __OpenBSD__ | |
#define HAS_PLEDGE 1 | |
#endif | |
#ifdef HAS_PLEDGE | |
if (pledge("stdio", NULL) == -1) | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; The official HD AI | |
; An Artificial Intelligence Script written by Archon and Promiskuitiv | |
; Get in contact with Promiskuitiv by sending a mail to [email protected] | |
; 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func foldBinary<T>(_ list: [T], operation: (T, T) -> T) -> T? { | |
if let initial = list.first { | |
return list.dropFirst().reduce(initial, operation) | |
} else { | |
return nil | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; 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))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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) { |