[QUIZ] Hello, world? (#158)

I may have missed it, but I didn't see this solution:

require 'enumerator'
"Hello world!\n".enum_for(:each_byte).inject($stdout){|res, b| res << b.chr}

Which in 1.9 looks much better:

"Hello world!\n".each_char.inject($stdout){|res, c| res << c}

Stefano

Here's another in a similar vein to my previous one (oh for the good old days...)

charset= {
   :h=> [130,130,130,254,134,134,134,0],
   :e=> [254,128,128,248,192,192,254,0],
   :l=> [128,128,128,192,192,192,254,0],
   :o=> [126,130,130,134,134,134,252,0],
   :w=> [130,130,130,150,150,150,108,0],
   :r=> [252,130,130,252,194,194,194,0],
   :d=> [252,130,130,194,194,194,252,0],
   :space=> [0,0,0,0,0,0,0,0]}

msg= [:h,:e,:l,:l,:o,:space,:w,:o,:r,:l,:d]

def to_pixels val
   val.to_s(2).rjust(8,'0').gsub('0',' ').gsub('1','X')
end

0.upto(7) do |line|
   msg.each do |ch|
     print to_pixels(charset[ch][line])
   end
   puts
end

Cheers,
Dave

Here's my simple method_missing one :

class H
  @acc = 'H'
  
  def H.bang!
    puts @acc << " !"
  end
  
  def H.method_missing(m)
    @acc << m.to_s.sub(/_/, ' ')
    self
  end
end

H.e.l.l.o._.W.o.r.l.d.bang!

Fred

···

Le 01 mars à 01:06, Matthew D Moss a écrit :

--
Watch me, I'm coming closer I am the mood you're in tonight
Pretty poser, perfect armageddon bride I am a circle, it feels right
I am the one who swallows light Multiplying parasite
Perfect features, perfect sight (K's Choice, Hide)

A few basic ones that I haven't seen anyone submit yet.
#unicode
puts [72, 101, 108, 108, 111, 44, 32, 87, 111, 114, 108, 100, 33].pack('U*')

#longs.
puts [1214606444, 1865162839, 1869769828, 555753482].pack('N*')

#deltas.
c=0
puts [72, 29, 7, 0, 3, -67, -12, 55, 24, 3, -6, -8, -67].map{|i| (c+=i).chr}*''

-Adam

···

On 2/29/08, Matthew D Moss <matthew.moss@gmail.com> wrote:

Your task this week is to print "Hello, world!" to standard output
using Ruby in atypical fashion.

FYI, the summary is running a little late due to some personal
circumstances. It will show up later tonight or Friday morning.

How did you do that???
Amazing.
R.

···

On Sat, Mar 1, 2008 at 5:54 AM, Bill Kelly <billk@cts.com> wrote:

Greetings!

Here's the result of my quiz solution(s) so far:

$ ruby 158_hello_world.rb
Hello, World!
Hello, World!
Hello, World!
Hello, World!

<grin>

Regards,

Bill

--
http://ruby-smalltalk.blogspot.com/

---
Whereof one cannot speak, thereof one must be silent.
Ludwig Wittgenstein

I love the maze !

Can ruby solve it ?

Isn't that better suited for a pure functional language ?

···

2008/3/2, Bill Kelly <billk@cts.com>:

Greetings,

My quiz solution(s) are here:

http://tastyspleen.net/~billk/ruby/quiz/158-hello-world/158_hello_world.rb

I did five Hello World variations. Thus, the output of the program
when run, is simply:

Hello, World!
Hello, World!
Hello, World!
Hello, World!

Hello, World!

I think I had the most fun with #4, the maze solver:

m = <<MAZE
###+---+---+
^ H| l| o|
#| e| l| |
#+---+-+-+ |
#| d !*| , |
#| +--++ -+#
#|l | _ |#
#+--+ +-+ |#
####|r |W|#
##+-+- -+ |#
##| o |#
##+--+----+#
MAZE

Regards,

Bill

Wow. Your solutions are quite creative!

T.

···

On Mar 2, 5:21 pm, "Bill Kelly" <bi...@cts.com> wrote:

Greetings,

My quiz solution(s) are here:

http://tastyspleen.net/~billk/ruby/quiz/158-hello-world/158_hello_wor\.\.\.

I did five Hello World variations. Thus, the output of the program
when run, is simply:

Hello, World!
Hello, World!
Hello, World!
Hello, World!
Hello, World!

Awesome!

···

On Sun, Mar 2, 2008 at 11:21 PM, Bill Kelly <billk@cts.com> wrote:

Greetings,

My quiz solution(s) are here:

http://tastyspleen.net/~billk/ruby/quiz/158-hello-world/158_hello_world.rb

Jesse Merriman wrote:

## attempt 3

class Hello
  def method_missing m; print m; self; end
end

Hello.new.H.e.l.l.o.send(', ').w.o.r.l.d!.send("\n")

A variation:

def method_missing(*a) print *a end;h.e.l.l.o(", ").w.o.r.l.d("!\n")

···

--
       vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407

Nice.

Todd

···

On Sun, Mar 2, 2008 at 9:05 PM, Justin Ethier <justin.ethier@gmail.com> wrote:

Here's my solution:

hello, world = "", 2645608968345021733469237830984
(hello << (world % 256); world /= 256) until world == 0
puts hello

require 'net/http'
require 'uri'

···

#
# Google knows everything :wink:
#

gke_url = URI.parse("http://www.google.com")
gke = Net::HTTP.start(gke_url.host, gke_url.port) { |http|
  http.get("/search?q=ruby%20quiz%20158")
}
puts gke.body.match('\[<b>QUIZ<\/b>\]\s(\w+, \w+).+as often as you can(\W)')[1..2].join("")

Here's one:

puts DATA.read
__END__
Hello, World!

Best regards,

Jari Williamsson

Hello,
Sorry that this reply seems simple, but ruby is the first programming
language I've learned and I've only been practicing it for a few weeks.
this is what I came up with:

def hello
  a = ["H", "e", "l", "l", "o", ",", " ", "W", "o", "r", "l", "d", "!"]
  puts(a[0]+a[1]+a[2]+a[3]+a[4]+a[5]+a[6]+a[7]+a[8]+a[9]+a[10]+a[11]+a[12])
end

hello

···

--
Posted via http://www.ruby-forum.com/.

Rubén Medellín wrote:

···

On Feb 29, 6:06 pm, Matthew D Moss <matthew.m...@gmail.com> wrote:

The three rules of Ruby Quiz 2:

Please, don't ask me HOW i can sleep at nights....

Great. Now I can't sleep %-P

--
       vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407

Rubén Medellín wrote:

  

The three rules of Ruby Quiz 2:
    
Please, don't ask me HOW i can sleep at nights....

#--- BEGIN scary stuff

<snip>

#-- END scary stuff
  
I declare you the winner. Even though this isn't a competition. I thought there was something really messed up with the formatting until I actually ran it.

Wow. Many kudos to you.

-Justin

···

On Feb 29, 6:06 pm, Matthew D Moss <matthew.m...@gmail.com> wrote:

My 2 solutions:

['h','e','l','l','o',', ','w','o','r','l','d','!'].inject{|v, m| v + m}

# ---

module Hello; def self.included(klass); klass.hello ', world!'; end; end

class World
  def self.method_missing(method_name, *args)
    puts method_name.to_s + args[0]
  end
  include Hello
end

Regards.

···

--
"Computer science education cannot make anybody an expert programmer any more
than studying brushes and pigment can make somebody an expert painter."

(Eric Raymond)

+-------------------------------------+
Gastón Ramos


GNU/Linux Counter user #450312

Maybe, but I'd like to see some benchmarks myself...

Fred
}:>

···

Le 1 mars 2008 à 13:25, Robert Dober a écrit :

On Sat, Mar 1, 2008 at 5:54 AM, Bill Kelly <billk@cts.com> wrote:

Greetings!

Here's the result of my quiz solution(s) so far:

$ ruby 158_hello_world.rb
Hello, World!
Hello, World!
Hello, World!
Hello, World!

How did you do that???
Amazing.

--
If you see a long line of rats streaming off of a ship, the correct
assumption is *not* "gosh, I bet that's a real nice boat now that those
rats are gone". (Mike Sphar in the SDM)

Hi,

I love the maze !

Can ruby solve it ?

The code to solve the maze is included in the quiz solution, here:

http://tastyspleen.net/~billk/ruby/quiz/158-hello-world/158_hello_world.rb

See: Variation 4: Ambulatory greeting

Isn't that better suited for a pure functional language ?

Although I have books on Haskell and Erlang, I have only tinkered
with functional programming so far. However, there is definitely
nothing uncommon about solving mazes in an imperative programming
style.

The algorithm I used in the quiz was a very simplistic, non-recursive
breadcrumb approach.

Regards,

Bill

···

From: "Gaspard Bucher" <gaspard@teti.ch>

require 'net/http'
require 'uri'

#
# Google knows everything :wink:
#

gke_url = URI.parse("http://www.google.com")
gke = Net::HTTP.start(gke_url.host, gke_url.port) { |http|
  http.get("/search?q=ruby%20quiz%20158")
}
puts gke.body.match('\[<b>QUIZ<\/b>\]\s(\w+, \w+).+as often as you can(\W)')[1..2].join("")

Excellent !