Programming challenges

Programming challenges

...

here's a challenge

Move out of your mom's basement. And you can't use C.

roll thread?

...

No

rol :D

reroll..

reeeeeeee roll

that's pretty good

rolo senpai

rolling rolling etc.

rolling

rollin - g herbo

rolling for 2, the only option

...

Roll

I rolled blackjack on the last thread.

> 1/2
/*
* bj.c - Play against the computer
*
* Compilation: cc -o bj bj.c
* Usage: ./bj
*
* Copyright (C) 2016, Anonymous.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND ANONYMOUS DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL ANONYMOUS BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/

#include
#include
#include

typedef struct c_s {
char *num;
int val;
} card;

typedef struct h_s {
card *c[11];
size_t n;
int s;
int d;
} hand;

card sorted_deck[52] = {
{ "A", 1}, { "A", 1}, { "A", 1}, { "A", 1},
{ "2", 2}, { "2", 2}, { "2", 2}, { "2", 2},
{ "3", 3}, { "3", 3}, { "3", 3}, { "3", 3},
{ "4", 4}, { "4", 4}, { "4", 4}, { "4", 4},
{ "5", 5}, { "5", 5}, { "5", 5}, { "5", 5},
{ "6", 6}, { "6", 6}, { "6", 6}, { "6", 6},
{ "7", 7}, { "7", 7}, { "7", 7}, { "7", 7},
{ "8", 8}, { "8", 8}, { "8", 8}, { "8", 8},
{ "9", 9}, { "9", 9}, { "9", 9}, { "9", 9},
{"10",10}, {"10",10}, {"10",10}, {"10",10},
{ "J",10}, { "J",10}, { "J",10}, { "J",10},
{ "Q",10}, { "Q",10}, { "Q",10}, { "Q",10},
{ "K",10}, { "K",10}, { "K",10}, { "K",10}
};

void calc_pts(hand *h)
{
size_t i;
h->s = 0;
for (i=0; i < h->n; i++)
h->s += h->c[i]->val;
for (i=0; i < h->n; i++)
if (h->c[i]->val == 1 && h->s s += 10;
}

> Error: Too many lines.
> 2/3
void pr_h(hand *h)
{
size_t i, j;
for (i=0; inum);
printf("\t%d\n\n", h[i].s);
}
}

void hit(card **d, hand *h, size_t *t)
{
h->c[h->n] = d[*t];
h->n++;
calc_pts(h);
(*t)++;
}

void shuf(card **d)
{
size_t i, j, t, s[52];
for (i=0; i

> 3/3
int main(void)
{
char buf[10];
hand *h;
card **d;
size_t t;
h = calloc(2, sizeof(hand));
d = calloc(52, sizeof(card *));
srandom(time(0));
while (1) {
printf("'D'eal or 'Q'uit?\n> ");
fflush(stdout);
if (!fgets(buf, 10, stdin))
goto quit;
switch (buf[0]) {
case 'q':
case 'Q':
goto quit;
case 'd':
case 'D':
shuf(d);
t = 0;
h[0].d = 0; h[1].d = 0; h[0].n = 0; h[1].n = 0;
hit(d, &h[1], &t);
hit(d, &h[0], &t);
hit(d, &h[1], &t);
hit(d, &h[0], &t);
if (h[1].s == 21 && h[0].s != 21) {
pr_h(h);
printf("Blackjack! Player wins, %d to %d.\n",
h[1].s, h[0].s);
break;
}
while (h[0].d == 0 || h[1].d == 0) {
pr_h(h);
if (h[1].d == 0) {
printf("'H'it, 'S'tand or 'Q'uit?\n > ");
fflush(stdout);
if (!fgets(buf, 10, stdin))
goto quit;
switch (buf[0]) {
case 'h':
case 'H':
hit(d, &h[1], &t);
break;
case 's':
case 'S':
h[1].d = 1;
break;
case 'q':
case 'Q':
goto quit;
}
if (h[1].s >= 21) {
pr_h(h);
h[1].d = 1;
}
}
if (h[0].d == 0) {
if (h[0].s < 17)
hit(d, &h[0], &t);
else
h[0].d = 1;
}
}
if (h[1].s 21 || h[1].s > h[0].s))
printf("Player wins, %d to %d.\n",
h[1].s, h[0].s);
else
printf("Dealer wins, %d to %d.\n",
h[0].s, h[1].s);
}
}
quit:
free(h);
free(d);
return 0;
}

> 3/3
> now slightly more legible
int main(void)
{
char buf[10];
hand *h;
card **d;
size_t t;
h = calloc(2, sizeof(hand));
d = calloc(52, sizeof(card *));
srandom(time(0));
while (1) {
printf("'D'eal or 'Q'uit?\n> ");
fflush(stdout);
if (!fgets(buf, 10, stdin))
goto quit;
switch (buf[0]) {
case 'q':
case 'Q':
goto quit;
case 'd':
case 'D':
shuf(d);
t = 0;
h[0].d = 0; h[1].d = 0; h[0].n = 0; h[1].n = 0;
hit(d, &h[1], &t);
hit(d, &h[0], &t);
hit(d, &h[1], &t);
hit(d, &h[0], &t);
if (h[1].s == 21 && h[0].s != 21) {
pr_h(h);
printf("Blackjack! Player wins, %d to %d.\n",
h[1].s, h[0].s);
break;
}
while (h[0].d == 0 || h[1].d == 0) {
pr_h(h);
if (h[1].d == 0) {
printf("'H'it, 'S'tand or 'Q'uit?\n > ");
fflush(stdout);
if (!fgets(buf, 10, stdin))
goto quit;
switch (buf[0]) {
case 'h':
case 'H':
hit(d, &h[1], &t);
break;
case 's':
case 'S':
h[1].d = 1;
break;
case 'q':
case 'Q':
goto quit;
}
if (h[1].s >= 21) {
pr_h(h);
h[1].d = 1;
}
}
if (h[0].d == 0) {
if (h[0].s < 17)
hit(d, &h[0], &t);
else
h[0].d = 1;
}
}
if (h[1].s 21 || h[1].s > h[0].s))
printf("Player wins, %d to %d.\n",
h[1].s, h[0].s);
else
printf("Dealer wins, %d to %d.\n",
h[0].s, h[1].s);
}
}
quit:
free(h);
free(d);
return 0;
}

Roll, even though obviously I'm never going to do it.

rolling
will do if not trivial

roll

...

Oh fuck it's already been posted

>got bootloader one time
>didn't know how to do it
>tried anyways
>learned a fuckton in the process
>didn't succeed
>still understand way more about computers ~outside the operating system~ than i did before

ALWAYS try your challenges

roll

Rolling

rollan

rawl

km

Reeeolll

> (OP)
>
>roll thread?
Rolling

> (OP)
>
>roll thread?
Fuckme

Rawr XD

Rolling hard

relll

roll, hoping for something easy

Which one for meeeeee