Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Plagiarized challenge for /prgo/

Name: Anonymous 2011-12-28 10:48

Someone posted a challenge for perl6, and one of those challenges is this->
http://strangelyconsistent.org/p6cc2011/t1-description

I recognize that I HAVE NO FUCKING IDEA HOW TO START...
So, let's plagiarize this and start a good challenge for /porg/, but with these rules

* Any language u want
* 50 LOC maximum (unless is asm)

Name: Anonymous 2011-12-28 17:04

>>11-12
You forgot some:
(9 * 9) - (9 / 9) = 80
(9 * 9) + (9 / 9) = 82
(9 * 9) + (9 * 9) = 162
(9 + 9) * (9 + 9) = 324


You didn't find these because you're not checking (f (g x y) (h z w)).

My code (Ruby 1.9):
# Quick hack: we want float division
class Fixnum; def /(other); fdiv(other); end; end
ops = %w(% / * - +); exps = []

# Brute force all solutions (no negatives needed)
ops.product(ops, ops) do |o1, o2, o3|
  exps << "9 #{o1} (9 #{o2} (9 #{o3} 9))"
  exps << "9 #{o1} ((9 #{o2} 9) #{o3} 9)"
  exps << "(9 #{o1} (9 #{o2} 9)) #{o3} 9"
  exps << "((9 #{o1} 9) #{o2} 9) #{o3} 9"
  exps << "(9 #{o1} 9) #{o2} (9 #{o3} 9)"
end

# Make a hash out of them
solutions = Hash[exps.map { |i| [((eval i).to_f rescue next) , i] }]

# Read N, list solutions 0..N
(0..gets.to_i).each do |i|
  j = solutions[i.to_f]
  puts j ? "#{i} = #{j}" : i
end

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List