Skip to content

Instantly share code, notes, and snippets.

@countries = ["Brazil", "Cameroon", "Chile", "Greece", "Uruguay", "Italy", "France", "Bosnia and Herzegovina", "Germany", "USA", "Russia", "Croatia", "Spain", "Australia", "Cote d'lvoire", "Costa Rica", "Switzerland", "Honduras", "Iran", "Portugal", "Belgium", "Korea Republic", "Mexico", "Netherlands", "Colombia", "Japan", "England", "Ecuador", "Argentina", "Nigeria", "Ghana", "Algeria" ]
@is_used = Array.new(@countries.length, false)
@max_loop_count = 0
def search (country, loop_count)
is_last = true
@countries.each_with_index do | country2, index2|
next if @is_used[index2]
if country2[0] == country[-1].upcase
is_last = false
@countries = ["Brazil", "Cameroon", "Chile", "Greece", "Uruguay", "Italy", "France", "Bosnia and Herzegovina", "Germany", "USA", "Russia", "Croatia", "Spain", "Australia", "Cote d'lvoire", "Costa Rica", "Switzerland", "Honduras", "Iran", "Portugal", "Belgium", "Korea Republic", "Mexico", "Netherlands", "Colombia", "Japan", "England", "Ecuador", "Argentina", "Nigeria", "Ghana", "Algeria" ]
@is_used = Array.new(@countries.length, false)
@max_loop_count = 0
def search (country, loop_count)
is_last = true
@countries.each_with_index do | country2, index2|
next if @is_used[index2]
if country2[0] == country[-1].upcase
is_last = false
# include integer part
answer_including_integer_part = 0
n = 0
while answer_including_integer_part == 0
n += 1
target_numbers = ('%10.10f'%Math.sqrt(n)).to_s.sub('.' ,'').split("")[0..9]
if target_numbers.uniq.length == 10
@memo = {}
def Fibonacci_number(n)
if n == 0 or n == 1
return @memo[n] = 1
end
(2..n).each do |i|
@memo[i] = @memo[i-1] + @memo[i-2]
end
@memo = {}
def Fibonacci_number(n)
return @memo[n] if @memo.has_key?(n)
if n == 0 or n == 1
return @memo[n] = 1
end
@memo[n] = Fibonacci_number(n-1) + Fibonacci_number(n-2)
@memo[n]
def Fibonacci_number(n)
if n == 1 or n == 2
return 1
end
Fibonacci_number(n-1) + Fibonacci_number(n-2)
end
answers = []
n = 2
def Fibonacci_number(n)
if n == 1 or n == 2
return 1
end
Fibonacci_number(n-1) + Fibonacci_number(n-2)
end
answers = []
n = 2
boys , girls = 20,10
answers = Array.new( boys + 1){
Array.new(girls + 1, 0)
}
answers[0][0] = 1
(boys + 1).times do | boy |
(girls + 1).times do | girl |
if ( boy != girl ) and ((boys - boy) != (girls - girl))
@cnt = 0
def change(target, coins, usable)
coin =coins.shift
if coins.size == 0 then
@cnt += 1 if target/coin <= usable
else
(0..target/coin).each do |i|
change(target - coin * i, coins.clone,usable -i )
end
end
coins = [10, 50, 100, 500]
cnt = 0
(2..15).each do |i|
coins.repeated_combination(i).each do |coin_set|
cnt += 1 if coin_set.inject(:+) == 1000
end
end
puts cnt