Skip to content

Instantly share code, notes, and snippets.

@ivyl
Created November 23, 2008 14:01
Show Gist options
  • Save ivyl/28118 to your computer and use it in GitHub Desktop.
Save ivyl/28118 to your computer and use it in GitHub Desktop.
Python Challange solutions in Ruby
#!/usr/bin/env ruby
require 'rubygems'
require 'open-uri'
require 'RMagick'
pixel = [Magick::Pixel.new(0, 0, 0)]
path = open('http://www.pythonchallenge.com/pc/return/cave.jpg', :http_basic_authentication => ["huge", "file"]).path
cat = Magick::ImageList.new(path).first
cat.columns.times do |column|
cat.rows.times do |row|
cat.store_pixels(column, row, 1, 1, pixel) if column.odd? && row.even? or column.even? && row.odd?
end
end
cat.display
#!/usr/bin/env ruby
require 'open-uri'
array = [[],[],[],[],[]]
open("http://www.pythonchallenge.com/pc/return/evil2.gfx", :http_basic_authentication => ["huge", "file"]).read.split(//).each_with_index{|l, i| array[i%5] << l}
array.each_with_index{|a, i| File.new("#{i+1}.jpg", "w").write(a.join(''))}
#!/usr/bin/env ruby
require 'xmlrpc/client'
require 'open-uri'
name = open("http://www.pythonchallenge.com/pc/return/evil4.jpg", :http_basic_authentication => ["huge", "file"])
puts XMLRPC::Client.new2("http://www.pythonchallenge.com/pc/phonebook.php").call("phone", name.read.match(/[A-Z]\w+/)[0])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment