/prog/ challenge
1
Name:
Anonymous
2012-12-24 0:12
All right, /prog/ , it is time for the ultimate challenge. Your task, if you are EXPERT to accept it, it to program something of reasonable complexity, in the language of your choice, how ever you see fit. In one year, you will reevaluate your code and comment on your design choices. Can you write code that will stand the test of time?
2
Name:
Anonymous
2012-12-24 1:01
Challenge accepted!
Weapon of choice :
Octave
Task :
www.kaggle.com/c/traveling-santa-problem/
3
Name:
Anonymous
2012-12-24 2:37
though 3000$ does sound a little cheap for the next tor / zombie bot-net routing sub-system ;)
4
Name:
Anonymous
2012-12-24 3:53
Fairly lazy approach takes ~12 sec, and finds a path of ~15,000,000
http://img.techpowerup.org/121224/path1.jpg
5
Name:
Lambda Arthur Wordcounterless
2012-12-24 8:10
I ACCEPT!
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
struct node {
char *str;
int val;
struct node *next;
};
static struct node *tab[2048];
static unsigned int hash(const char *str)
{
enum { MULTIPLIER = 31 };
unsigned int h = 0;
while (*str)
h = MULTIPLIER * h + (unsigned char) *str++;
return h % (sizeof tab / sizeof tab[0]);
}
static struct node *install(struct node *np)
{
unsigned int h;
np->next = tab[(h = hash(np->str))];
tab[h] = np;
return np;
}
static struct node *lookup(const char *str)
{
struct node *np;
for (np = tab[hash(str)]; np && strcmp(str, np->str); np = np->next)
;
return np;
}
static struct node *new(const char *str)
{
struct node *v;
if (!(v = malloc(sizeof *v)) || !(v->str = malloc(strlen(str) + 1)))
exit(EXIT_FAILURE);
strcpy(v->str, str);
v->val = 1;
return v;
}
static void print(struct node *const *tab, size_t n)
{
struct node *tp;
while (n--)
for (tp = *tab++; tp; tp = tp->next)
printf("%d %s\n", tp->val, tp->str);
}
int main(void)
{
struct node *ptr;
char buf[2048];
while (scanf("%2047s", buf) == 1)
if (!(ptr = lookup(buf)))
install(new(buf));
else
ptr->val++;
print(tab, sizeof tab / sizeof tab[0]);
return 0;
}
6
Name:
Anonymous
2012-12-24 9:45
>>2
How long have you been on kaggle? I am interested in it as well. Any advice would be really helpful.
7
Name:
Anonymous
2012-12-24 14:49
>>5
Fuck you, trie are way funnier than hash tables.
8
Name:
Anonymous
2012-12-24 15:24
>>7
Return to /g/ you angsty teen
!
9
Name:
Anonymous
2012-12-24 16:41
>>5
You may wish to make your hash table have a length equal to a large prime!
10
Name:
Anonymous
2012-12-24 19:41
One year
This is way too long, I question my design choices only months, sometimes weeks after I write them in the first place.
11
Name:
Anonymous
2014-04-06 0:09
>>5
I imagined your code would be shouted too.
Also, dubs.