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
func getWordCount(text string) map[string]int { | |
words := strings.Fields(text) | |
wordCounter := make(map[string]int) | |
for _, word := range words { | |
word = strings.ToLower(word) | |
if wordCounter[word] > 0 { | |
wordCounter[word]++ | |
} else { | |
wordCounter[word] = 1 |
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
func removePunctuation(text string) string { | |
// match a sequence of unicode letters which may contain an apostrophe | |
re := regexp.MustCompile("\\p{L}+('\\p{L}+|\\p{L}*)") | |
return strings.Join(re.FindAllString(text, -1), " ") | |
} |
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
-module(tictactoe). | |
-export([play/0]). | |
%-compile(export_all). | |
%% -1 is X and false | |
%% 1 is O and true | |
%% 0 is _ | |
wins() -> | |
[[1,2,3], [4,5,6], [7,8,9], |
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
// static evaluate function | |
// adapted from http://kartikkukreja.wordpress.com/2013/03/30/heuristic-function-for-tic-tac-toe/ | |
// original author : Kartik Kukreja | |
val wins = Array( Array(0,1,2), Array(3,4,5), Array(6,7,8), | |
Array(0,3,6), Array(1,4,7), Array(2,5,8), | |
Array(0,4,8), Array(2,4,6) ) | |
val heuristic = Array( Array(0, -10, -100, -1000), | |
Array(10, 0, 0 , 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
// Tested using Java version 1.7.0_21 in Eclipse Juno | |
// | |
// 3 recursive functions to compute the sum of the first n odd positive integers | |
// n can reach 4000 | |
public static int sumOdds1(int n, int sum, int counter){ // call : sumOdds1(20, 0, 0) | |
if (n == 0){ | |
return sum; | |
}else{ |
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
-- Tested with Lua 5.1.4 | |
-- 3 recursive functions to compute the sum of the first n odd positive integers | |
-- n can reach 100,000,000 | |
function sumOdds1(n, sum, counter) -- call: sumOdds(20, 0, 0) | |
if n == 0 then | |
return sum | |
else | |
if counter % 2 == 1 then |