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 7506633
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:19:22+00:00 2026-05-29T22:19:22+00:00

I’m trying to write a small baseball statistics program using data from retrosheet.org, but

  • 0

I’m trying to write a small baseball statistics program using data from retrosheet.org, but I’m having trouble parsing their line score data. In a game where a team does not score double digits in any particular inning, their line score would look like this 001003000 (they scored 1 run in the third inning, and 3 runs in the sixth). If, however, a team scores double digit runs, the data will look like this 00100(10)000 (1 run in the third, and 10 runs in the sixth).

For now, I’m just trying to parse out the score for each inning and put it in an array. Here’s what I have so far:

scores = %w{00100300800 32004300X 00(11)34000 0000(15)000X 0000(15)000(13) 10(18)47(11)8(10)3}

scores.each do |s|
  game = []
  if s.include? "("
    # HELP!
  else 
    s.each_char { |c| game << c }
  end
  puts game.join("+")
end

I’m sure the solution involves regex, which I’m terrible at, so I’ve been trying all sorts of terrible string manipulation methods. In the end, I think it’s going to be better to just ask for help.

So, how would you guys do this?

  • 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-29T22:19:23+00:00Added an answer on May 29, 2026 at 10:19 pm

    You can parse those with scan:

    s.scan(/\(\d+\)|\d/)
    

    For example:

    >> scores = %w{00100300800 32004300X 00(11)34000 0000(15)000X 0000(15)000(13) 10(18)47(11)8(10)3}
    >> scores.each { |s| puts s.scan(/\(\d+\)|\d/).inspect }
    ["0", "0", "1", "0", "0", "3", "0", "0", "8", "0", "0"]
    ["3", "2", "0", "0", "4", "3", "0", "0"]
    ["0", "0", "(11)", "3", "4", "0", "0", "0"]
    ["0", "0", "0", "0", "(15)", "0", "0", "0"]
    ["0", "0", "0", "0", "(15)", "0", "0", "0", "(13)"]
    ["1", "0", "(18)", "4", "7", "(11)", "8", "(10)", "3"]
    

    And then just strip off the parentheses and call to_i:

    s.scan(/\(\d+\)|\d/).map { |s| s[/\d+/].to_i }
    

    For example:

    >> scores.each { |s| puts s.scan(/\(\d+\)|\d/).map { |s| s[/\d+/].to_i }.inspect }
    [0, 0, 1, 0, 0, 3, 0, 0, 8, 0, 0]
    [3, 2, 0, 0, 4, 3, 0, 0]
    [0, 0, 11, 3, 4, 0, 0, 0]
    [0, 0, 0, 0, 15, 0, 0, 0]
    [0, 0, 0, 0, 15, 0, 0, 0, 13]
    [1, 0, 18, 4, 7, 11, 8, 10, 3]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
We're building an app, our first using Rails 3, and we're having to build
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I want to construct a data frame in an Rcpp function, but when I
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but

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.