[Meaningful] ITT we code for a week before posting [Profound] (27)

1 Name: Anonymous : 2009-02-01 05:26 ID:cFnaTVWi (File: 78 kb, 1024x768, C.jpg) [Del]

78 kb, 1024x768
/* need to declare this before visit() */
static void order_vertices(struct cfgstruct *cfg, uint startvextex, uint numvertices, uint *vertices, struct stackstruct* order);
/**  Find and order SCCs with Tarjan's algorithm - recursive.
* See http://www.ics.uci.edu/~eppstein/161/960220.html#sca for more info on Tarjan's
*/
static uint visit(uint p /** Current vertex */, struct stackstruct *L, uint *dfsnum, uint *low, struct cfgstruct *cfg, struct stackstruct* order, uint curnum)
{
L->stack[L->index] = p;
L->index++;
    low[p] = curnum;
    dfsnum[p] = curnum;
    for(uint i = cfg->vertices[p].numexits; i > 0; i--)  /* By doing it in reverse order, the reverse postorder will look nice ordered */
{
uint q = cfg->vertices[p].exits[i - 1];
        switch(dfsnum[q])
{
case UINT_MAX: /* Not yet visited, visit it */
curnum = visit(q, L, dfsnum, low, cfg, order, curnum + 1);
if(low[q] < low[p])
low[p] = low[q];
break;
            case UINT_MAX-1:    /* Visited but no longer on the stack */
break;
            default:    /* Visited and on the stack */
if(dfsnum[q] < low[p])
low[p] = dfsnum[q];
break;
}
}
    if(low[p] == dfsnum[p]) /* Found a (possibly trivial) SCC */
{
uint numvertices = 0;
        uint v;
do
{
L->index--;
v = L->stack[L->index];
dfsnum[v] = UINT_MAX-1; /* No longer to be used */
numvertices++; /* Increase number of vertices in component */
} while(v != p);
        dbgprint(CFG_DEBUG, "Found SCC:");
for(uint j = 0;j < numvertices; j++)
{
dbgprint(CFG_DEBUG, " %d", L->stack[L->index + j]);
}
dbgprint(CFG_DEBUG, "\n");
        if(numvertices == 1)        /* Found a trivial (single vertex) SCC */
{
assert(order->index > 0);
order->index--;
order->stack[order->index] = p; /* Put that vertex in the order */
}
else
{
/* Calculate indegrees from outside the SCC */
uint *indegrees, *insccmap;
indegrees = xcalloc(cfg->numvertices * sizeof(*indegrees));
insccmap = xcalloc(cfg->numvertices * sizeof(*insccmap ));
            for(uint i = 0; i < numvertices; i++)
insccmap[L->stack[L->index + i]] = 1;
            for(uint i = 0; i < cfg->numvertices; i++)
if(insccmap == 0)
for(uint j = 0; j < cfg->vertices[i].numexits; j++)
indegrees[cfg->vertices[i].exits[j]]++;
            xfree(insccmap);
            uint max = 0, maxidx = 0;   /* Default is the first */
            for(uint i = 0; i < numvertices; i++)
{
if(indegrees[L->stack[L->index + i]] > max)
{
max = indegrees[L->stack[L->index + i]];
maxidx = i;
}
}
            dbgprint(CFG_DEBUG, "Highest indegree: %d with %d\n", L->stack[L->index + maxidx], max);
            xfree(indegrees);
            if(numvertices == 2)    /* We know what this will be so no need to recurse again */
{
assert(order->index > 0);
order->index--;
order->stack[order->index] = L->stack[L->index + (maxidx == 0 ? 1 : 0)]; /* Lowest indegree */
                assert(order->index > 0);
order->index--;
order->stack[order->index] = L->stack[L->index + maxidx]; /* Greatest indegree */
}
else /* Sort that */
{
order_vertices(cfg, L->stack[L->index + maxidx], numvertices, &L->stack[L->index], order);
}
}
}
    return curnum;
}
/** Approximately topologically sort all vertices in a graph.
* Strongly connected components are found with Tarjan's algorithm
* and if necessary sorted with this function,
* after choosing the first vertex by indegree.
* We return the SCC's in a reverse postorder.
*/
static void order_vertices(struct cfgstruct *cfg, uint startvertex, uint numvertices, uint *vertices, struct stackstruct* order)
{
uint *dfsnum, *low;
struct stackstruct L;
    L.stack = xmalloc(numvertices * sizeof(*L.stack));    /* This may overallocate a bit, but whatever */
L.index = 0;
    low     = xmalloc(cfg->numvertices * sizeof(*low));
dfsnum = xmalloc(cfg->numvertices * sizeof(*dfsnum));
    for(uint i = 0; i < cfg->numvertices; i++)
dfsnum[i] = UINT_MAX-1; /* All are not to be used unless */
for(uint i = 0; i < numvertices; i++)
dfsnum[vertices[i]] = UINT_MAX; /* they are specifed in the list. */
    dfsnum[startvertex] = UINT_MAX-1;       /* The starting vertex is never to be used */
    /* Emulate the startvertex so it is not in an SCC */
uint curnum = 0;
for(uint i = cfg->vertices[startvertex].numexits; i > 0; i--) /* By doing it in reverse order, the reverse postorder will look nice ordered */
{
uint q = cfg->vertices[startvertex].exits[i - 1];
if(dfsnum[q] == UINT_MAX)
{
curnum = visit(q, &L, dfsnum, low, cfg, order, curnum); /* Do it! */
curnum++;
}
}
    dbgprint(CFG_DEBUG, "Found SCC: %d\n", startvertex);
    assert(order->index > 0);
order->index--;
order->stack[order->index] = startvertex; /* Put the startvertex in the order */
    /* Free stuff */
xfree(L.stack);
xfree(low);
xfree(dfsnum);
}

2 Name: Anonymous : 2009-02-02 16:24 ID:f7B8s64G [Del]

puts "nice tiled screenshot";

3 Name: Anonymous : 2009-02-04 20:42 ID:zY.R.aDm [Del]

this is PROGressive Rock, NOT PROGraming! >_>

4 Name: Anonymous : 2009-02-04 22:18 ID:Heaven [Del]

>>3 needs to lurk more.

5 Name: Anonymous : 2009-02-08 05:01 ID:aPaDuV05 [Del]

echo -e ">>3,4 Didn\'t code for a week"

6 Name: : 2009-02-08 09:17 ID:sylXifVG [Del]

totient n = length $ filter (\p -> gcd p n == 1) [1 .. n - 1]
cototient n = n - totient n
main = do putStrLn(show(map cototient [1 .. 50]))

It took me FUCKING 100 HOURS to get this to work right.

7 Name: Anonymous : 2009-02-08 15:25 ID:7C3a3Ssy [Del]

>>6

print "toilet";

8 Name: Anonymous : 2009-02-09 06:53 ID:uqbOexcD [Del]

>>7
lol.

Totients are weird, I've only seen them used in crypto stuff, like generating keys for RSA.
At first I was trying to figure out how to generate the series of highly totient numbers (http://www.research.att.com/~njas/sequences/A097942) but my maths and Haskell skills just aren't good enough, so I just settled on being satisfied that I managed to get the cototient function to work right.

9 Name: Anonymous : 2009-02-24 08:39 ID:mvT.1SZe [Del]

-- -*- haskell -*-
primeTest n=all((0/=).mod n)$takeWhile(<=floor(sqrt$fromIntegral n))$drop 3 primes
primes=2:3:5:7:[k+r|k<-[0,30..],r<-[11,13,17,19,23,29,31,37],primeTest(k+r)]
isPrime n=elem n$takeWhile(<=n)primes

10 Name: Anonymous : 2009-02-24 11:23 ID:o9k3oMFB [Del]

[rem]-*- bbcode -*-[/rem]
[define=expert text][b][u][i][o]text[/o][/i][/u][/b][/define]
[define=foldr=tag text][if=text][tag][car]text[/car][foldr=tag][cdr]text[/cdr][/foldr][/tag][/if][/define]
[expert][foldr=spoiler]EXPERT BBCODE METAPROGRAMMER[/foldr][/expert]

THIS BOARD NEEDS BBCODE :(

11 Name: Anonymous : 2009-02-24 12:42 ID:EvVBI.qq [Del]

showPosts = inBase . mapM_ (puts . ("   " ++) . show) . M.toList =<< getPosts
clearPosts = mapM_ removePost . M.keys =<< getPosts

12 Name: Anonymous : 2009-02-25 07:17 ID:Heaven [Del]

>>10

-- -*- haskell -*-
putStr$cycle"NO IT DOESN'T!"

13 Name: Anonymous : 2009-03-12 13:35 ID:8sb2DyE1 [Del]

Этот тред состоит из: УНЫЛОСТЬ и ФАГГОТОРИЯ.

14 Name: Anonymous : 2009-03-13 05:11 ID:8/yYe9o3 [Del]

# -*- py -*-
def factorial(n):
if not isinstance(n, (int, long)): raise TypeError("expected %s but got %s" % ((int, long), type(n)))
if n < 0: raise ValueError("%d is less than 0" % n)
if n < 2: return 1
global N
p = r = N = high = 1
h = shift = 0
def floorlog2(n):
a = 0
while n > 1:
n >>= 1
a += 1
return a
log2n = floorlog2(n)
def product(n):
global N
m = n / 2
if m == 0:
N += 2
return N
if n == 2:
N += 4
return N * (N - 2)
return product(n - m) * product(m)
while h != n:
shift += h
h = n >> log2n
log2n -= 1
len = high
high = (h - 1) | 1
len = (high - len) / 2
if len > 0:
p *= product(len)
r *= p
return r << shift

15 Name: Anonymous : 2009-03-26 23:30 ID:e.HXkUNJ [Del]

# -*- ruby -*-
def satori
[]
end
$hybt = satori()
def yhbt?
true unless $hybt.join != ("yhbt")
end
def method_missing(abelson,*harold)
$hybt << abelson.to_s[0,1]
satori = satori()
if yhbt?
%w{Gerald Jay Sussman SICP}.each_with_index{|snake, grunnur| satori[grunnur] = snake.length; @gjs = snake.upcase if grunnur == 2}
((satori[0]+satori[3])*(satori[1]+satori[2])*satori[1]).times{puts @gjs}
end
end
have you read your poignant guide to ruby today? bacon how yummy?

16 Post deleted by user.

17 Name: Anonymous : 2009-03-29 23:37 ID:y/d4eW9U [Del]

>>15

?- satori(ruby).
no

18 Name: Anonymous : 2009-03-31 04:45 ID:uDDNPhKJ [Del]

: loeb ( f -- g ) dup [ loeb swap call ] curry fmap ;

too bad it doesn't seem to work.

19 Name: Anonymous : 2009-03-31 08:14 ID:Heaven [Del]

>>17
yhbt

20 Post deleted by user.

21 Post deleted by user.

22 Name: Leon Kaiser !!YkPAJRP/ : 2010-09-18 17:55 ID:xeX9uobq [Del]

# -*- py -*-
def popcap(whitey):
whitey.pop()
return

23 Name: Anonymous : 2010-09-18 17:59 ID:FvA7KgQe [Del]

In Soviet Russia, week codes you!

24 Name: Leon Kaiser !!YkPAJRP/ : 2010-09-19 10:32 ID:6bqMpWId [Del]

# -*- py -*-
def isblack(dong):
if dong > 6: # they also have viruses
dong = long(dong) # White boy got a big dick
else:
pump(dong) # White boy got a small dick
return

25 Name: !UzAznSUAVE : 2010-10-16 08:21 ID:Heaven [Del]

>>1
see, that is why images are stupid on a programming board.
it's a stupid picture that doesn't add anything to the post, and breaks the indentation.

26 Name: Anonymous : 2011-02-09 18:44 ID:Heaven [Del]

>>24
PLURAL OF VIRUS IS STILL VIRUS

YHBT

27 Name: Anonymous : 2011-03-27 20:45 ID:Heaven [Del]

>>26
ONLY IN LATIN, NOT IN ENGLISH

YHBT

Name: Link:
Spam trap (don't touch):
File: