ruby - Finding in txt specific chars by index -


i have problem ruby homework.

there txt file 1000 chars (one per each line)
program asks user 9 numbers 0..999
after should find , print 9 chars file

example output
give 1. number between 0-999: 444
give 2. number between 0-999: 756
give 3. number between 0-999: 223
give 4. number between 0-999: 999
give 5. number between 0-999: 0
give 6. number between 0-999: 123
give 7. number between 0-999: 23
give 8. number between 0-999: 44
give 9. number between 0-999: 533
word ryqbaasqn

here code

#coding:utf-8 path = "7-3_tiedosto.txt" lst = array.new  word = array.new text = ""  puts "luodaan salasana."  in 1..9    print "anna #{i}. luku väliltä 0-999: "    lst.push(gets.to_i) end  = file.open(path, "r") my.each{|line| word.push(line.chomp)} my.close  in 0..8    = lst[i]       text = text << word[a] end  puts "ohjelma loi salasanan #{text}" 

this looks opportunity familiarize ruby debugging. issues these arise when program state different expected. it's figure out why state different expect , take corrective action.

i'd recommend trying either 1) using put statements print out program state while program executing or 2) use ruby debugger step through program running verify state.

here's primer on debugging: http://ruby.about.com/od/advancedruby/a/debugging.htm

hope helps! these kinds of issues come time, it's important learn how approach them. best of luck.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -