6 ms·
Code Golf at Google
- spydum 11y agoi think the sad pattern I see in a lot of these code golf implementations is the solution score is based on Lines of Code, which we already agree is a POOR representation of either complexity or simplicity. I think it would be far more interesting to measure number of instructions to complete the objective. Though I suspect the folks familiar with assembly would run circles, perhaps you could segment by solution language?
- jsmthrowaway 11y agoYou are not describing code golf, though. "A sad pattern in chess is checkmate; the goal should be to eliminate the other player entirely." I agree what you describe would be fun, too, but it isn't code golf.
- userbinator 11y agoThe demoscene may be of interest if you're into optimising the binary for size and not the source: http://www.hugi.scene.org/compo/ http://www.hugi.scene.org/compo/ That one seems abandoned for a few years now but you can find plenty of tiny graphical effects here, executables are 512 bytes and below: http://www.pouet.net/prodlist.php?type%5B%5D=32b&type%5B%5D=64b&type%5B%5D=128b&type%5B%5D=256b&type%5B%5D=512b&page=1 http://www.pouet.net/prodlist.php?type%5B%5D=32b&type%5B%5D=...
- modeless 11y agoYou may be interested in http://www.zachtronics.com/tis-100/ http://www.zachtronics.com/tis-100/. It's essentially a code golf game with many different metrics to optimize including number of instructions.
- JoshTriplett 11y agoLines of code is a poor representation, but non-whitespace characters is a somewhat better one. Perl golf and vim golf both use that.
- NegativeK 11y agoGiven the entirely whimsical and (hopefully) intentionally rebellious nature of Code Golf, I don't think that worrying about the usefulness of the metric is really worth it.
- pjungwir 11y agoThe reason lines of code is a poor way to score solutions is that you should be counting characters! :-) My favorite Perl golf challenge is something I got from Boston Perl Mongers many years ago: You have the numbers 1 to 9 (in order), and in between each number you can insert a plus, a multiply, or nothing. Your program should print all expressions that evaluate to 2002. For instance it should print the solution 1*23+45*6*7+89 (and one other) I have a command-line solution in 80 characters, including the `perl ` at the beginning. It works on 5.10 and 5.16. I think there was a better solution back in the 5.8 days, but my notes are unclear.
- ectoplasm 11y agoOnce you know the other solution you can do much better than 80 characters!
- rory096 11y ago>http://go/codegolf http://go/codegolf How does this work, some sort of TLD magic? (That shouldn't be possible, right?) Is it just routed within Google's internal network?
- dmayle 11y agoBy default foo resolves to foo.mydomain.mytld (man resolv.conf, section domain), so as long as the machines are configured with a local domain, this will work.
- cornstalks 11y agoIt works the same as any other corporate network: either custom DNS resolution on the machine (i.e. /etc/hosts), DNS resolution in the internal network, or DNS resolution on the VPN. Or, more likely, a mix of the 3. To get to go links, you've got to be connected to Google's network (either physically, or through VPN). It's essentially the same as accessing a computer on your LAN with its host name (in which case, the router can do the DNS lookup and resolution for the internal network).
- thrownaway2424 11y agoFascinating but totally incorrect analysis. All anyone needs to get to go/ is to put corp.google.com in their resolver search paths. Of course, such people will also need a google.com login to actually be redirected to the destination.
- tperson 11y agoI'd assume the same way localhost works on your computer.
- deleted 11y ago[deleted]
- ot 11y agoIt's probably resolved by the internal network DNS. You can do the same even with your home router.
- 11y ago
- webo 11y agoHah, I remember spending hours on this during work hours when I was interning last year. I used to come up with very clever and short solutions only then to find out I wasn't even top 10 :(
- Omnipresent 11y agoCan a googler put the questions in public for others to see?
- nate_martin 11y agoFun fact: there has been a problem with Googlers calculating hash functions that pass all the test cases for certain questions.
- Retra 11y agoIf you think about it the right way, that's what everyone is doing: calculating a hash from the problem statement into stream of symbols with certain constraints. So the problem here is not calculating hash functions per se, but over-fitting the solution to those test cases.
- Buge 11y agoI'm trying to run the c++ version, but it won't compile because the loop variables in the range for loops do not have declarations.
- detrino 11y agoThere was a proposal[1][2] for C++17 to allow: for (e : c) which would be equivalent to: for (auto &&e : c) Gcc implements this when compiling with -std=c++1z. My understanding is that it was rejected by the committee. [1] http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n3853.htm http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n385... [2] http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n3994.htm http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n399...
- karavelov 11y agoPerl is a way more fun for golfing but it's missing from the supported languages
- planetjones 11y agoI watched the wolf of wall street recently. I see some of the solutions to these code golf exercises as similar to the bankers who beat their chests and celebrate their masculinity in selling penny stocks to gullible investors.These code golf exercises seem like the software developer equivalent: "look at how brilliant and superior I am that I can obfusicate code into something no-one understands in only 2 lines". My concern here is that this Code Golf mentality infects the normal day-to-day coding at Google. Just because an implementation can spawn a few lines it doesn't make it a good implementation. What about clean code, maintainability, automated testing, self documenting code... I pity the codebase I would have to maintain from one of these code golfers.
- mewse 11y agoMy concern here is If people write a haiku They might never stop.
- jsnell 11y agoNice how many off-handed insults you've managed to pack into such small space, based on no data at all except extrapolating from your own prejudices. It's almost like some kind of HN comment golf. A playful programming competition is really not at all comparable to cheating innocent people out of their money. Like, seriously. People are generally able to behave appropriately in situations with different expectations. There's no reason to think that it's not equally applicable to using the appropriate programming style for the project. It's like you're looking at somebody walking on the street in jeans and a T-shirt, and complaining that they're not properly dressed for the opera. And no code gets committed without a code review at Google anyway. Finally, code golf is rarely about obfuscation; obfuscation just for its own sake isn't compatible with minimizing code length. Once you e.g. know the basic Perl golf tricks, the code can be surprisingly readable since it really just contains the core of the algorithm.
- Vexs 11y agoInsult golf sounds kinda fun. Try to come up with the most insulting thing possible in the least characters. On a more serious note, I agree with you. There's some alarmist reactions to things like this, but in reality I don't think it's an issue at all. Sure, there might be bragging and such, but that's the point of something like this, isn't it? It's a game, not a serious discussion on optimization. Short code is more "fun" than superoptimized to my mind.
- uberbadtaxigood 11y agoMy Goog code golf examples were marked down because I didn't insert the method call to sellAdsToSuckers() call everywhere!
- acomjean 11y agoI had to do a code test for a job (sigh). But it actually was kind of fun. The website takes your code and checks correctness and efficiencies. The company posts "challenges" every month. But they also have lessons which contain some interesting code challenges. The only problems is 1) they're timed 2) sometimes the descriptions are kinda mathy which may put people off. https://codility.com/programmers/lessons/ https://codility.com/programmers/lessons/