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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T04:28:32+00:00 2026-05-30T04:28:32+00:00

How do I execute this code inside a Thread object? I want continuous execution,

  • 0

How do I execute this code inside a Thread object?

I want continuous execution, but I a have poor knowledge working with Thread objects. I have a Number class, which receives a number as a parameter.

If the number is even, do something, if odd, do something else, eventually what I am after is a continuous evaluation of the number within this framework of conditions with ‘number’ getting to 1. All elements are to be stored inside an array and querying the array.last to return 1.

class Number
  attr_accessor :x
  def initialize (number)
    @x=[] 
    if (number % 2 == 0)
      @x << number/2

    elsif (number % 2 != 0)
      @x << (number*3)+1
    end
    print  @x.to_s.concat(" ") // unable to continue

  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-05-30T04:28:33+00:00Added an answer on May 30, 2026 at 4:28 am

    I think this is what you are trying to do:

    def recurse(x, a = [])
      a << x
      return a if x == 1
      if x % 2 == 0
        recurse(x/2, a)
      else
        recurse((x*3 + 1)/2, a)
      end
    end
    
    recurse 7
    => [7, 11, 17, 26, 13, 20, 10, 5, 8, 4, 2, 1]
    
    recurse 12
    => [12, 6, 3, 5, 8, 4, 2, 1]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I run this code, will each AppDomain execute in a different thread? ThreadPool.QueueUserWorkItem(delegate
I have this program that should execute a piece of code base on the
I have a C# program that executes a thread. Inside this thread, I have
This is part of the code inside a thread (or it could be a
I have code like this: class Debug(object): ... @property def ThreadAwareLogger(self): if not self.logger_instance_for_current_thread:
I have to execute some code in the context of the main thread. I
With doctrine if you execute this code $columns = $accountTable->getColumns(); foreach ($columns as $column)
With this code: var db = google.gears.factory.create('beta.database'); db.open('cominar'); db.execute('CREATE TABLE IF NOT EXISTS Ajax
This bit of code is taking almost a half second to execute. Could somebody
I like my code formatted like this: WithDataContext.Execute( delegate(DataContext dataContext) { // code goes

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.