Skip to content

Instantly share code, notes, and snippets.

View camilleroux's full-sized avatar
🍪
Eating cookies

Camille Roux camilleroux

🍪
Eating cookies
View GitHub Profile
@camilleroux
camilleroux / christmas_tree.rb
Created December 24, 2010 18:08
A Ruby code to draw a Christmas Tree in less than 140 character
((1..20).to_a+[6]*4).each{|i|puts ('#'*i*2).center(80)};puts;puts 'Merry Christmas'.center(80)
require 'matrix'
require 'benchmark'
def regress x, y, degree
x_data = x.map { |xi| (0..degree).map { |pow| (xi**pow).to_f } }
mx = Matrix[*x_data]
my = Matrix.column_vector(y)
((mx.t * mx).inv * mx.t * my).transpose.to_a[0]