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
| module Main where | |
| import Board.Mark (x, y) |
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
| module Main where | |
| import Board.Mark as Mark |
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
| -- Declare a module | |
| module Game.Logic where | |
| {- content -} |
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
| -- Declare a module and specify functions to export | |
| module Game.Logic | |
| ( isOver | |
| , isValid | |
| , hasWon | |
| ) where | |
| {- content -} |
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
| var fib = function(n) { | |
| if (n <= 1) { | |
| return n; | |
| } else { | |
| return fib_tail_recursive(n, 0, 1); | |
| } | |
| } | |
| var fib_tail_recursive = function(n, a, b) { | |
| if (n === 0) { |
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
| var minimum_number_of_stamps = function() { | |
| var memo = []; | |
| var min_stamps = function(postage, stamps) { | |
| if (postage == 0) { | |
| return 0; | |
| } else if (memo[postage]) { | |
| return memo[postage]; | |
| } else { | |
| var min = postage; | |
| for (var i = 0; i < stamps.length; i++) { |
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
| var postage = 32; | |
| var stamps = [90, 30, 24, 15, 12, 10, 5, 3, 2, 1]; | |
| minimum_number_of_stamps(postage, stamps); // 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
| function reverse_words_in_sentence() { | |
| for (i = arguments.length - 1; i > -1; i--) { | |
| this.push(arguments[i]); | |
| } | |
| return this.join(" "); | |
| } | |
| sentence = "The Good, the Bad and the Ugly".split(" "); | |
| reverse_words_in_sentence.apply([], sentence); | |
| // "Ugly the and Bad the Good, The" |
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
| String.prototype.reverse_words_in_sentence = function() { | |
| return this.split(" ").reverse().join(" "); | |
| } |
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
| String.prototype.reverse = makeReverseFunction(); | |
| function makeReverseFunction() { | |
| function reverse() { | |
| var string_array = this.split(""); | |
| var length = this.length; | |
| var swap = function(a, b) { | |
| temp = string_array[a]; | |
| string_array[a] = string_array[b]; | |
| string_array[b] = temp; |