## Search found 1812 matches

Fri Jul 30, 2010 3:36 pm UTC
Forum: Coding
Topic: Phone screening for programmers
Replies: 18
Views: 2415

### Re: Phone screening for programmers

IMHO, you definitely need to ask them to do something that demonstrates their basic competency at programming before bringing them in, either on the phone or as a "homework" assignment (with a deadline of maybe an hour). I think that Yegge article is great. Why do you think you can't use s...
Fri Jul 30, 2010 2:23 pm UTC
Forum: Coding
Topic: [Unnecessarily-] Compact coding tricks
Replies: 112
Views: 15919

### Re: [Unnecessarily-] Compact coding tricks

int sum_range(int a, int b)[code]int sum_range(int a, int b) { if(a > b) return -1; if(a < 0 && b > 0) return sum_range(a, 0) + sum_range(0, b); int s = a + b; if(a < 0) { int t = abs(a); a = abs(b); b = t; } int d = 1 + b - a, q = d / 2; return ((s > 0) - (s < 0)) * (s * q + (a + q) * (d %...
Fri Jul 30, 2010 12:35 pm UTC
Forum: Coding
Topic: [Unnecessarily-] Compact coding tricks
Replies: 112
Views: 15919

### Re: [Unnecessarily-] Compact coding tricks

here's one that actually works: int sum_range(int a, int b) { if(a > b) return -1; if(a < 0 && b > 0) return sum_range(a, 0) + sum_range(0, b); int s = a + b, x = abs(a), d = 1 + abs(b) - x, q = d / 2; return ((s > 0) - (s < 0)) * (s * q + (x + q) * (d % 2); } That doesn't work at all. It s...
Wed Jul 28, 2010 8:52 pm UTC
Forum: Coding
Topic: [Unnecessarily-] Compact coding tricks
Replies: 112
Views: 15919

### Re: [Unnecessarily-] Compact coding tricks

I used to use the return values from assignment (in C and C++) all the time. I would say "if (x = f(y))" on purpose, for instance. It seemed normal to me, and I was surprised when I found out most people don't like it. Here's a couple of lines from a Javascript game I wrote that use this: ...
Wed Jul 28, 2010 8:14 pm UTC
Forum: Coding
Topic: HTML5 + Javascript and collision detection
Replies: 11
Views: 8937

### Re: HTML5 + Javascript and collision detection

If you're doing ball-ball collisions, you can simplify the code quite a bit, and get rid of all trig functions, and all but one square root. If you're interested, here's the collision routine I wrote for a game of mine in Javascript: function Overlap(ThingOne, ThingTwo) { Del = (ThingOne.Size + Thin...
Thu Jul 22, 2010 2:15 pm UTC
Forum: Logic Puzzles
Topic: Chess problem: The missing king
Replies: 60
Views: 10722

### Re: Chess problem: The missing king

Here's another hard one I've seen a few places on the web. Fill in the rest of the game:

1. e4 ???
2. ??? ???
3. ??? ???
4. ??? ???
5. ??? NxR++
Tue Jul 20, 2010 3:16 pm UTC
Forum: Logic Puzzles
Topic: Chess problem: The missing king
Replies: 60
Views: 10722

### Re: Chess problem: The missing king

Ah, now I see how it all fits together. That's a great puzzle: nothing about the board is superfluous, despite how it seems at first.
Tue Jul 20, 2010 2:27 pm UTC
Forum: Coding
Topic: What code/software license should I use?
Replies: 5
Views: 1520

### Re: What code/software license should I use?

Hey, sorry to hijack, but I also have a license question. Is there a "public domain"-like license for code along the lines of CC0 ? Or can I just use CC0 on code? Also, Google code requires that you release your code using one of their pre-approved licenses: Apache 2.0, Artistic/GPL, Eclip...
Tue Jul 20, 2010 12:35 pm UTC
Forum: Logic Puzzles
Topic: Chess problem: The missing king
Replies: 60
Views: 10722

### Re: Chess problem: The missing king

I also don't have a solution, but one thing I notice that might be significant is.... Both black and white must have had at least four pawn captures (including the last move). In black's case, you can see four of the squares that captures must have happened on, and they're all white....
Sat Jul 17, 2010 1:52 pm UTC
Forum: Coding
Topic: Why doesn't flash/etc state persist past tab closing?
Replies: 13
Views: 1784

### Re: Why doesn't flash/etc state persist past tab closing?

I for one would not want a resource-hogging script to wait 30 seconds after being closed before freeing its resources. But I guess it could be included as an option.
Fri Jul 16, 2010 6:51 pm UTC
Forum: Coding
Topic: Coding: Fleeting Thoughts
Replies: 9890
Views: 1829579

### Re: Coding: Fleeting Thoughts

Hey neat! Well, it took me a while to figure out what the issue is, but I got it now. I guess this is a quirk of the way the canvas element takes care of its data. Every time you're assigning to outputdata[i], it's getting coerced to an integer. Since you're summing up a bunch of floating-point valu...
Fri Jul 16, 2010 4:33 pm UTC
Forum: Coding
Topic: Coding: Fleeting Thoughts
Replies: 9890
Views: 1829579

### Re: Coding: Fleeting Thoughts

That makes it sound like you have other issues besides floating-point precision issues. Gaussian blur isn't that hard. Would you be interested in posting your code?
Fri Jul 09, 2010 2:49 am UTC
Forum: Coding
Topic: coworker rants
Replies: 92
Views: 13395

### Re: coworker rants

Well, I don't think I've ever heard of a CLL either. However, based on the name alone I'm pretty sure I know what it is and how to implement it (and Wikipedia confirms). I'm not a CS major, though, but I think I have a fair handle on data structures. I'm just saying.
Tue Jul 06, 2010 2:23 am UTC
Forum: Coding
Topic: The "IT DOESN'T WORK!" thread
Replies: 1958
Views: 525348

### Re: The "IT DOESN'T WORK!" thread

First off, I feel like my code is a terrible mess. Can anyone confirm or deny that? Confirmed. However, I don't think it's useful for people to just lay a bunch of style on a beginner. It's something you'll learn over time. Just keep at it. Second... I think should see if the ball is to the left of...
Fri Jul 02, 2010 2:55 pm UTC
Forum: Coding
Replies: 10
Views: 1823

### Re: Reading JPEG and GIF

Okay, the ImageMagick library has a C API called MagickWand [link]. I haven't used it, but I'm sure it can handle this.
Fri Jul 02, 2010 2:33 pm UTC
Forum: Coding
Replies: 10
Views: 1823

### Re: Reading JPEG and GIF

This is extremely close to the PPM image format. I would start by converting the image files to PPM, which can be done using lots of programs, like Gimp and ImageMagick. Depending on exactly what you need, that might be enough, and in any event it'll be easy from there.
Wed Jun 30, 2010 12:41 am UTC
Forum: Coding
Topic: coworker rants
Replies: 92
Views: 13395

### Re: coworker rants

I'm back on the "intentional obfuscation" train. Seriously, exploiting *side effects* of iterators in order to get every second element of a slice? That's fucking disgusting, and he's going to hell. I don't know, the more I think about it, the less I feel like this is "exploiting a s...
Tue Jun 29, 2010 8:05 pm UTC
Forum: Coding
Topic: coworker rants
Replies: 92
Views: 13395

### Re: coworker rants

Yes, I understand (although, it's because I understood the code to begin with, not because I really follow your flow chart that well). I shouldn't have made it a functional rant. I take it back. I have seen what I believe to be a myopically functional programming mindset resulting in bad Python, but...
Tue Jun 29, 2010 2:51 pm UTC
Forum: Coding
Topic: coworker rants
Replies: 92
Views: 13395

### Re: coworker rants

Okay okay, I don't *hate* functional programming. But we run pylint on production code (which this is not), and by default it gives a warning for every use of "map". At first it seemed ridiculous to exclude a feature of the language like that, but now I'm tending to agree.
Tue Jun 29, 2010 2:25 pm UTC
Forum: Coding
Topic: coworker rants
Replies: 92
Views: 13395

### Re: coworker rants

It took me 15 minutes to figure out what this does: k = tuple(map((lambda x,y: y), *([iter(items[1:separator])]*2))) v = tuple(map((lambda x,y: y), *([iter(items[separator+1:])]*2))) and replace it with this: k = tuple(items[2:separator:2]) v = tuple(items[separator+2::2]) I'm glad to be working in ...
Tue Jun 29, 2010 10:22 am UTC
Forum: Coding
Topic: Epic coding moments
Replies: 127
Views: 21195

### Re: Epic coding moments

Yeah I know, I wasn't saying there was no point. I was just making an observation. When I first looked at your solution I thought, well that doesn't seem so impressive. But then I remembered it was Java and I changed my mind.
Mon Jun 28, 2010 6:33 pm UTC
Forum: Forum Games
Topic: Word Puzzle
Replies: 114
Views: 14847

### Re: Word Puzzle

SHOOTING
Spoiler:
via RIFLE OP
Mon Jun 28, 2010 5:15 pm UTC
Forum: Coding
Topic: Incrementing a Byte
Replies: 7
Views: 842

### Re: Incrementing a Byte

Standard modular arithmetic. 255 + 1 = 0.
Mon Jun 28, 2010 5:10 pm UTC
Forum: Logic Puzzles
Topic: Minimum Number of Orderings
Replies: 3
Views: 1301

### Re: Minimum Number of Orderings

Here's a solution for n = 6, card(B) = 5, found by exhaustive search:
Spoiler:
(0, 1, 2, 3, 4, 5)
(2, 1, 3, 4, 0, 5)
(1, 4, 3, 2, 5, 0)
(2, 4, 0, 5, 1, 3)
(4, 1, 0, 5, 2, 3)
A similar search didn't yield anything for n = 5, card(B) = 4.
Mon Jun 28, 2010 5:03 pm UTC
Forum: Coding
Topic: Epic coding moments
Replies: 127
Views: 21195

### Re: Epic coding moments

A less recent epic coding moment was compating down my java solution to http://golf.shinh.org/p.rb?hexagon+2nd+fixed as tightly as I did. I gotta say, it doesn't surprise me that Java yields the worst (highest-scoring) solution to that problem, 26% longer than the second-longest. Is that pretty typ...
Thu Jun 24, 2010 2:44 pm UTC
Forum: Logic Puzzles
Topic: Ten Pin Bowling Score
Replies: 9
Views: 5374

### Re: Ten Pin Bowling Score

What does it mean, "the machine missed a bit"?
Tue Jun 22, 2010 2:39 pm UTC
Forum: Logic Puzzles
Topic: Angels and Demons
Replies: 55
Views: 14024

### Re: Angels and Demons

t1mm01994 wrote:there is no way to exclude that Demons always speak the truth too, in which case you'll never find out.

Uh, yes there is. You just ask "are you a Demon?"
Tue Jun 22, 2010 12:40 pm UTC
Forum: Forum Games
Topic: Word Puzzle
Replies: 114
Views: 14847

### Re: Word Puzzle

You can't go from LIDS to POST anyway, unless I'm missing something.

You just have to get "creative" about words. Think like a cruciverbalist. What about LIDS -> PASSED
Spoiler:
As in, "the bartender slid me a drink"
Tue Jun 15, 2010 8:38 pm UTC
Forum: Coding
Topic: Ordering a list in python
Replies: 5
Views: 1034

### Re: Ordering a list in python

Code: Select all

`[x/2 if (x/2^x)&1 else max-1-x/2 for x in range(max)]`

If max is divisible by 4:

Code: Select all

`sum(zip(range(max-1,0,-2), range(0,max/2,2), range(1,max,2), range(max-2,0,-2)), ())`
Wed Jun 09, 2010 2:31 pm UTC
Forum: Logic Puzzles
Topic: The two boat races
Replies: 18
Views: 3116

### Re: The two boat races

I wonder why a current-powered craft that goes downstream faster than the current is easier to accept than a wind-powered craft that goes downwind faster than the wind.... Because the current powered craft is also wind powered? Even when there's no wind? (Depending on your frame of reference, of co...
Wed Jun 09, 2010 2:12 pm UTC
Forum: Logic Puzzles
Topic: The two boat races
Replies: 18
Views: 3116

### Re: The two boat races

I wonder why a current-powered craft that goes downstream faster than the current is easier to accept than a wind-powered craft that goes downwind faster than the wind....
Sun May 30, 2010 3:32 pm UTC
Forum: Forum Games
Topic: Word Puzzle
Replies: 114
Views: 14847

### Re: Word Puzzle

ERA
Sun May 30, 2010 1:08 am UTC
Forum: Coding
Topic: Coding: Fleeting Thoughts
Replies: 9890
Views: 1829579

### Re: Coding: Fleeting Thoughts

FT: How do you write Python? I don't mean like the tutorials say, I mean how to not "write C with Python". Maybe it's different for different people, but for me the big thing was getting iterable types (list, tuple, set, dict, str) and comprehensions down cold. Get really good at using &q...
Fri May 28, 2010 7:54 pm UTC
Forum: Logic Puzzles
Topic: Born on a Tuesday
Replies: 2
Views: 1472

### Re: Born on a Tuesday

Good call, I didn't see it there. I think this should be locked!
Fri May 28, 2010 7:23 pm UTC
Forum: Logic Puzzles
Topic: Born on a Tuesday
Replies: 2
Views: 1472

### Born on a Tuesday

I see some random guy on the street and I say, "Do you have exactly two children?" to which he replies "Yes." I then ask, "Do you have at least one son?" to which he replies "Yes." We all know that the probability that this guy has two sons is 1/3 . I see anot...
Tue May 25, 2010 10:45 pm UTC
Forum: Coding
Topic: Timsort in Python
Replies: 9
Views: 3211

### Re: Timsort in Python

Oh my bad. I guess I didn't look closely enough.
Tue May 25, 2010 8:16 pm UTC
Forum: Coding
Topic: Timsort in Python
Replies: 9
Views: 3211

### Re: Timsort in Python

I think I found one here, but it's not what I'd call a straightforward implementation. It does a lot of logging that you can probably do without. If you have a list x, you can sort it by calling sortable.Tim()(x).
Wed May 12, 2010 9:44 pm UTC
Forum: Coding
Topic: Local variables problem in Python
Replies: 7
Views: 1495

### Re: Local variables problem in Python

Re: deep copying When I first learned Python, I found it weird that it's not obvious how to do a deep copy. Now that I'm comfortable with Python, though, I find that there's almost never any need to do it. In fact, I don't think I've ever deep copied anything. When they differ, shallow copy is almos...
Fri May 07, 2010 10:26 pm UTC
Forum: Coding
Topic: Coding: Fleeting Thoughts
Replies: 9890
Views: 1829579

### Re: Coding: Fleeting Thoughts

That looks like a job for xargs. I can't test this, but what happens when you do:

Code: Select all

`nslookup irc.foonetic.net | tail -n +5 | grep "Address: " | cut -d" " -f2 | xargs ping -c 3`
I mean, obviously there's more than one way to do this, but this seems most intuitive to me.
Mon Apr 26, 2010 7:34 pm UTC
Forum: Coding
Topic: PHP Ackermann's Implementation
Replies: 10
Views: 2832

### Re: PHP Ackermann's Implementation

Modular exponentiation is a good start, but it's not enough. For instance, Wikipedia's non-recursive formula for A(4,4) has it in terms of 2^2^2^65536. Using modular exponentiation this takes 2^65536 operations. You'll need to be more clever than that to get it done. You should be able to get A(4,4)...