Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 845063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T06:23:11+00:00 2026-05-15T06:23:11+00:00

I am setting up a World Cup Challenge between some friends, and decided to

  • 0

I am setting up a World Cup Challenge between some friends, and decided to practice my Ruby and write a small script to automate the process.

The Problem:

  • 32 World Cup qualifiers split into 4 tiers by their Fifa ranking
  • 8 entries
  • Each entry is assigned 1 random team per tier
  • Winner takes all 🙂

I wrote something that suffices yet is admittedly brute force. But, in my attempt to improve my Ruby, I acknowlege that this code isn’t the most elegant solution around – So I turn to you, the experts, to show me the way.

It may be more clear to check out this gist – https://gist.github.com/91e1f1c392bed8074531

My Current (poor) solution:

require 'yaml'

@teams = YAML::load(File.open('teams.yaml'))
@players = %w[Player1 Player2 Player3 Player4 Player5 Player6 Player7 Player8]

results = Hash.new
players = @players.sort_by{rand}

players.each_with_index do |p, i|
  results[p] = Array[@teams['teir_one'][i]]
end

second = @players.sort_by{rand}
second.each_with_index do |p, i|
  results[p] << @teams['teir_two'][i]
end

third = @players.sort_by{rand}
third.each_with_index do |p, i|
  results[p] << @teams['teir_three'][i]
end

fourth = @players.sort_by{rand}
fourth.each_with_index do |p, i|
  results[p] << @teams['teir_four'][i]
end

p results

I am sure there is a better way to iterate through the tiers, and duplicating the @players object ( dup() or clone() maybe?)

So from one Cup Fan to another, help me out.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T06:23:13+00:00Added an answer on May 15, 2026 at 6:23 am

    I’m still learning Ruby too, but here’s an attempt:

    require 'yaml'
    
    tiers   = YAML::load(File.open('world_cup_tiers.yaml'))
    players = %w[P1 P2 P3 P4 P5 P6 P7 P8]
    
    draws = Hash.new { |h,k| h[k] = [] }
    
    tiers.each do |tier, teams|
        players.zip(teams.sort_by{rand}).each do |tuple|
            player, team = tuple
            draws[player].push(team)
        end
    end
    
    players.each { |player| puts [player, draws[player]].join(' ') }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need some help setting up a particular terrain. I have a world that
I'm in the process of setting up a new website which would greatly benefit
I am new in android world. When I create a project while setting Target
Some popular words, like food, are used all over the world as loan words.
I am venturing into the world of setting up cronjobs and trying to learn
I'm having a very small problem with my Rails App. I'm setting up a
I went through the process of setting this up once, but now I need
I would like to have an .emacs setting so that tabs are always formed
How would I go about setting a link to perform certain functions like hide
What tools would you recommend for setting up CI for build and deployment of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.