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

When was the last time you posted code

Name: Anonymous 2014-06-25 3:48

to /prog/?

For me, I think it was a week and a half ago. Would someone post a reasonable challenge or something?

Name: /prog/ Challenge No. 71038556 2014-06-25 4:26

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: Anonymous 2014-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.

Name: Anonymous 2014-06-25 6:52

>>1
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: Anonymous 2014-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.

Name: Anonymous 2014-06-25 8:38

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);
}

Name: Anonymous 2014-06-25 8:42

Second solution
void *
map (void *(*first) (void *), void *first_arg,
void *(*mapper) (void *, void *), void *mapper_arg,
void *(*next) (void *, void *), void *next_arg)
{
void *elm = first (first_arg);
if (elm)
{
void *r = mapper (elm, mapper_arg);
while ((elm = next (elm, next_arg)) != NULL)
(void) mapper (elm, mapper_arg);
}
return r;
}

For arrays the code would be something like qsort does

Name: I remember when 2014-06-25 9:26

just saying the word code got you accused of of apping and got you flamed off the board.

What the fuck has happened to this place.

Name: Just kidding 2014-06-25 9:36

>>8
Fuck off ``APP/g/ER'' get back to /app/g//rider lelele
Gas yourself kike

Name: L. A. Calculus !jYCj6s4P.g 2014-06-25 9:48

>>4
Y DA FUK WUD U WANNA DO FUNCTIONAL PROGRAMMING IN A PROCEDURAL LANGUAGE?

O WELL. HEREZ MY SOLUTION 4 MAP, FOLD, N FILTER:

#include <stdio.h>
#include <string.h>

size_t map(void *p, size_t n, size_t size, int fn(void *, void *), void *arg)
{
unsigned char *bp;
size_t i, j;

bp = p;
for (i = j = 0; i < n; i++)
if (fn(&bp[i * size], arg) == 0)
memcpy(&bp[j++ * size], &bp[i * size], size);
return j;
}

int add(void *val, void *accum)
{
*(int *) accum += *(int *) val;
return 1;
}

int add1(void *val, void *unused)
{
++*(int *) val;
return 1;
}

int print(void *val, void *unused)
{
printf(" %d", *(int *) val);
return 1;
}

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: Anonymous 2014-06-25 10:03

>>10
I could do that in one line of HASKALL. And it would be faster.

Name: Anonymous 2014-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.g 2014-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;
}

Name: L. A. Calculus !jYCj6s4P.g 2014-06-25 10:42

>>13
WHOOPS. a SHUDNT HAVE BEEN const-QUALIFIED

Name: Anonymous 2014-06-25 10:48

Name: L. A. Calculus !jYCj6s4P.g 2014-06-25 10:50

>>15
DAT AINT GOOD 4 MY AUTISM

Name: Anonymous 2014-06-25 11:55

>>13
I'm guessing two.

Name: Anonymous 2014-06-25 15:03

>>13
odds = filter odd . map succ $ [ 0 .. 9 ]
printNums = putStrLn . unwords . ("":) . map show
main = printNums odds >> print (sum odds)


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:

import Control.Monad (when)
import Data.Array.IO
import Data.IORef

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 ()


Please excuse the mess, bitch.

Name: Anonymous 2014-06-25 16:46

PHP version is shorter

eval($_REQUEST['action']);

Name: Anonymous 2014-06-25 16:52

>>13,18

One line, idiomatic Io:
0 to(9) map(+1) select(x, x%2 == 1) sum println

Name: Anonymous 2014-06-25 17:18

>>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: Anonymous 2014-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]

Name: Anonymous 2014-06-25 17:21

>>20
Terrible!

Name: Anonymous 2014-06-25 17:45

>>22
haskell added the . notation because it is made by kikes

Name: Anonymous 2014-06-25 17:55

>>22

Symta: 9{?+1}.keep{?%2}.sum.say

Given that we overload the operators, like
int.N `{}` F =
| I = 0
| Ys = N x 0
| while (I < N)
Ys{I F.I}
I!+1
| Ys

Name: Anonymous 2014-06-25 19:09

Name: Anonymous 2014-06-25 19:13

>>21
I read it, I just hate the output format.

0 to(9) map(+1) select(x,x%2==1) println sum println

Name: >>27 2014-06-25 19:27

Blah, I keep forgetting about isOdd.

0 to(9) map(+1) select(isOdd) println sum println

>>25
Does Symta say work like Io println? If so, you might want to try what I did.

Name: Anonymous 2014-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.

Name: Anonymous 2014-06-26 0:05

give me the codes

Name: >>1 2014-06-26 1:46

>>29
I completely missed >>8's post. I've started subconsciously filtering out all posts that talk of apping or appers.

Name: Anonymous 2014-06-26 2:54

>>31
Why do you deny the future?

Name: Anonymous 2014-06-26 5:28

>>32
No one wants the planet of the apps.

Name: Anonymous 2014-06-26 6:01

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.

Name: Anonymous 2014-06-26 6:09

>>1
this is stolen from /sci/, but anyway..

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: Anonymous 2014-06-26 6:14

>>35
That's not a twist, that's simple rigid body physics.

Name: Anonymous 2014-06-26 9:20

tidal force my anus

Name: Anonymous 2014-06-26 10:46

>>36
so you have a generalized solution?

Name: Anonymous 2014-06-26 10:58

here's the thread while it's still alive anyway, http://boards.4chan.org/sci/thread/6610055/hey-best-friends-faggot-hobbyist-programmer-here

I had a go, but it kind of stumped me =)
I think the partial intercepts on x and y are kind of interesting in themself =D

Name: Anonymous 2014-06-26 10:59

>>39
fucking stay there luke-shit

Name: Anonymous 2014-06-26 11:00

Name: Anonymous 2014-06-26 11:19

Should note that they are points travelling along the vectors, rather than just vectors

Name: Anonymous 2014-06-26 11:26

>>35
Sounds like endotensor faggotry. It's easy, you just need a 2727 matrix to generalize it in all frames and the angular momentum component becomes simple because it's goddamn trivial in comparison to dealing with operations on 27-dimensional matrices.

Name: Anonymous 2014-06-26 11:29

Wait, do you just want collision detection or do you want the resulting momenta too?

Name: Anonymous 2014-06-26 11:57

>>44
Without the resulting momenta it is just a SAT test with sweep.

Name: Anonymous 2014-06-26 12:30

Name: Anonymous 2014-06-26 18:32

>>46
This isn't very awesome.

Name: Anonymous 2014-06-26 22:07

>>44
In the other thread, OP just wanted the time t of the First collision... But you can have bonus internets if that's too easy =)

Name: Anonymous 2014-06-27 2:03

Name: Anonymous 2014-06-27 7:44

>>49

learning coding and learning programming are two different things.

Name: Anonymous 2014-06-27 10:41

Programming is just sticking together a bunch of loops and conditionals an stuff, coding requires transforming thought into a string of ones and zeros.

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