Skip to content

Instantly share code, notes, and snippets.

bool item_is_rechargeable(const item_def &it, bool hide_charged)
{
const bool is_wand = it.base_type == OBJ_WANDS;
return (is_wand || is_xp_evoker(it))
&& (!hide_charged
|| (is_wand && item_ident(it, ISFLAG_KNOW_PLUSES)
&& it.charges < wand_max_charges(it))
|| !evoker_is_charged(it));
}
(letfn [(part [n]
[(list `quote (symbol (str "step-" n))),
`(count (doto ~'coll (.add ~n)))])]
`(let [~'coll (java.util.LinkedList.)]
~(apply array-map (mapcat part (range 10)))))
;; eval the result of the previous form:
user> (eval (letfn [(part [n]
[(list `quote (symbol (str "step-" n))),
`(count (doto ~'coll (.add ~n)))])]
user> (println (disassemble-str (fn [ss]
(loop [coll (seq ss)]
(when coll
(println (first coll))
(recur (next coll)))))))
public final class user$eval2412$fn__2413 extends clojure.lang.AFunction {
// elided for brevity...
public java.lang.Object invoke(java.lang.Object ss);
0 getstatic user$eval2412$fn__2413.const__0 : clojure.lang.Var [15]
3 invokevirtual clojure.lang.Var.getRawRoot() : java.lang.Object [21]
template<typename T, typename Iterator>
T* random_choose_weighted(Iterator xs, function<int (const T&)> weight)
{
int totalweight = 0;
const T* result = nullptr;
while (xs) {
T* curr = *xs;
int cweight = weight(*curr);
totalweight += cweight;
if (x_chance_in_y(cweight, totalweight)) {
cljs.user=> (def obj (js-obj {}))
cljs.user=> (def foo (fn [x] (this-as this [this x])))
cljs.user=> (set! (.-f obj) foo)
cljs.user=> (.f obj 1)
[#js {:f #object[cljs$user$foo "function cljs$user$foo(x){
var this$ = this;
return new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [this$,x], null);
}"]} 1]
cljs.user=> ((.-f obj) obj 1)
[#object[Window [object Window]] #js {:f #object[cljs$user$foo "function cljs$user$foo(x){
(lldb) frame info
frame #2: 0x0000000101c9692b crawl`tag_read_you_dungeon(th=0x00007fff5ef456e0) + 1851 at tags.cc:3873
(lldb) l 3868
3868 ASSERT(count_p <= you.get_all_place_info().size());
3869
3870 for (int i = 0; i < count_p; i++)
3871 {
3872 place_info = unmarshallPlaceInfo(th);
3873 ASSERT(!place_info.is_global());
3874 you.set_place_info(place_info);
import Control.Monad
xs = Right 5
ys = Left "oops"
-- listComp = [(x, y) | x <- xs, y <- ys]
-- monad = do
-- x <- xs
-- y <- ys
@amalloy
amalloy / charges.hs
Last active September 17, 2016 07:05
data Rule = Rule {bytes :: Int,
cost :: Double}
charges :: [Rule] -> Int -> Double
charges = foldr applyCharge (const 0)
where applyCharge _ _ 0 = 0
applyCharge (Rule n mult) cont used = (mult * (fromIntegral $ min n used))
+ cont (max 0 (used - n))
value = charges (zipWith Rule [1024, 51200, 512000, 512000, 5120000, 1024000]
$ make
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
/Applications/Xcode.app/Contents/Developer/usr/bin/make -C rltiles all ARCH=x86_64-apple-darwin15.3.0 TILES=
CXX godabil.o
godabil.cc:4139:33: error: no viable conversion from 'string' (aka 'basic_string<char, char_traits<char>, allocator<char> >') to 'const char *'
you.props.erase(key);
^~~
./store.h:286:28: note: passing argument to parameter 'key' here
void erase(const char *key) { map::erase(string(key)); }
^
(let [[a b c] (repeatedly gensym)
e1 [a b]
e2 [a c]]
(fn [x]
(let [y (conj x e1 e1 e2)
diff (- (count y) (count x))]
(condp = diff
1 :map
2 :set
(if (= (first y) e2)