This file contains 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
;;; dashtest.el --- benchmarking dash -*- lexical-binding: t -*- | |
(defmacro --map-mapcar (form list) | |
(declare (debug (form form))) | |
`(mapcar (lambda (_) ,form) ,list)) | |
(defmacro --map-loop (form list) | |
(declare (debug (form form))) | |
(let ((result-sym (make-symbol "result"))) | |
`(let (,result-sym) |
This file contains 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
;; Minimum Number Of Coin Tosses Such That Probability Of Getting 3 | |
;; Consecutive Heads Is Greater Than 1/2 | |
;; http://blog.eduflix.tv/2012/05/contest-answer-minimum-number-of-coin-tosses-such-that-probability-of-getting-3-consecutive-heads-is-greater-than-12/ | |
(require 'cl) | |
(defun flip () | |
"Flip a coin." | |
(if (< 0 (random)) 'H 'T)) |
This file contains 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
;; http://xahlee.blogspot.com/2011/11/emacs-lisp-exercise-latitude-longitude.html | |
(defun latitude-longitude-decimalize (str) | |
(destructuring-bind (lath latm lats latd lonh lonm lons lond) | |
(split-string str "[^0-9.NEWS]+" t) | |
(vector (latlon-helper latd lath latm lats) | |
(latlon-helper lond lonh lonm lons)))) | |
(defun latlon-helper (d &rest hms) | |
(* (if (or (equal d "N") (equal d "E")) 1 -1) |
This file contains 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
CFLAGS = -std=c99 -Wall -Wextra -O3 -g3 | |
solve: solve.c | |
clean: | |
rm -rf solve |
This file contains 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
CFLAGS = -std=c99 -Wall -Wextra -O3 -g3 | |
lfsr: lfsr.c |
This file contains 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
/* Estimate pi by shooting arrows at a shield. | |
* https://www.smbc-comics.com/comic/math-and-war | |
* Only uses integer operations except for displaying the quotient. | |
*/ | |
#include <time.h> | |
#include <stdio.h> | |
#include <inttypes.h> | |
#define HALF UINT64_C(0x80000000) | |
#define QUARTER UINT64_C(0x40000000) |
This file contains 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 <stdio.h> | |
#include <stdlib.h> | |
#include <stdint.h> | |
unsigned | |
hashCode(const unsigned short *s, size_t len) | |
{ | |
unsigned hash = 0; | |
for (size_t i = 0; i < len; i++) | |
hash = 31 * hash + s[i]; |
This file contains 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://redd.it/96wper */ | |
#include <stdio.h> | |
#include <stdlib.h> | |
static const unsigned long factors[] = { | |
1ULL, 10ULL, 100ULL, 1000ULL, 10000ULL, 100000ULL, 1000000ULL, | |
10000000ULL, 100000000ULL, 1000000000ULL, 10000000000ULL, | |
100000000000ULL, 1000000000000ULL, 10000000000000ULL, 100000000000000ULL, | |
1000000000000000ULL, 10000000000000000ULL, 100000000000000000ULL | |
}; |
This file contains 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://github.com/skeeto/utf-7/issues/1 | |
*/ | |
#include <stdio.h> | |
#include "utf7.h" | |
static unsigned long | |
rand32(unsigned long s[1]) | |
{ | |
unsigned long x = (*s += 0xd6abc211ul) & 0xfffffffful; | |
x ^= x >> 16; |
This file contains 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
## Returns the Perlin noise value for the given point. Accepts 2D | |
## arrays for x and y, i.e. from meshgrid(). For example, | |
## | |
## [x y] = meshgrid(0:0.1:10, 0:0.1:10); | |
## d = perlin(x, y); | |
## | |
## The special thing here is it's entirely vectorized: no loops! | |
function v = perlin(x, y) | |
## Find the nearest grid points (2D) | |
x0 = floor(x); |