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

  • Home
  • SEARCH
  • 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 8882045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:28:48+00:00 2026-06-14T20:28:48+00:00

file = File.open(file.dat) columns = [] file.each_line do |line| columns << line.split( )[0 ,

  • 0
file = File.open("file.dat")
columns = []
file.each_line do |line|
  columns << line.split(" ")[0 , 3]
end

print columns
true_columns = columns[8..37]
p true_columns

true_columns.each do |data|
  min_col = true_columns.min_by{|data| data[1].to_i - data[2].to_i}
  print min_col[0]
end

When I try to find the min difference between columns, I get 30 answers of the same exact thing.

print true_columns 
  => [["1", "88", "59"], ["2", "79", "63"], ["3", "77", "55"], ["4", "77", "59"], ["5", "90", "66"], ["6", "81", "61"], ["7", "73", "57"], ["8", "75", "54"], ["9", "86", "32*"], ["10", "84", "64"], ["11", "91", "59"], ["12", "88", "73"], ["13", "70", "59"], ["14", "61", "59"], ["15", "64", "55"], ["16", "79", "59"], ["17", "81", "57"], ["18", "82", "52"], ["19", "81", "61"], ["20", "84", "57"], ["21", "86", "59"], ["22", "90", "64"], ["23", "90", "68"], ["24", "90", "77"], ["25", "90", "72"], ["26", "97*", "64"], ["27", "91", "72"], ["28", "84", "68"], ["29", "88", "66"], ["30", "90", "45"]]

print min_col
  => ["14", "61", "59"]["14", "61", "59"]["14", "61", "59"]["14", "61", "59"]["14", "61", "59"]["14", "61", "59"]["14", "61", "59"]["14", "61", "59"]["14", "61", "59"]["14", "61", "59"]["14", "61", "59"]["14", "61", "59"]["14", "61", "59"]["14", "61", "59"]["14", "61", "59"]["14", "61", "59"]["14", "61", "59"]["14", "61", "59"]["14", "61", "59"]["14", "61", "59"]["14", "61", "59"]["14", "61", "59"]["14", "61", "59"]["14", "61", "59"]["14", "61", "59"]["14", "61", "59"]["14", "61", "59"]["14", "61", "59"]["14", "61", "59"]["14", "61", "59"]

print min_col[0]
  =>141414141414141414141414141414141414141414141414141414141414

How and why is the code coming up 30 times every time I print it? Thanks in advance.

  • 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-14T20:28:49+00:00Added an answer on June 14, 2026 at 8:28 pm

    The min_by method does all the looping. Change this bit:

    true_columns.each do |data|
      min_col = true_columns.min_by{|data| data[1].to_i - data[2].to_i}
      print min_col[0]
    end
    

    to

    min_col = true_columns.min_by{|data| data[1].to_i - data[2].to_i}
    p min_col
    

    See if that results in something useful.

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

Sidebar

Related Questions

open( my $handle, '<', 'file.dat' ) or die $!; my @data = map {
I am reading in data in the following format: {ok,Volts} = file:open(voltage1.dat,read). In the
i'm reading file which has some number of columns each line has different number
I'm struggling to open a file, and read each line until EOF. I'm using
fstream file; Patient Obj(XXX,'M',XXX); file.open(Patients.dat,ios::in|ios::out|ios::app); file.seekg(ios::end); file.write((char*)&Obj,sizeof(Obj)); file.seekg(ios::beg); Patient x; file.read((char*)&x,sizeof(x)); x.printallInfo(); file.close(); I'm
f= File.open('path_to_file','w') f.lineno #=> 0 f.gets #=>this is the content of the first line
The docs for django.core.files.File imply I can do this: print File(open(path)).url but the File
Here is my problem, I'm trying to read in data from a file beginningbalance.dat
I am trying to open a .dat file in Excel, which is tab delimited,
I have a file named data.dat with contents (sample): 0.0 2.3 4.5 0.9 0.5

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.