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
(def fib-seq | |
"lazy seq of Fibonacci numbers" | |
(lazy-cat [0 1] (map + (rest fib-seq) fib-seq))) | |
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 <cstdint> | |
#include <cstddef> | |
#include <iostream> | |
#include <iterator> | |
//g++ -std=c++0x balance.cxx -o balance_cxx -O4 -march=native | |
int main(int argc, char* argv[]) { | |
for(std::istream_iterator<int64_t> in(std::cin),e; in!=e && *in; ){ | |
int64_t res(0); | |
for(int64_t i(0),nb(*in++); i != nb; ++i,++in) | |
{ res+= (i < (nb /2)) ? *in : ((i > (nb /2) ||(nb %2 == 0 )) ? -*in :0); } |
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
#!/bin/bash | |
DATA=../data_2000_50000.in | |
NB_RUN=10 | |
for SOURCE in $(ls *.cxx); | |
do | |
EXEC=${SOURCE%.cxx} | |
[ ! -e ${EXEC} ] && g++-snapshot -std=c++11 ${SOURCE} -o ${EXEC} -O4 -march=native -Wno-deprecated | |
echo -ne ${EXEC}'\t' | |
for i in $(seq ${NB_RUN}); | |
do |
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- optimal-plan-ordered [bids] | |
(let [optimal-plan-after (fn [flight] | |
(let [earliest (+ (:DEPART flight) (:DUREE flight)) | |
after (drop-while #(< (:DEPART %) earliest) bids)] | |
(if (empty? after) {:gain 0 :path '()} (optimal-plan-ordered after)))) | |
current-plan (fn [flight] | |
(let [{:keys [gain path]} (optimal-plan-after flight)] | |
{:gain (+ (:PRIX flight) gain) :path (conj path (:VOL flight))}))] | |
(reduce #(if (> (:gain %2) (:gain %1)) %2 %1) (map current-plan bids)))) |
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 rxjava-datomic.query | |
(:require [datomic.api :as d]) | |
(:use [clojure.repl :only [pst]]) | |
(:import [rx Observable] | |
datomic.Peer)) | |
(defn query [qry & inputs] | |
(Observable/toObservable | |
(Peer/q qry (object-array inputs)))) |
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 power [a n op] | |
"Compute a to the (positive int) power n using operator op, using | |
exponentiation by squaring." | |
(let [ power-accumulate-positive (fn [r a n op] | |
(let [r (if (odd? n) (op r a) r)] | |
(if (= 1 n) | |
r | |
(recur r (op a a) (quot n 2) op))))] | |
(if (odd? n) | |
(let [n (quot n 2)] |
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
Decoding compiled method 0x00007fe951138a90: | |
Code: | |
[Entry Point] | |
[Constants] | |
# {method} '<init>' '(Ljava/net/URLClassLoader;Ljava/lang/String;)V' in 'java/net/URLClassLoader$1' | |
# this: rsi:rsi = 'java/net/URLClassLoader$1' | |
# parm0: rdx:rdx = 'java/net/URLClassLoader' | |
# parm1: rcx:rcx = 'java/lang/String' | |
# [sp+0x20] (sp of caller) | |
0x00007fe951138bc0: mov 0x8(%rsi),%r10d |
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 <array> | |
#include <iostream> | |
#include <numeric> | |
#include <algorithm> | |
#include <tuple> | |
#include <sstream> | |
/* const correctness and pass by value vs const ref, move semantics | |
left as an exercise to the reader. | |
iterator range API prevents a flatmap as the flatmapped function | |
could not either return a value or a range. |
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 <functional> | |
// TODO : monoid | |
template<typename... Fn> struct composer; | |
template<> struct composer<> { | |
template<typename Data> Data operator()(Data d){ return d; } | |
}; | |
template<typename F0, typename... Fn> | |
struct composer<F0, Fn...> : private composer<Fn...> { | |
F0 f; | |
composer(F0 f0, Fn const&... fn): composer<Fn...>(fn...), f(f0){} |
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 <iostream> | |
#include <iterator> | |
#include <string> | |
#include <tuple> | |
#include <functional> | |
#include "transducers.hxx" | |
#include "tuple_reader.hxx" | |
// usage: seq 1 20 |./FizzBuzz 3 Fizz 5 Buzz |
OlderNewer