Skip to content

Instantly share code, notes, and snippets.

@scientific-coder
scientific-coder / bench.sh
Created July 22, 2012 13:15
Optimization Contest
#!/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
#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); }
@scientific-coder
scientific-coder / fib-seq-1.clj
Created March 1, 2012 16:58
Code snippets for Duchess-fr Battle Language 2012-02-29 test it on http://tryclj.com/ !
(def fib-seq
"lazy seq of Fibonacci numbers"
(lazy-cat [0 1] (map + (rest fib-seq) fib-seq)))