943,749 Members | Top Members by Rank

Ad:
  • Ruby Discussion Thread
  • Unsolved
  • Views: 2277
  • Ruby RSS
May 21st, 2009
0

Ruby: Count to 1 Billion, basing from a C++ Code

Expand Post »
How long does it take to count 1 billion?
Determine the amount of time it takes the program.

Ruby Syntax (Toggle Plain Text)
  1. Int i,j,k, count=0;
  2. For (i=0; i<N; i++)
  3. For (j=0; j<N; j++)
  4. For (k=0; k<N; k++)
  5. count++

to complete in your programming environment, for N=1000, and 1000. If your compiler has optimization features that are supposed to make a program more efficient, check whether or not they do for this program.

However, this code below was the cheapest and the cheating way to fulfill how long will it count to 1Billion.
Ruby Syntax (Toggle Plain Text)
  1. for k in 1..1000000000
  2. print k," "
  3. end
  4. print "\n"

Note, this is my first time to get up close and personal with Ruby, not just the Ruby in RPG Maker XP.
Similar Threads
Reputation Points: 17
Solved Threads: 0
Newbie Poster
ClimaxBeetle is offline Offline
15 posts
since Mar 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Ruby Forum Timeline: WSDL and ruby
Next Thread in Ruby Forum Timeline: How to change the server port number in redmine





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC