Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Execute Ruby Online

# Hello World Program in Ruby
puts "Hello World!";
#Variables and expressions.
a = 10
b = 3 * a + 2
printf("%d %d\n", a, b);

# Type is dynamic.
b = "A string"
c = 'Another String'
print b + " and " + c + "\n"

nls reputatie

# Hello World Program in Ruby
def calculate_reputation(processed, delivered, unsubscribed, spamreports, bounced)
    delivery_rate = (delivered.to_f / processed) * 100
    unsubscribe_rate = (unsubscribed.to_f / delivered) * 100
    spamreports_rate = ((spamreports.to_f * 100) / delivered) * 100
    bounced_rate = ((bounced.to_f * 0.2) / processed) * 100
    
    puts 'delivery_rate:    %s%' % delivery_rate
    puts 'unsubscribe_rate: %s%' % unsubscribe_rate
    puts 'spamreports_rate: %s%' % spamreports_rate
    puts 'bounced_rate:     %s%' % bounced_rate

    [
      100,
      delivery_rate - unsubscribe_rate - spamreports_rate - bounced_rate
    ].min.ceil
end

reputation = calculate_reputation(
    processed=100, 
    delivered=80, 
    unsubscribed=0,
    spamreports=0,
    bounced=20)
puts '---------------'
puts 'raputation:        %s%' % reputation

odd_or_even?

def odd_or_even(number)
    if number % 2 == 0
        return "even"
    else
        return "odd"
    end
end

puts odd_or_even(2)

CCTest

# Hello World Program in Ruby
puts "Hello World!";

dfdf

# Hello World Program in Ruby
puts "Hello World!";

lab2

class MyArray < Array
    
    @@thread_number=3
    
    class ThreadPool
        
        def initialize(max_threads)
            @pool = SizedQueue.new(max_threads)
            max_threads.times{ @pool << 1 }
            @mutex = Mutex.new
            @threads = []
        end
        
        def run()
            @pool.pop
            @mutex.synchronize {
                @threads << Thread.start {
                    yield
                    @pool << 1
                }
            }
        end

        def await_completion
            @threads.each {|thread| thread.join}
        end
        
    end
    
    
    def using_thread()
        pool = ThreadPool.new(@@thread_number);
        
        self.each.with_index { |element, index| 
                pool.run{yield(element, index)}
        }
        pool.await_completion;
    end
    
  
    def map()
        answer=(1..self.length).map{|i| []};
        using_thread(){|element, batch_index| 
            answer[batch_index] << yield(element);
        }
        return answer.flatten(1);
    end
   
   
    def select()
        answer = []
        min_index=1000000;
        using_thread(){|element| 
            if yield(element)
                answer << element;   
            end
        }
        return answer;
    end
 
    def all()
        answer=true;
        using_thread(){|element| 
            if !yield(element)
                answer=false;
                return;
            end
        }
    end
    
    def any()
        answer=false;
        using_thread(){|element| 
            if yield(element)
                answer=true;
                return;
            end
        }
    end
    
end


 # Tests:
 a=MyArray.new([1, 2, 3, 4, 5]);
 print a.map(){|i| i+1};
 puts
 print a.select(){|i| i>=4}
 puts
 print a.all? {|i| i!=0} 
 puts
 print a.any? {|i| i==4} 
 

RubyFile

# Hello World Program in Ruby
puts "Hello World!";

eduardas

# Hello World Program in Ruby

gamers_t1 = %w[a b c d e f g].shuffle
gamers_t2 = %w[h i j k l m n].shuffle

t1,t2=[],[]
gamers_t1.each.with_index(1) do |e, i|
    (i % 2 == 0 ? t1 : t2) << e
end

gamers_t2.each.with_index(1) do |e, i|
    (i % 2 != 0 ? t1 : t2) << e
end


puts 'Team1'
print t1
puts ''
puts ''
puts 'Team2'
print t2

Execute Ruby Online

@tab = Array.new(3) {Array.new 3, rand(0..1)}
for i in([email protected])
      for j in ([email protected])
        print "#{@tab[i][j]}\s"
      end
      print "\n"
    end

print "\n"

@tab.each_index do |x|
    subtab = @tab[x]
    vec = @tab[x]
    a = vec[x] + 1
    print "#{vec[x]}\s" << a
    subtab.each_index do |y|
        
    #    print "#{@tab[x][y]}\s"
    end
    print "\n"
end

asdasdasdasd

if true
  asd = 2
else
  asd = 3
end

puts asd

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.