Learn A New Language
June 25, 2010
There are hundreds, probably thousands, of programming language. Some are general-purpose, others are intended for a limited domain. Some are useful, most get in your way. Some are just weird. We programmers frequently have to learn a new language, or re-learn an old one, or adapt to improvements from the vendor.
A good way to learn a new language is to write in the new language a familiar program from an old language with which you are experienced. Many people have written that they use the exercises at Programming Praxis as a way to get started with a new language.
Your task is to write a program that solves the Programming Praxis exercise of your choice in a programming language in which you are not proficient. When you are finished, you are welcome to read or run a suggested solution, or to post your own solution or discuss the exercise in the comments below.
[…] Praxis – Learn A New Language By Remco Niemeijer The goal in today’s Programming Praxis exercise is to solve a previous exercise in a language you’re not […]
Steve Yegge’s Phone-Screen Coding Exercises using Ruby (see http://bonsaicode.wordpress.com/2010/06/25/programming-praxis-learn-a-new-language/ for a version with comments):
I did the Texas Hold’Em problem in Ruby. For the rest of the code go to http://codingjunkie.net
require ‘deck’
require ‘card’
require ‘player’
card_deck = Deck.new
keep_running = true
while keep_running
results = {}
card_deck.shuffle
seven_cards = card_deck.deal
seven_cards.sort!
copy = Array.new(seven_cards)
puts “Press enter to deal cards..”
line = gets
if line.chop == “quit”
keep_running = false
else
for i in 0..5
for j in i..5
copy.delete_at(i)
copy.delete_at(j)
hand = Player.check_hand(copy,0,0,nil)
if results[hand]
copy = Player.compare_hands(copy, results[hand], 4)
end
results[hand] = copy
copy = Array.new(seven_cards)
end
copy = Array.new(seven_cards)
end
max_score = -1
winning_hand = nil
best_cards = nil
results.each do |hand, cards|
score = Player.ranks[hand]
score = score.nil? ? cards[4].value : score
if score > max_score
max_score = score
score = Player.ranks[hand]
best_cards = cards
winning_hand = hand
end
end
puts “Best hand from #{seven_cards.join(“, “)} ”
puts “\n\t #{winning_hand} : #{best_cards.join(“, “)}”
end
end
The golden ratio exercise from July 10 2009 in Scheme, recursively:
and iteratively (I’ve started working my way through SICP as you can probably tell…):