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
class List: | |
def __init__(self, data, next): | |
self.data = data | |
self.next = next | |
def __repr__(self): | |
return 'List({0.data!r}, {0.next!r})'.format(self) | |
def str_helper(self): | |
if self.next == None: | |
return '{0.data!s}'.format(self) | |
else: |
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
;; This fn allows calling any method, as long as it's the first with that name in getDeclaredMethods(). | |
;; Works even when the arguments are primitive types. | |
(defn call-method | |
[obj method-name & args] | |
(let [m (first (filter (fn [x] (.. x getName (equals method-name))) | |
(.. obj getClass getDeclaredMethods)))] | |
(. m (setAccessible true)) | |
(. m (invoke obj (into-array Object args))))) |
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
(ns cljclass) | |
;; Various ways to solve the problem of transforming a collection to a seq or vector of indices starting at zero, but | |
;; using an index of -1 for items for which (pred item) is true. | |
;; E.g. (index-except odd? [1 4 18 7 9 2 4 3]) => [-1 0 1 -1 -1 2 3 -1] | |
;; NB: | |
;; This is not the same as assigning indices and replacing the elements for which pred is true with -1. | |
;; E.g. (index-except odd? [1 2 3]) => [-1 0 -1] and not [-1 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
from numpy import zeros, array | |
import itertools | |
from pymclevel.level import extractHeights | |
terrainBlocktypes = [1, 2, 3, 7, 12, 13, 14, 15, 16, 24, 56, 73, 74, 82, 87, 88, 89] | |
terrainBlockmask = zeros((256,), dtype='bool') | |
terrainBlockmask[terrainBlocktypes] = True | |
inputs = ( | |
("Repeat count", (1, 50)), |
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
(defn macroexpand-n [n form] | |
(if (zero? n) | |
form | |
(recur (dec n) | |
(macroexpand-1 form)))) |