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
# define function computeCost | |
computeCost = function(X, y, theta) { sum((X %*% theta - y) ^ 2) / (2 * nrow(X))} | |
# define function to compute next value of theta | |
nextTheta = function(X, y, theta, alpha) { theta - (t(X) %*% (X %*% theta - y) * alpha / nrow(y))} | |
# define function to perform gradientDescent | |
gradientDescent = function(X,y,theta,alpha,num_iters) { | |
jHistory = rep(NA,num_iters); | |
for (i in 1:num_iters) { |
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
def prime_generator(): | |
current = 2 | |
primes = [] | |
while True: | |
while any(map(lambda x: current % x == 0, primes)): | |
current += 1 | |
yield current |
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
def prime_generator(): | |
yield 2 | |
prev = [2] | |
potential = 3 | |
while True: | |
while any(map(lambda x: potential % x == 0, prev)): | |
potential += 1 |
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
package tictactoe | |
import scala.collection.immutable.Map | |
// Players | |
sealed abstract case class Player(val number: Int, val mark: Char, val next: () => Player) | |
case object player_0 extends Player(0,'O', () => player_1) | |
case object player_1 extends Player(1,'X', () => player_0) | |
// Cell |
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
# Rules : https://github.com/edgecase/ruby_koans/blob/master/koans/GREED_RULES.txt | |
r = ((100,1000), (0,200), (0,300), (0,400), (50,500), (0,600)) | |
def times(dct,val) : | |
dct[val-1] = dct[val-1] + 1 | |
return dct | |
def score(dice) : | |
dct = reduce(times,dice,dict((x,0) for x in range(6))) |
NewerOlder