Write a bot that scrapes programming challenges from random sites and posts one periodically to this board in ANSI /prog/ challenge format.
Deadline: before the admin pulls a moot.
As a bonus, you may have the bot scrape the answers as well and post a solution as the OP an hour after the thread is made, regardless of the stated deadline, in old /prog/ tradition.
Name:
Anonymous2014-06-25 4:55
>>1,2 I'm working on compressing the old world4ch dbs while maintaining fast random access time. Right now I'm abbreviating the tags to 2 characters. After that I will collapse repeated posts with identical content to compress the spam bots that posted static content.
Would someone post a reasonable challenge or something?
Implement Map, Fold/reduce, Filter, etc... in standard C The implemetation shall be able to work with any type and it may or may not use macros It shall be in C90 or any later standard Using compiler extencions is allowed but you loose Five points!
Name:
Anonymous2014-06-25 8:25
>>4 That's really good for a language-specific challenge. It sounds almost trivial, but useful and I've never done it. I guess I stopped writing C full time around the time I started using map, reduce, filter and so on.
This is a easy to implement and use solution that works on every(?) data structure while being less easy to use void * map (void *(*first)(void *), void *first_arg, void (*mapper)(void *, void *), void *mapper_arg, void *(*next)(void *, void *), void *next_arg) { for (void *elm = first (first_arg); elm; elm = next (elm, next_arg)) mapper (elm, mapper_arg); }
int even(void *val, void *unused) { return *(int *) val % 2 == 0; }
int main(void) { int a[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; size_t n = sizeof a / sizeof a[0]; int x;
/* map example: add 1 to each element */ map(a, n, sizeof a[0], add1, NULL);
/* filter example: filter even numbers */ n = map(a, n, sizeof a[0], even, NULL);
/* for-each example: print each element */ map(a, n, sizeof a[0], print, NULL); printf("\n");
/* fold example: sum elements */ x = 0; map(a, n, sizeof a[0], add, &x); printf("%d\n", x);
return 0; }
Name:
Anonymous2014-06-25 10:03
>>10 I could do that in one line of HASKALL. And it would be faster.
Name:
Anonymous2014-06-25 10:14
>>10 That's nice and all but please let me MICRO-OPTIMSE it size_t map (void *p, size_t size, size_t n, bool fn (void *, void *), void *arg) { char *const bp = p; size_t j = 0;
for (size_t i = 0; i < n; i++) if (fn(&bp[i * size], arg) && i != j++) memcpy(&bp[(j - 1) * size], &bp[i * size], size); return j; }
Name:
L. A. Calculus!jYCj6s4P.g2014-06-25 10:35
>>11 REALLY? HOW MANY FUKIN LINES OF HASKALL WUD IT TAKE TO WRITE DA FOLLOWING PROGRAM? (STICK WITH DA PROCEDURAL PARADIGM, JUNIOR): #include <stdio.h>
int main(void) { const int a[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; size_t i; int x;
x = 0; for (i = 0; i < sizeof a / sizeof a[0]; i++) if (++a[i] % 2 != 0) { x += a[i]; printf(" %d", a[i]); } printf("\n%d\n", x); return 0; }
That produces output identical to yours, and it's not even golfed. But if you insist on translating it from the C version as directly as possible, then (quelle surprise!) it will look pretty much like C:
main = do a <- newListArray (0, 9) [ 0 .. 9 ] :: IO (IOUArray Int Int) i <- newIORef 0 x <- newIORef 0 cStyleFor (i $= 0, i $< 10, i += 1) $ do a_i <- plusplus a =<< readIORef i when (a_i `mod` 2 /= 0) $ do x += a_i putStr (' ' : show a_i) x' <- readIORef x putStrLn ('\n' : show x')
-- Helper functions so we can pretend we're banging rocks together instead -- of using a real language ref $= value = writeIORef ref value ref $< value = (< value) `fmap` readIORef ref ref += value = modifyIORef ref (+ value)
-- Has to be implemented separately from (+=) unless we want to whip out -- some fucking typeclasses like the Illuminati plusplus array index = do old <- readArray array index let new = old + 1 writeArray array index new return new
cStyleFor (pre, cond, post) body = pre >> loop where loop = cond >>= \test -> if test then body >> post >> loop else return ()
>>20 You're not printing the actual numbers you summed. The idiomatic Haskell for what you're doing is about the same: main = print . sum . filter odd . map succ $ [0 .. 9]
How about you actually read the code you're trying to beat, or at least run it so you can see what it prints.
Name:
Anonymous2014-06-25 17:20
>>21 Why are you writing right to left, are you a Hebrew?
main = map succ >>> filter odd >>> sum >>> print $ [0 .. 9]
>>25 Does Symta say work like Io println? If so, you might want to try what I did.
Name:
Anonymous2014-06-25 23:13
>>8 Using code as a noun is okay. Source code has always been valid. Source program sounds silly. I guess Program is fine too, but code is a more precise definition because the snippets being posted here seem to be part of a larger program.
Using code as a verb is frowned upon on /prog/, with good reason. Though >>1-san used code as a noun and there's nothing wrong with that.
Me and my staccboi crew get fuckin' hype (thx Vinny for da Vyvanse) and code up mad fuckin' apps. It's so easy bro. You can like drag and drop the facebook api and shit. Knock a couple apps out while my 10/10 bae gives me dome then hit the club. Girls all tryin' to get a piece of my entrepreneurial pie once they know I got App Store swag.
The challenge is to implement Collision Detection on 2d Rectangles, with a twist.. =) The rectangles have both linear and angular momentum (basically they are moving and spinning)
Name:
Anonymous2014-06-26 6:14
>>35 That's not a twist, that's simple rigid body physics.