This file contains hidden or 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
enum IntList { | |
Empty, | |
Cons(int, @IntList) | |
} |
This file contains hidden or 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
trait Monad<A> { | |
//fn bind<B>(&self, &fn (b: B) -> Self) -> Self; | |
fn ret(a: A) -> Self; | |
} | |
enum Zoption<T> { | |
ZSome(T), | |
ZNone | |
} |
This file contains hidden or 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
// bitvec.c | |
// Bit vector com ate 64 elementos | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <assert.h> | |
#define MAX_SIZE 64 | |
typedef struct tagBitVector { |
This file contains hidden or 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
using DataFrames | |
datafile = "data1.csv" | |
function coeff(data::AbstractDataFrame) | |
n = nrow(data) | |
A = sum(data["pop"]) | |
Y = sum(data["profit"]) | |
ya = sum(data["pop"] .* data["profit"]) | |
a2 = sum(data["pop"] .^ 2) |
This file contains hidden or 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
# | |
# iris.jl | |
# Classificação no conjunto de dados Iris usando knn | |
# | |
# Andrei Formiga, 2013-06-17 | |
# | |
using DataFrames | |
train_file = "iris.train.csv" |
This file contains hidden or 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
// multiple indexing for matrices | |
struct Matrix { | |
n: int, | |
m: int, | |
data: ~[int] | |
} | |
impl Index<[int, ..2], int> for Matrix { |
This file contains hidden or 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
(* estimating pi by monte carlo and buffon's needle *) | |
let mc_pi ~repeats = | |
let halfpi = asin 1.0 in | |
let rec loop i crosses = | |
if i = 0 then crosses | |
else | |
let x = Random.float 1.0 in | |
let theta = Random.float halfpi in | |
if x <= (0.5 *. (sin theta)) then loop (i-1) (crosses+1) | |
else loop (i-1) crosses in |
This file contains hidden or 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
# Estimate pi simulating Buffon's needle experiment | |
function mc_pi_iter(repeats::Int) | |
halfpi = asin(1) | |
crosses = 0 | |
for i in 1:repeats | |
x = rand() | |
theta = halfpi * rand() | |
if (x <= 0.5 * sin(theta)) | |
crosses = crosses + 1 | |
end |
This file contains hidden or 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
# Estimate pi simulating the Buffon's needle experiment | |
function mc_pi(repeats::Int) | |
halfpi = asin(1) | |
x = rand(repeats) | |
theta = halfpi * rand(repeats) | |
crosses = sum( x .<= 0.5 * sin(theta) ) | |
repeats / crosses | |
end |
This file contains hidden or 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
function find_bin(x::Float64, limits::Vector{Float64}) | |
bin = length(limits) + 1 | |
for i in 1:length(limits) | |
if x < limits[i] | |
bin = i | |
break | |
end | |
end | |
bin | |
end |