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

Pages: 1-4041-

New coding contest

Name: Anonymous 2009-11-28 15:49

We haven't had one in a while so let's have a new coding contest. I'm open to suggestions for the challenge, but if we don't have any good suggestions we will default to something stupid like "implement cowsay in erlang shitty language X".

Name: Anonymous 2009-11-28 15:51

How 'bout a game?

Name: Anonymous 2009-11-28 15:52

>>2
It would need to be a simple game, the usual time limit is 24 hours.

Name: Anonymous 2009-11-28 15:56

FIBS!

Name: Anonymous 2009-11-28 16:03

How about a (very simple) mud server in your language of choice?

Name: Anonymous 2009-11-28 16:06

>>5
FIBS!
FIBS
FIBS!

Name: Anonymous 2009-11-28 16:10

A C preprocessor or a sudoku solver

Name: Anonymous 2009-11-28 16:12

>>3
make a better version of excellent quest!

Name: Anonymous 2009-11-28 16:17

How about pong? 24 hours to make the smallest, most complex, or retarded version of pong you can.

Name: Anonymous 2009-11-28 16:24

>>2
here
>>3
I was thinking: minesweeper in console/terminal

lol

Name: Anonymous 2009-11-28 16:26

||
||
||
||
||
||
||
||
||
||

Name: Anonymous 2009-11-28 16:28

>>1-11

Shut up.

We're making Tetris.
Get to work.

Name: Anonymous 2009-11-28 16:29

>>12
count me out

Name: Anonymous 2009-11-28 16:39

>>13
is not an [b][i][u]EXPERT PROGRAMMER[/b][/i][/u].

Name: Anonymous 2009-11-28 16:41

>>14
and neither am I, apparently.

Name: Anonymous 2009-11-28 16:45

Let's do a Fibonacci Tetris Mud server.
Implementation details are left as an exercise to the contestant.

Name: Anonymous 2009-11-28 16:48

>>14
it's not that, I just hate tetris.

Name: Anonymous 2009-11-28 16:55

>>16

You find yourself trapped in a pit, deep and square.
Blocks are falling from the sky. One reaches the ground and blasts your ears with a resounding thud. You shiver.
The next block appears to be more complex than the last one, and the one after that appears to be more complex than that one. You do not think this cycle will end.
Obvious exits are UP.
_

Name: Anonymous 2009-11-28 17:02

UP⏎

Name: Anonymous 2009-11-28 17:16


You cannot fly!
You turn around just as another block lands by your feet. It suddenly occurs to you that there is little time before a block will try to occupy the same space as your body and crush it.
_

Name: Anonymous 2009-11-28 17:23

The next block appears to be more complex than the last one
And what does it mean for a block to be more complex than another I wonder

Name: Anonymous 2009-11-28 17:28

>>21
They are fractals. Fancy that.

Name: Anonymous 2009-11-28 17:38

maybe we should form a "/prog/ contest comitee".

i vote for the fucked up tetris.

Name: Anonymous 2009-11-28 17:52

>>23

Sign me up.

Fibonacci tetris pong, perhaps?

Name: Anonymous 2009-11-28 18:02

>>24
So pong, but instead of a ball you have a tetromino (or however the fuck that's spelt), and each time it hits off a bat, the previous number is added to the mix?

Name: Anonymous 2009-11-28 18:03

Given a function fibs(int n):int, that returns the n'th fibonacci number, write a function sumFibs(int n):int, that returns the sum of the first n fibonacci numbers with only one call to fibs and no loops or recursion.

Name: Anonymous 2009-11-28 18:04

4D Pong

Name: Anonymous 2009-11-28 18:15

>>26
Yeah, I remember doing that when I was 12.

Name: Anonymous 2009-11-28 18:15

>>26
Clever

Name: Anonymous 2009-11-28 18:20

>>25

I was thinking along the lines of playing pong and tetris at the same time. Whenever you miss a ball in pong, another garbage line is added to the game of tetris. Every time you gain a level in tetris, the number of balls becomes the next fibonacci number, but you need to have that number of balls scored against you to have a line added. Speed increases in both games with each level.

For example, on level 8 of tetris, you would have 21 balls on screen at once, and every 21st point scored against you would add a garbage line to the tetris playfield.

Name: Anonymous 2009-11-28 18:21

>>30

Actually, I don't care what the contest is, I'm making Fibbopongtris.

Name: Anonymous 2009-11-28 18:26

Now we just need FV (or MDickie) to lead the team, and we're set.

Name: OP 2009-11-28 18:33

Since we can't seem to get a consensus on anything other than fibs and the weird tetris is unlikely to be doable in a day. I'm just going to go with the default.

Implement Cowsay or equivalent program for a different animal (e.g tablecats). It must support the -n command line option. The text lines must wrap at 40 characters by default, and may be overriden by a -W flag. All other details are optional, but highly recommended. For more information, please see man cowsay

Name: OP 2009-11-28 18:34

You have 24 hours, gentleman.
Best of luck.

Name: Anonymous 2009-11-28 18:35

>>33

Fuck you, nigger, I'm doing Fibbopongtris.

Name: Anonymous 2009-11-28 18:36

>>33
So fibbopongtris it is! *grabs opengl*

Name: Anonymous 2009-11-28 18:38

>>35,36
Assuming you do it in a day, you win. The purpose of this thread wasn't to make something useful, but just to counter some of the spam that gets posted and to get people to post code for a change

Name: Anonymous 2009-11-28 18:44

>>37
So why are you saging a non-spam thread then?

Hell, I bumped the duck typing thread because it was less spammy than average.

Name: Anonymous 2009-11-28 18:45

>>38
So why are you saging
Habit

Name: Anonymous 2009-11-28 19:02

Alright, so when does this thing begin?  Is that guy going to tell us when we have 24 hours?

Name: Not OP 2009-11-28 19:04

>>40

You have until Midnight Monday, EST.
Go.

Name: Anonymous 2009-11-28 22:35

>>26
Bitches don't know about my second identity

Name: Anonymous 2009-11-29 0:01

>>37
Hax my anus

Name: Anonymous 2009-11-29 0:18

>>40

You have 24 hours from the time that you comprehend the task

This is an honor system designed to give each coder 24 hours, rather than the idea.

Name: Haxxus the Tetris 2009-11-29 0:20

>>41
Well fuck it, I'm starting.  Monday at 12:00 AM EST it is.

Name: Anonymous 2009-11-29 0:48

I will not do anything involving tetris, fibs or pong. I might write a mud server. However, I will, in the spirit of this thread, write something I otherwise wouldn't have by Monday at 00:00 EST. (I may or may not post it here.)

Name: Anonymous 2009-11-29 1:36

>>46
I'm writing Tetris.  I say we all just do whatever the fuck we want.

Name: Anonymous 2009-11-29 1:41

>>46
So... you'll write Tetris, fibs, or Pong?

Name: Anonymous 2009-11-29 1:47

>>48
no, by "otherwise wouldn't have" I mean something unscheduled, as opposed to atypical.

Name: Anonymous 2009-11-29 18:27

So did anyone bother?

Name: Anonymous 2009-11-29 18:39

>>50
Kind of.  I am too crappy of a programmer to have finished my Tetris game by now though.

Name: Leah Culver !1LEahRIBg. 2009-11-29 18:49

Here is a nearly complete version of cowsay implemented in python, although it differs slightly from the original.
* It doesn't support cowthink (although this shouldn't be difficult to add).
* The help returned by -h is sparse and the docstrings non-existant.
* It doesn't support the -l flag which displays the COWPATH as I don't support cowfiles.
* The -f flag opens up a regular file and uses that as a message, whereas the original uses a cowfile instead.
* It keeps the bug/feature of the original in that you can pass in a 1 character tongue string or eye string.
 I'm sure there are others and bugs that I haven't found(well, I didn't do any unit tests ;), but there you go. Before you ask, the code is ugly, because I'm lazy and didn't really give a shit.

from optparse import OptionParser
from collections import namedtuple

def chunks(s,n):
    l = []
    while len(s) > n:
        l.append(s[:n])
        s = s[n:]
    l.append(s)
    return l

def strip_extra_whitespace(s):
    l = []
    prev = False
    for c in s:
        if c.isspace():
            if prev:
                continue
            prev = True
        else:
            prev = False
        l.append(c)
    return "".join(l)

CowType = namedtuple('Cowtype','eyes tongue')

class Cow():
    template = """
        \\   ^__^
         \\  (%s)\\_______
            (__)\       )\\/\\
             %s ||----w |
                ||     ||"""

    cowtypes = {"normal" : CowType("oo","  "),
            "borg" : CowType("==","  "),
            "dead" : CowType("XX","U "),
            "greedy" : CowType("$$","  "),
            "paranoid" : CowType("@@","  "),
            "stoned" : CowType("**","U "),
            "tired" : CowType("--","  "),
            "wired" : CowType("OO","  "),
            "youthful" : CowType("..","  ")}

    def __init__(self,words,type="normal",wrap=40):
        self.words = self.generate_speech(words,wrap=wrap)
        self.eyes,self.tongue = self.cowtypes[type]
    def __repr__(self):
        global templates
        return self.words + self.template % (self.eyes,self.tongue)
    def generate_speech(self,s,wrap=False):
        if wrap:
            lines =  chunks(strip_extra_whitespace(s.replace("\n"," ").replace("\t",4 * " ")),wrap)
        else:
            lines =  s.replace("\t",4*" ").splitlines()
        maxlen =  max(map(len,lines))
        toplines = [" " + "_"*(maxlen+2)]
        bottomlines = [" " + "-"*(maxlen + 2)]
        if len(lines) == 1:
            lines[0] = "< %s >" % lines[0]
        else:
            for i in range(len(lines)):
                if i == 0:
                    delimiters = "/","\\"
                elif i == len(lines)-1:
                    delimiters = "\\","/"
                else:
                    delimiters = "|","|"

                lines[i] = "%s %s%s %s" % (delimiters[0],lines[i], (maxlen-len(lines[i])) * " ",delimiters[1])
        return "\n".join(toplines + lines + bottomlines)

def make_parser():
    parser = OptionParser()
    parser.add_option("-e",dest="eye_string")
    parser.add_option("-f",dest="file")
    parser.add_option("-n",dest="whitespace",action="store_true",default=False)
    parser.add_option("-T",dest="tongue_string")
    parser.add_option("-W",dest="column",type="int",action="store")

    parser.set_defaults(cowtype="normal")
    parser.add_option("-b",dest="cowtype",action="store_const",const="borg")
    parser.add_option("-d",dest="cowtype",action="store_const",const="dead")
    parser.add_option("-g",dest="cowtype",action="store_const",const="greedy")
    parser.add_option("-p",dest="cowtype",action="store_const",const="paranoid")
    parser.add_option("-s",dest="cowtype",action="store_const",const="stoned")
    parser.add_option("-t",dest="cowtype",action="store_const",const="tired")
    parser.add_option("-w",dest="cowtype",action="store_const",const="wired")
    parser.add_option("-y",dest="cowtype",action="store_const",const="youthful")

    return parser

if __name__ == "__main__":
    import sys
    parser = make_parser()
    (options,args) = parser.parse_args()
    if options.file:
        try:
            f = open(options.file)
            message = f.read()
            f.close()
        except IOError:
            sys.stderr.write("File %s not found\n" % options.file)
            sys.stderr.flush()
            sys.exit(1)
           
    elif args:
        message = " ".join(args)
    else:
        message = sys.stdin.read()

    if options.whitespace:
        wrap = False
    elif options.column:
        wrap = options.column
    else:
        wrap = 40

    cow = Cow(message,options.cowtype,wrap)
    if options.eye_string:
        cow.eyes = options.eye_string[:2]
    if options.tongue_string:
        cow.tongue = options.tongue_string[:2]

    print cow

Name: Anonymous 2009-11-29 19:10

>>52
________________
< feels good man >
 ----------------
         \
          \
            ^__^
    _______/(oo)
/\/(       /(__)
   | W----|| |~|
   ||     || |~|  ~~
             |~|  ~
             |_| o
             |#|/
            _+#+_

Name: Anonymous 2009-11-29 20:04

>>30 here.

Yeah, I never finished. My goal is to have a pong program and a tetris program done by wednesday, after which I'll make fibbopongtris. Hey, I'll do it, give me a break.

Name: Anonymous 2009-11-29 20:09

>>54
I wasn't expecting you to ;), but I needed to ensure that I kept myself to the deadline (incidentally I posted the code after it, but was finished when I asked) and just so that it doesn't disappear from the front page and our memories.

Name: Anonymous 2009-11-29 21:04

Fully functional Tetris with a touch of Fibonacci.  My first FIOC.  Shouldn't be too hard to integrate a Pong if you're into that sort of thing.

#!/usr/bin/python

from curses import *
from curses.wrapper import *
import time
import random

blockShapes = [
    # http://tetris.wikia.com/wiki/File:NESTetris-pieces.png
    [[ (1, 1), (2, 1), (1, 2), (2, 2) ]]*4,    # O
    [[ (0, 1), (1, 1), (2, 1), (3, 1) ],
     [ (2, 0), (2, 1), (2, 2), (2, 3) ]]*2,    # I
    [[ (1, 1), (2, 1), (1, 2), (0, 1) ],
     [ (1, 1), (1, 2), (0, 1), (1, 0) ],
     [ (1, 1), (0, 1), (1, 0), (2, 1) ],
     [ (1, 1), (1, 0), (2, 1), (1, 2) ]],    # T
    [[ (1, 1), (2, 1), (1, 2), (0, 2) ],
     [ (1, 0), (1, 1), (2, 1), (2, 2) ]]*2,    # S
    [[ (1, 1), (2, 2), (1, 2), (0, 1) ],
     [ (1, 1), (2, 0), (2, 1), (1, 2) ]]*2,    # Z
    [[ (2, 1), (1, 1), (0, 1), (0, 2) ],
     [ (1, 2), (1, 1), (1, 0), (0, 0) ],
     [ (0, 1), (1, 1), (2, 1), (2, 0) ],
     [ (1, 0), (1, 1), (1, 2), (2, 2) ]],    # L
    [[ (2, 2), (1, 2), (0, 2), (0, 1) ],
     [ (1, 3), (1, 2), (1, 1), (2, 1) ],
     [ (0, 2), (1, 2), (2, 2), (2, 3) ],
     [ (1, 1), (1, 2), (1, 3), (0, 3) ]],    # J
]

boardSymbols = ["  "] + ["()"]*7 + ["%%"]    # empty, 7 normal blocks, garbage

def fibs(n):
    a, b = 0, 1
    for i in xrange(n):
        a, b = b, a + b
    return a

class Tetris:
    RUNNING, LOST = range(2)    # gamestate values
   
    def __init__(self, nrows, ncols):
        self.nrows = nrows
        self.ncols = ncols
        self.board = [[0]*ncols for y in xrange(nrows)]
        self.blockbuf = []
        self.falling = None    # (type, rotation, (x, y))
        self.gamestate = Tetris.RUNNING
        self.score = 0
        self.level = 0
        self.preview = None
   
    def genBlock(self):
        if not self.blockbuf:
            self.blockbuf = range(7)
            random.shuffle(self.blockbuf)
        return self.blockbuf.pop()
   
    def nextBlock(self):
        block = self.preview
        if block == None:
            block = self.genBlock()
        self.preview = self.genBlock()
        return block
   
    def squaresOccupiedBy(self, (type, rotation, (x, y))):
        shape = blockShapes[type][rotation]
        return [(x+s[0], y+s[1]) for s in shape]
   
    def blockFits(self, newBlock):
        for (x,y) in self.squaresOccupiedBy(newBlock):
            if x < 0 or x >= self.ncols or y < 0 or y >= self.nrows or self.board[y][x]:
                return False
        return True
   
    def placeBlock(self, newBlock, allowClear=True):
        for (x,y) in self.squaresOccupiedBy(newBlock):
            self.board[y][x] = newBlock[0]+1
        if allowClear:
            self.clearFullRows()
   
    def clearFullRows(self):
        ncleared = 0
        runStart = None
        def clear(start, until):
            n = until - start
            self.board = [[0]*self.ncols for y in xrange(n)] \
                + self.board[0:start] + self.board[until:]
            return n
        for y in xrange(self.nrows):
            if 0 in self.board[y]:
                if runStart != None:
                    ncleared += clear(runStart, y)
                    runStart = None
            elif runStart == None:
                runStart = y
        if runStart != None:
            ncleared += clear(runStart, self.nrows)
        if ncleared:
            self.score += 50 * ncleared * (ncleared + 1)
            self.maybeLevelUp()
   
    def maybeLevelUp(self):
        while self.score >= 1000 * fibs(self.level + 1):
            self.addGarbageRows(self.level)
            self.level += 1
   
    def addGarbageRows(self, count):
        self.board = self.board[count:]
        for row in xrange(count):
            self.board.append([8*random.randrange(0, 2) for x in xrange(self.ncols)])
       
    def drawBoard(self, window):
        window.border(0, 0, 32)
        window.addch(0, 0, 32)
        window.addch(0, 21, 32)
        for y in xrange(self.nrows):
            for x in xrange(self.ncols):
                window.addstr(1 + y, 1 + 2*x, boardSymbols[self.board[y][x]])
        if self.falling:
            for (x,y) in self.squaresOccupiedBy(self.falling):
                if x >= 0 and x < self.ncols and y >= 0 and y < self.nrows:
                    window.addstr(1 + y, 1 + 2*x, "[]")
   
    def drawPreview(self, window, x0, y0):
        for y in xrange(y0 + 1, y0 + 3):
            window.addstr(y, x0, "        ")
        if self.preview != None:
            for (x,y) in blockShapes[self.preview][0]:
                window.addstr(y0 + y, x0 + 2*x, "[]")
   
    def step(self):
        if self.gamestate != Tetris.RUNNING:
            return
        if self.falling:
            (type, rotation, (x, y)) = self.falling
            newPos = (type, rotation, (x, y+1))
            if self.blockFits(newPos):
                self.falling = newPos
            else:
                self.placeBlock(self.falling)
                self.falling = None
        else:
            newBlock = (self.nextBlock(), 0, (self.ncols//2 - 2, 0))
            if self.blockFits(newBlock):
                self.falling = newBlock
            else:
                self.placeBlock(newBlock, False)
                self.gamestate = Tetris.LOST
   
    def shift(self, dir):
        if self.falling:
            (type, rotation, (x, y)) = self.falling
            newPos = (type, rotation, (x+dir, y))
            if self.blockFits(newPos):
                self.falling = newPos
   
    def rotate(self, dir):
        if self.falling:
            (type, rotation, (x, y)) = self.falling
            newPos = (type, (rotation+dir)%4, (x, y))
            if self.blockFits(newPos):
                self.falling = newPos
   
    def drop(self):
        if self.falling:
            (type, rotation, (x, y)) = self.falling
            newPos = self.falling
            for ny in xrange(y+1, self.nrows):
                testPos = (type, rotation, (x, ny))
                if self.blockFits(testPos):
                    newPos = testPos
                else:
                    break
            self.placeBlock(newPos)
            self.falling = None

def tet(screen):
    try:
        curs_set(0)
    except:
        pass
    halfdelay(1)
    t = Tetris(20, 10)
    window = screen.derwin(22, 22, 0, 10)
    window.keypad(1)
    def redraw():
        t.drawBoard(window)
        window.refresh()
        screen.addstr( 8, 35, "LEFT/RIGHT to move")
        screen.addstr( 9, 35, "    UP     to spin")
        screen.addstr(10, 35, "   DOWN    to drop")
        screen.addstr(11, 35, "    Q      to quit")
        screen.addstr(14, 35, "Level: " + str(t.level))
        screen.addstr(15, 35, "Score: " + str(t.score))
        screen.addstr(16, 35, "Next:")
        t.drawPreview(screen, 36, 17)
        screen.move(0, 0)
        screen.refresh()
    while True:
        gamespeed = .5 - .03 * t.level
        nextStep = time.time() + gamespeed
        redraw()
        while time.time() < nextStep:
            key = window.getch()
            if key == ERR:
                pass
            elif key == KEY_LEFT:
                t.shift(-1)
                redraw()
            elif key == KEY_RIGHT:
                t.shift(1)
                redraw()
            elif key == KEY_UP:
                t.rotate(1)
                redraw()
            elif key == KEY_DOWN:
                t.drop()
                break
            elif key in [ord('q'), ord('Q')]:
                return
        t.step()
        if t.gamestate == Tetris.LOST:
            redraw()
            screen.addstr(22, 10, "***  You have died  ***")
            screen.refresh()
            while window.getch() not in [ord('q'), ord('Q'), 10]: pass
            return

wrapper(tet)

Name: Anonymous 2009-11-29 21:30

>>56
Most impressive.

Name: Anonymous 2009-11-29 22:46

>>57
if you don't know anything about programming, maybe

Name: Anonymous 2009-11-29 22:54

>>58
Most impressive out of what's been posted, smart ass.

Name: Anonymous 2009-11-29 23:22

>>59
.&.

Name: HASKELL GENITALS MEMESMITH 2009-11-30 1:30

>>60
Excuse me?

Name: HMA FAN 2009-11-30 5:27

>>61
hma :: Anus -> Anus -> Post
hma you me = post . map toUpper $ you .&. me

Name: HMA FAN 2009-11-30 5:29

>>62
Actually, I'm starting to reconsider the arguments. I don't think "HAX MY ANUS" should be executed by the other poster's anus. Perhaps using the .|. AKA *grabs dick* operator would be be necessary.

Name: Anonymous 2009-11-30 15:58

bump

Name: Anonymous 2009-12-03 2:08

>>56
integrate a Pong
What does that mean?

Name: Anonymous 2009-12-03 2:28

PONG MY ANUS

Name: Anonymous 2009-12-03 6:24

PLAY PONG WITH MY ANII

Name: Anonymous 2009-12-03 6:38

>>66
PING MY PONG

Name: Anonymous 2009-12-03 11:19

int sumFibs(int n){
    return Fibs((n + 2) - 1);
}

Name: Anonymous 2009-12-03 11:26

>>69
What the fuck is that?

Name: Anonymous 2009-12-03 13:03

>>70
Someone who needs to spend a few hours in the LISP chamber.

Name: Anonymous 2009-12-03 13:27

>>71
A few hours? Don't you think that's a little extreme? After about 90 minutes you are in severe danger of breaking down mentally and feeling kinda good about it :)

Name: HACKERS AND ANAL RAPISTS 2009-12-03 19:45

HACKERS AND ANAL RAPISTS

Name: Anonymous 2009-12-03 19:46

>>73
(♥‿♥ )

Name: Anonymous 2009-12-04 14:08

>>65
You get to optionally play pong with the tetris pieces.

Name: Anonymous 2009-12-04 19:09

>>65
see >>30

Name: Anonymous 2011-01-31 21:05

<-- check em dubz

Name: Anonymous 2011-02-03 6:40

Name: tray 2012-03-14 22:57


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