The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
Rubyize This: Live in Vancouver. Refactoring #2

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Scott Patten

Posts: 43
Nickname: spatten
Registered: Jan, 2008

Scott Patten is a freelance web developer and Ruby on Rails trainer based in Vancouver
Rubyize This: Live in Vancouver. Refactoring #2 Posted: Jan 26, 2008 7:34 PM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Scott Patten.
Original Post: Rubyize This: Live in Vancouver. Refactoring #2
Feed Title: Scott Patten's Blog
Feed URL: http://feeds.feedburner.com/scottpatten.ca
Feed Description: Scott Patten is the cofounder of Ruboss (http://ruboss.com) and Leanpub (http://leanpub.com), both based in Vancouver. He is also the author of The S3 Cookbook (http://leanpub.com/thes3cookbook). He blogs about Startups, Ruby, Rails, Javascript, CSS, Amazon Web Services and whatever else strikes his fancy.
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Scott Patten
Latest Posts From Scott Patten's Blog

Advertisement
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/env ruby

require 'pp'

BIG_NUMBER = 32768

# Get data from a file, turn it in to a float, and find the max
data = File.readlines('random.txt')
max = -BIG_NUMBER
for n in (0 ... data.length)
  data[n] = data[n].chomp.to_f
  if data[n] > max
    max = data[n].to_i + 1 # max is ceil(max(data[n]))
  end
end

# Create the empty histogram
histogram = []
for n in (0 ... max)
  histogram.push(0)
end

# Fill the histogram
for n in (0 ... data.length)
  histogram[data[n].to_i] += 1
end

# Print the histogram
pp histogram
puts
for n in (0 ... max)
  puts "*" * histogram[n]
end

Read: Rubyize This: Live in Vancouver. Refactoring #2

Topic: Ruby/Rails Conferences Previous Topic   Next Topic Topic: Quote of the Week: George Orwell

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use