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 cartprod(*args) | |
| result = [[]] | |
| while [] != args | |
| t, result = result, [] | |
| b, *args = args | |
| t.each do |a| | |
| b.each do |n| | |
| result << a + [n] | |
| 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
| def permute(*args) | |
| # filter the arguments | |
| args.reject! {|x| !x.is_a?(Array) || x.empty?} | |
| # get the number of all combinations | |
| total = args.inject(1) {|total, array| total * array.size} | |
| # prepare the small_cycles array to know how many times | |
| # one element should be repeated in a loop |
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 File.expand_path(File.dirname(__FILE__) + "/../test_helper") | |
| include Test::Unit::UserStory | |
| story "Create the thing", %{ | |
| As a user | |
| I want to create something | |
| In order to show something | |
| } do | |
| criteria "without js when logged in" 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
| module Test::Unit::UserStory | |
| class UserStoryTestCase < ActionController::IntegrationTest | |
| class << self | |
| attr_accessor :description | |
| alias :it :test | |
| def criteria(name, options = {}, &block) | |
| klass = create_class(name, self, &block) | |
| helper_klass = options[:js] ? CapybaraJavascriptTestHelper : CapybaraTestHelper |
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
| bar.receive_order(client.put_words_in_mouth('Un croissant, por favor.').speak_up) |
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
| :- lib(ic). | |
| croissant(X,Y,Z) :- | |
| (X^2+Y^2+Z^2+7*sqrt(5)/2-11/2)^2 - ((1+sqrt(5))*X-7+3*sqrt(5))^2-(1+sqrt(5))^2*Y^2 $= 0, | |
| locate([X,Y,Z], 1e-5). | |
| # one of the solutions | |
| croissant(X,Y,Z). | |
| X = X{0.0 .. 7.4073630564431975e-6} | |
| Y = Y{1.066573563196598 .. 1.0665754743970506} |
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 permute(*args) | |
| # initialize the register for each array | |
| # with [array itself, offset, its size] | |
| memory = [] | |
| perm_count = 1 | |
| args.each do |array| | |
| size = array.size | |
| memory << [array, 0, size-1] |
NewerOlder