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
| import random | |
| import itertools | |
| # The function we want to minimise. Our function takes a 4-tuple of values. | |
| def f(tup): | |
| w, x, y, z = tup # This is called "tuple unpacking" | |
| return w + x + y + z | |
| # Here's a function that takes a tuple and returns True if it fits the constraints, | |
| # False otherwise. I've decided that there should be no more than 2 values > 50 in our |
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
| class Node | |
| attr_accessor :value # The value we're storing | |
| attr_accessor :next_node # The next node in the list, if any | |
| def initialize(new_value) | |
| @value = new_value | |
| @next_node = nil | |
| end | |
| 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
| files = [] | |
| puts "<background> | |
| <starttime> | |
| <year>2009</year> | |
| <month>08</month> | |
| <day>04</day> | |
| <hour>00</hour> | |
| <minute>00</minute> | |
| <second>00</second> | |
| </starttime>" |
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
| class Node | |
| attr_accessor :value | |
| attr_accessor :next, :previous | |
| def initialize(value) | |
| @value = value | |
| @next = nil | |
| @previous = nil | |
| end | |
| 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
| require 'test/unit' | |
| class TestStringReversal < Test::Unit::TestCase | |
| def setup | |
| @methods = self.methods.select {|name| name.to_s.include? "reverse"} | |
| end | |
| def test_string_reversal | |
| @methods.each {|method| |
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
| class Hotel | |
| DOUBLE_ROOM_CAPACITY = 2 | |
| SINGLE_ROOM_CAPACITY = 1 | |
| def initialize(double_count, single_count) | |
| @rooms = [] | |
| @capacity = 0 | |
| @guestbook = [] | |
| double_count.times do |
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
| # Add this to your .bashrc. | |
| parse_git_changes() { | |
| if [ -d .git ] || git rev-parse --git-dir > /dev/null 2>&1; then | |
| git update-index -q --refresh | |
| DIFFS=$(git diff-index --no-ext-diff --name-only HEAD --) | |
| LOCALS=$(git ls-files --exclude-standard --others) | |
| if [[ "$DIFFS$LOCALS" ]]; then | |
| echo "*" | |
| fi | |
| fi |