Randomly selected coin and lighter/heavier its value with Ruby:
# frozen_string_literal: true
# Save file as coins.rb and run `ruby coins.rb`
def initialize(place, value)
@coins = Array.new(7, 1).insert(place, value)
@count = 0
return puts @count if @coins.size == 1
@count += 1
step = @coins.size / 2
first = @coins.first(step)
last = @coins.last(step)
@coins = first.sum > last.sum ? first : last
Coins.new(rand(0..7), [0, 2].sample).weight
We're a place where coders share, stay up-to-date and grow their careers.
We strive for transparency and don't collect excess data.