Skip to content

Instantly share code, notes, and snippets.

@mosinski
Created December 9, 2014 21:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mosinski/f3c12bc1b0bc97a6b522 to your computer and use it in GitHub Desktop.
Save mosinski/f3c12bc1b0bc97a6b522 to your computer and use it in GitHub Desktop.
zad13
#!/usr/bin/ruby
require 'active_support/all'
@a = Array(1..ARGV[0].to_i)
def funkcja1(i)
if index = @a.index(i)
temp = @a.take(index).combination(2).to_a.delete_if { |a| a.sum != i }
@a.delete(i) if temp.empty?
puts "Funkcja1 i: #{i}"
end
end
def funkcja2(i)
if index = @a.index(i)
temp = @a.take(index).combination(2).to_a.delete_if { |a| a.sum != i }
@a.delete(i) if temp.size > 1
puts "Funkcja2 i: #{i}"
end
end
for i in 3..ARGV[0].to_i
t1 = Thread.new{funkcja1(i)}
t2 = Thread.new{funkcja2(i)}
t1.join
t2.join
end
puts "U = #{@a.inspect}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment