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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T22:55:33+00:00 2026-06-09T22:55:33+00:00

I am trying to do some math on a section of an array. And

  • 0

I am trying to do some math on a section of an array. And then I want to increment to do math on more of it. However I don’t know how to do it correctly.

The below code simply puts 3 columns of csv data into 1 array each. And then does math on it.

require 'csv'

csv_data = 'data.csv'

Location = []
  CSV.foreach(csv_data,'r') {|row| Location << row[0]}
Data1 = []
  CSV.foreach(csv_data,'r') {|row| Data1 << row[1]}
Data2 = []
  CSV.foreach(csv_data,'r') {|row| Data2 << row[2]}


index = 500
indexmax = 510


while index < indexmax
MathResults = Data1[index].to_f - Data2[index-1].to_f
index += 1
puts MathResults
end

If I put the MathResults above the while loop I obviously get the same result 10 times. If I put it in the loop I get 10 different results like I want but lots of errors with it that say:
warning: already initialized constant MathResults

I know this is still usable but the errors must be telling me I should be doing things differently.

So I was wondering if someone could tell me.

Thank you!

Edit: To add one thing. I realize I have 3 arrays and only 2 in use. The Location array is to later fill out the index variable after searching for the correct location. Instead of it saying just 500. Don’t worry about that.

  • 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-06-09T22:55:35+00:00Added an answer on June 9, 2026 at 10:55 pm

    You should probably use plain variable instead of constant (math_results instead of MathResults).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

With the below javascript code i am trying some BackboneJs concepts. Couldn't figure out
I'm trying to write some math code for a project and I stumbled upon
I'm trying to do some date math in Visual Basic. The NETWORKDAYS function in
I'm trying to do some very basic time math - basically, given inputs of
I was trying some problems with my 2D ruby array and my LOC reduces
This is my DjangoTemplates/(mysite)/index.html. I'm trying to do some math in my index.html. I
I am using SQL Server 2008. I am trying to do some basic math
Trying to do some really basic math here, but my lack of understanding of
I'm trying to do some simple math like $example = (12 - 4); but
I am trying to do some date math based on the week number 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.