Skip to content

Instantly share code, notes, and snippets.

(defn a-star [get-options calc-distance from to]
(let [add-node (fn [queue node]
(if (> (calc-distance (:pos (first queue)) to) (calc-distance (:pos node) to))
(cons node queue)
(cons (first queue) (add-node (rest queue) node))))
process (fn [[node & queue] visited]
(if (= (:pos node) to) node
(if (and (get visited (:pos node)) (< (:cost (get visited (:pos node))) (:cost node)))
(process queue visited)
(let [new-nodes (for [new-pos (get-options (:pos node))]
@bzar
bzar / reaktor_outrun.cpp
Last active August 29, 2015 13:57
Reaktor fast track outrun C++ solution
// g++ -Ofast -fomit-frame-pointer -funroll-loops -o reaktor_outrun reaktor_outrun.cpp
#include <iostream>
#include <vector>
#include <algorithm>
#include <limits>
#include <cctype>
#include <cstdio>
int main(int argc, char** argv)
{
#include <iostream>
#include "../src/promise.h"
int main(int argc, char** argv)
{
Promise<int> p;
p.then<int>([](int const& i) {
std::cout << "1 = " << i << std::endl;
import Html
import Html (..)
import Window
main = lift scene Window.dimensions
scene (w,h) = Html.toElement w h content
content = node "div" [] []
[ text "Hellollo World"
@bzar
bzar / algebraic.cpp
Last active August 29, 2015 14:11
Algebraic datatype emulation in C++ (and the same in Rust)
#include <iostream>
#include <cassert>
#include <string>
// Algebraic type
enum ShapeType { CIRCLE, RECTANGLE, ZERO };
struct Circle { int cx, cy, r; static const ShapeType type = CIRCLE; };
struct Rectangle { int x, y, w, h; static const ShapeType type = RECTANGLE; };
struct Zero { static const ShapeType type = ZERO; };
@bzar
bzar / gist:406cddabeff450e988cb
Created December 11, 2014 18:45
A tuple of containers with compile-time seek by type in C++
#include <iostream>
#include <vector>
#include <type_traits>
template<template<typename...> class Container, typename T, typename... Ts>
class ContainerTuple
{
public:
template<typename TT>
typename std::enable_if<std::is_same<T, TT>::value, Container<T>&>::type get()
#include <iostream>
#include <functional>
#include <vector>
using Cb = std::function<void()>;
using Cbs = std::vector<Cb>;
void print(Cbs& cbs)
{
auto n = cbs.size();
for(decltype(n) i = 0; i < n; ++i)
#!/bin/bash
COMMAND=$1
TESTLIST=$2
DONELIST=$3
touch "$DONELIST"
while read TEST; do
if [ -z "$TEST" ]; then
echo
@bzar
bzar / E.js
Created January 26, 2015 18:04
function E(node) {
function isChildren(x) { return x instanceof Array; }
function isText(x) { return typeof x === "string"; }
if(!(node instanceof Array))
return node;
var element = node[0];
var props = null;
var text = null;
import QtQuick 2.4
import QtQuick.Window 2.2
import goqml 1.0
Window {
visible: true
property var roles: ["bullet", "enemyBullet", "player"]
function getRole(name)
{