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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T05:56:11+00:00 2026-06-09T05:56:11+00:00

I’ve written the program below previously in Basic and Pascal, now I’m porting it

  • 0

I’ve written the program below previously in Basic and Pascal, now I’m porting it to Ruby. The puts in lines 20..26 stand in for what were calls to subroutines (gosub..return) in basic and pascal. I don’t find subroutines in Ruby. Would I create a method for each of these? The subroutines are graphical displays, manipulations of the brain matrix, etc. It’s important that when they finish, I return to the same spot.

(If it is useful: external events, e.g., key presses, put values in the stimulus matrix, that, when multiplied by the brain matrix generate the values in the behavior matrix.)
A more elegant way of doing lines 20..26 is also welcome.

Thanks.

require 'matrix'
class Matrix
  def []=(i, j, x)
    @rows[i][j] = x
  end
end #code to allow putting individual elements in matrix at i,j

brain=  Matrix[ [0,0,0,0,99,0,0,0,0,1,0],
            [0,0,0,0,0,99,0,0,0,1,0],
            [0,0,0,0,0,0,99,0,0,1,0],
            [25,0,0,0,0,0,0,1,-1,1,-99],
            [0,23,0,0,0,0,0,1,-1,1,1],
            [0,0,24,0,0,0,0,1,-1,1,1],
            [0,0,0,22,0,0,0,1,-1,1,1] ]
stimulus=Matrix.column_vector([0,0,0,0,0,0,0,0,0,0,0])
behavior=Matrix.column_vector([0,0,0,0,0,0,0])

t=500 # t=threshold
behavior=brain*stimulus
if behavior[0,0] > t then puts "do poistive fixer" end
if behavior[1,0] > t then puts "do negative fixer" end
if behavior[2,0] > t then puts "show UCR" end
if behavior [3,0] > t then puts "show operant 1" end
if behavior[4,0] > t then puts "show operant 2" end
if behavior[5,0] > t then puts "show operant 3" end
if behavior[6,0] > t then puts "show operant 4" end
  • 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-09T05:56:13+00:00Added an answer on June 9, 2026 at 5:56 am

    Yes, a method is a reusable chunk of code, just like a subroutine.

    The quickest refactor of 20-26 would look like this:

    puts "do positive fixer" if behavior[0,0] > t
    puts "do negative fixed" if behavior[1,0] > t
    

    Whether or not you prefer the minimal savings is a matter of opinion.

    The next level of refactoring might be as simple as putting the strings in an array (untested but close):

    do_this = [ "do positive fixer", "do negative fixer", ... ]
    (0..6).each { |n| puts do_this[n] if behavior[n, 0] > t }
    

    As Tin Man notes you could use the array directly:

    do_this.each_with_index { |s, n| puts s if behavior[n, 0] }
    

    Etc.

    • 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
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
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.