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".
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:
Anonymous2009-11-28 17:02
UP⏎
Name:
Anonymous2009-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.
_
>>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:
Anonymous2009-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.
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.
Now we just need FV (or MDickie) to lead the team, and we're set.
Name:
OP2009-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
>>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:
Anonymous2009-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.
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 Tetris2009-11-29 0:20
>>41
Well fuck it, I'm starting. Monday at 12:00 AM EST it is.
Name:
Anonymous2009-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:
Anonymous2009-11-29 1:36
>>46
I'm writing Tetris. I say we all just do whatever the fuck we want.
>>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)
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:
Anonymous2009-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:
Anonymous2009-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
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 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, "[]")
>>61 hma :: Anus -> Anus -> Post
hma you me = post . map toUpper $ you .&. me
Name:
HMA FAN2009-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.
>>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 :)