Assigned seats + missing ticket puzzle

I just came across this tweet and thought it would be fun to share here:

It looks like some people in the Twitter replies have already come up with a solution, but I thought it would be a fun puzzle nonetheless!

Did you find this post useful? Show some love!

Here's my simulation in Ruby. I know that one million is overkill, Lol

Spoilers below โ†“

class Threater
  def self.run(iterations = 1_000_000)
    last_person_got_seat = 0.0
    total_runs = 0.0

    iterations.times do |i|
      if i % 1000 == 0
        print("\rNยบ of iterations: #{i.to_s.ljust(iterations.to_s.length)}")
      end
      last_person_got_seat += 1 if new.last_person_got_seat
      total_runs += 1
    end

    last_person_got_seat / total_runs
  end

  def initialize(threater_size = 100)
    @seats = [nil] * threater_size
    @seats[random_seat] = 0 # 1st in line lost her ๐ŸŽŸ

    (1...threater_size).to_a.each do |person_seat|
      seat_person(person_seat, person_seat)
    end
  end

  def last_person_got_seat
    @seats.last == 99
  end

  private

  def random_seat
    rand(0...@seats.length)
  end

  def seat_person(seat, person)
    if @seats[seat]
      seat_person(random_seat, person)
    else
      @seats[seat] = person
    end
  end
end


result = Threater.run
puts "\nResult: #{result}%"

It's 50%, apparently!

When the 100th person enters, the occupied seats are 99, so the seat is either his or it isn't. Hence 50%, matches with the twitter feed. Not sure if this approach is right though.

Classic DEV Post from Jun 3

What's your opinion on Microsoft's GitHub Acquisition?

The Verge just reported that Microsoft has acquired GitHub.

READ POST
dev.to is now open source!
View Announcement Post View GitHub Repo
Peter Kim Frank
Working on dev.to. Previously: on-demand tutoring and textbooks. Before that, ran/sold an online community and worked for the company that built Tinder. ๐Ÿ˜Ž
More from @peter
Project Euler #3 - Largest Prime Factor
#projecteuler #challenge
Project Euler #2 - Even Fibonacci numbers
#projecteuler #challenge
Trending on dev.to
How many computers do you use?
#discuss
Software Made Simple
#design #simple #productivity #devtips
How Do You Really Get Hired?
#careers #beginners #discuss
Style your Terminal better by mastering these settings ๐Ÿคฉ
#terminal #productivity #tools #webdev
What productivity tools/hacks do you find most effective for your day-to-day?
#discuss #productivity
What is your task management process? Do you use trello, asana, calendar etc or a hybrid? And how?
#productivity #tools
What are common myths about software careers?
#discuss #career
What's your origin story?
#career #learn #webdev