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 11:03

Define LOC.

Name: Anonymous 2011-12-28 11:08

the fuck is LOC

Name: Anonymouse 2011-12-28 11:10

>>2,3
Level Of Cnowledge

Name: Anonymous 2011-12-28 11:21

Lines Of Code

Name: Anonymous 2011-12-28 11:28

>>5
Define "Lines Of Code".

Name: Anonymous 2011-12-28 11:32

(((9 div 9) - 9) + 9) = 1
(((9 + 9) div 9) mod 9) = 2
(((9 + 9) + 9) div 9) = 3
(9 - ((9 + 9) div 9)) = 7
(9 - ((9 div 9) mod 9)) = 8
(((9 - 9) * 9) + 9) = 9
(((9 div 9) mod 9) + 9) = 10
(((9 + 9) div 9) + 9) = 11
((9 - (9 div 9)) + 9) = 17
(((9 - 9) + 9) + 9) = 18
(((9 div 9) + 9) + 9) = 19
(((9 + 9) + 9) + 9) = 36
(((9 * 9) - 9) - 9) = 63
((9 - (9 div 9)) * 9) = 72
(((9 * 9) - 9) + 9) = 81
(((9 div 9) + 9) * 9) = 90
(((9 * 9) + 9) + 9) = 99
(((9 + 9) * 9) - 9) = 153
(((9 + 9) * 9) + 9) = 171
(((9 + 9) + 9) * 9) = 243
(((9 * 9) - 9) * 9) = 648
(((9 * 9) * 9) - 9) = 720
(((9 * 9) * 9) + 9) = 738
(((9 * 9) + 9) * 9) = 810
(((9 + 9) * 9) * 9) = 1458
(((9 * 9) * 9) * 9) = 6561

Name: Anonymous 2011-12-28 12:04

>>7
¿Code?

Name: Anonymous 2011-12-28 12:19

Putting this into code is dead hard, at least in only 50 lines. And even considering Assembly is crazy.

Name: Anonymous 2011-12-28 12:30

http://projecteuler.net/problem=93

Also it's very similar to this one. Very similar indeed, find the code for Euler n. 93 and adapt it to this one.

Name: Anonymous 2011-12-28 12:58

>>8
I didn't save it, it is just bruteforce, though. The main loop was something like this:
(let ((1op '(+ -)) (2op ('+ - mod div *)) (op1 (lambda (x) `(,x 9))) (op2 (lambda (f g) (lambda (x y) `(,f (,g ,x ,y))))))
  (append*
   (for*/list ((o1 1op) (o2 1op) (o3 1op)
               (o4 1op) (o5 1op) (o6 1op) (o7 1op)
               (f 2op) (g 2op) (h 2op))
     (let ((x (op1 o1)) (y (op1 o2)) (z (op1 o3)) (w (op1 o4))
           (f (op2 o5 f)) (g (op2 o6 g)) (h (op2 o7 h)))
       (list (f (g (h x y) z) w)
             (f (g x (h y z)) w)
             (f x (g (h y z) w))
             (f x (g y (h z w)))))))

Then the generated code was evaled, with mod and div returning 0 on bad inputs, filter non-exact-positive-integers, remove expressions with the same result, sort, pretty print.

Name: Anonymous 2011-12-28 13:00

>>8
I didn't save it, it is just bruteforce, though. The main loop was something like this:
(let ((1op '(+ -)) (2op ('+ - mod div *)) (op1 (lambda (x) `(,x 9))) (op2 (lambda (f g) (lambda (x y) `(,f (,g ,x ,y))))))
  (append*
   (for*/list ((o1 1op) (o2 1op) (o3 1op)
               (o4 1op) (o5 1op) (o6 1op) (o7 1op)
               (f 2op) (g 2op) (h 2op))
     (let ((x (op1 o1)) (y (op1 o2)) (z (op1 o3)) (w (op1 o4))
           (f (op2 o5 f)) (g (op2 o6 g)) (h (op2 o7 h)))
       (list (f (g (h x y) z) w)
             (f (g x (h y z)) w)
             (f x (g (h y z) w))
             (f x (g y (h z w)))))))

Then the generated code was evaled, with mod and div returning 0 on bad inputs, filter non-exact-positive-integers, remove expressions with the same result, sort, pretty print.

Name: Anonymous 2011-12-28 13:01

>>11-12
Sorry for the double post.

Name: Anonymous 2011-12-28 13:18

#! /usr/bin/env python

import sys
import operator
import itertools

operators = [
    operator.mul,
    operator.div,
    operator.mod,
    operator.add,
    operator.sub
]

otoa = {
    operator.mul : '*',
    operator.div : '/',
    operator.mod : '%',
    operator.add : '+',
    operator.sub : '-'
}

try:
    N = int(sys.argv[1])
except Exception as e:
    print >> sys.stderr, 'error: %s' % e
    print >> sys.stderr, 'usage: %s N' % sys.argv[0]
    exit(1)

numbers = {}

for (a, b, c) in itertools.product(operators, repeat=3):
    try:
        res = a(9, b(9, c(9, 9)))
    except:
        continue
    numbers[res] = (a, b, c)

for n in range(N+1):
    if numbers.has_key(n):
        (a, b, c) = numbers[n]
        print "%d = 9 %s (9 %s (9 %s 9))" % (
            n, otoa[a], otoa[b], otoa[c]
        )
    else:
        print n

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

Name: Anonymous 2011-12-28 17:12

(Bumping this thread; it's the only good one on the frontpage right now.)

Name: Anonymous 2011-12-28 17:23

>>15
You didn't find these because you're not checking (f (g x y) (h z w)).
Oh, right. Good catch.

Name: Anonymous 2013-09-01 20:22


C can be a bit understanding with pointers and assign things appropriately, but when you added another level (arrays) I think the assignment was forced into something that didn't work. That's my take on it. I think I will put up a bounty so you can get a better answer.

Name: Anonymous 2013-09-01 21:08



It’s from the Germanic root gel which has produced both English yellow and German gelb (OED).

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