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

Pages: 1-

\prog\ challenge

Name: Anonymous 2020-09-09 19:33

Just post any fucking code, can be fibs or even hello world

Name: Anonymous 2020-09-09 19:37

any fucking code

Array.from (document.getElementsByClassName ("trip")).forEach (e => { e.parentNode.parentNode.children [1].innerHTML = "I am a child seeking attention."; })

Name: Anonymous 2020-09-09 21:05

Password 12345

Name: Anonymous 2020-09-10 0:49

console.log("expert programmer's" ) ;

Name: Anonymous 2020-09-10 1:16

#include <stdio.h>
#include <stdlib.h>

char* b36(int n) {
static char buf[99];
int len = 0;
char *dig = "0123456789abcdefghijklmnopqrstuvwxyz";
if(!n) { buf[len++] = dig[0]; buf[len] = 0; return buf; }

int sgn = (n < 0); n = abs(n);

while(n) { buf[len++] = dig[n % 36]; n /= 36; }
if(sgn) buf[len++] = '-';
buf[len] = 0;

for(int i = 0, j = len-1; i < j; i++,j--) {
int x = buf[i], y = buf[j];
buf[i] = y; buf[j] = x;
}
return buf;
}

int main(int argc, char *argv[]) {
if(argc <= 1) {
printf("usage: b36 <number> [<number>...]\n");
exit(0);
}

while(argc > 1) {
int n = atoi(argv[1]);
printf("%d -> %s\n", n, b36(n));
argc--; argv++;
}
return 0;
}

Name: Anonymous 2020-09-10 5:29

//test file for void3 enum class
#include <stdio.h>
#include <stdint.h>
#define atype __auto_type
#define enumc(name,...) typedef union{}name;name __VA_ARGS__;
#define istype(x,type) (_Generic((x),type:1,default:0))
int main(){
enumc(Colors,Red,Blue,Yellow,Green);
Colors Purple=Red;
atype Black=Blue;
printf("%d:%d,%d:%d",istype(Purple,Colors),istype(Black,int),sizeof(Red),sizeof(Blue));
}

Name: Anonymous 2020-09-10 7:20

>>5 I didn't like this so i've made my version:
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
char* lltoa(int64_t inp,int base){
const char bases_str[]="0123456789abcdefghijklmnopqrstuvwxyz";
size_t i=127;static char buf[128]={0};
char sgn=(inp<0)?inp=-inp,'-':' ';
do{buf[i--]=bases_str[inp%base];inp/=base;}while(inp );
buf[i]=sgn;return &buf[i];}
int main(int argc,char**argv){

for(int i=1;i<argc;i++){printf("%s\n\n",lltoa(atoll(argv[i]),36));}
Edited on 10/09/2020 07:21.

Name: Anonymous 2020-09-10 8:41

>>6 What is that...? http://www.robertgamble.net/2012/01/c11-generic-selections.html

>>5
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <inttypes.h>

int64_t atoi64(char *str) {
int64_t n = 0;
sscanf(str, "%" PRId64, &n);
return n;
}

char* to_base(int base, int64_t num) {
if(base < 2 || 36 < base) return "???";

// include some padding
static char buffer[8*64 + 4] = {0};
char *str = (buffer + sizeof(buffer) - 2);

// long long is at least 64-bit
int sign = (num < 0); num = llabs(num);

do
{
*str-- = (num % base)["0123456789abcdefghijklmnopqrstuvwxyz"];
num /= base;
}
while(num);

if(sign) *str = '-'; else str++;
return str;
}

int main(int argc, char *argv[]) {
if(argc-1 < 1) {
puts("usage: to-base <use-base> [<decimal-number>...]");
exit(1);
}

int base = atoi(argv[1]);
for(int i = 2; i < argc; i++) {
int64_t num = atoi64(argv[i]);
printf("%" PRId64 " = %d#%s\n", num, base, to_base(base, num));
}
return 0;
}

Name: Anonymous 2020-09-10 9:24

>>8
A type-safe zero-overhead Enum Class.
#define atype __auto_type
#define enumc(name,...) typedef union{}name;name __VA_ARGS__;
#define istype(x,type) (_Generic((x),type:1,default:0))

#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
int main(int argc,char**argv){
enumc(Colors,Red,Blue,Yellow,Green);
Colors Purple=Red;
atype Black=Blue;
#define isblue(x) (&Blue==&x)
#define isgreen(x) (&Green==&x)
#define ispurple(x) (&Purple==&x)
printf("%d:%d,%d:%d \n%d:%d,%d:%d,",istype(Purple,Colors),istype(Black,int),isblue(Blue),isblue(Red),
isblue(Black),ispurple(Purple),isblue(Yellow),isgreen(Green));

}

Name: Anonymous 2020-09-10 10:13

>>9
Note that it exists at compile time and is mostly used with macros, not passed to functions (it doesn't make sense to pass empty structs either).
#define iseq(x,y) (x==y)
int iscolorx(Colors* x,Colors* y){return x==y;}
printf("Red:%p;Black:%p ;%d:%d\n",&Red,&Black,iseq(&Red,&Black),iscolorx(&Red,&Black));
Result:
Red:0x7ffc036f8400;Black:0x7ffc036f8400 ;0:1 //gcc with no optimization Edited on 10/09/2020 10:26.

Name: Anonymous 2020-09-13 23:15

#include <stdio.h>

int fib(int n)
{
return n < 2 ? n : fib(n - 2) + fib(n - 1);
}

int main()
{
for (int i = 1; i <= 10; ++i)
printf("%d\n", fib(i));

return 0;
}

Name: Anonymous 2020-09-13 23:44

test

Name: Anonymous 2020-09-14 12:30

>>12
test failed
YHBT
HAND

Name: Anonymous 2020-09-14 19:58

Output: https://files.catbox.moe/kpo3xt.png

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#define W 640
#define H 480
int screen[H][W];

void imgout(char *fn) {
FILE *f = fopen(fn, "w");
fprintf(f, "P2\n%d %d\n%d\n", W, H, 255);

for(int j = 0; j < H; j++) for(int i = 0; i < W; i++) fprintf(f, "%d\n", screen[j][i]);
fclose(f);
}

void p(double x, double y) {
int xx = (int)x, yy = (int)y;
if(xx < 0 || W <= xx || yy < 0 || H <= yy) return;
screen[yy][xx] = 255;
}

void line(double x, double y, double A, double r) {
int x1 = (int)x, x2 = (int)(x + r*cos(-A));
int y1 = (int)y, y2 = (int)(y + r*sin(-A));
int steps = 2 + abs(x2-x1) + abs(y2+y1); // overestimation...
for(int i = 0; i <= steps; i++) {
x = i*x2 + (steps-i)*x1; x /= steps;
y = i*y2 + (steps-i)*y1; y /= steps;
p(x, y);
}
}

void point(double x, double y, double A, double r, double *outx, double *outy) {
double xx = x + r*cos(-A);
double yy = y + r*sin(-A);
*outx = xx; *outy = yy;
}

double d2r(double degrees) { return (degrees * M_PI / 180.0); }

void segment(int depth, double x, double y, double A, double r) {
if(depth <= 0) { line(x, y, A, r); return; }

segment(depth-1, x, y, A, (r/3)); point(x, y, A, (r/3), &x, &y); A += d2r(+60);
segment(depth-1, x, y, A, (r/3)); point(x, y, A, (r/3), &x, &y); A += d2r(-120);
segment(depth-1, x, y, A, (r/3)); point(x, y, A, (r/3), &x, &y); A += d2r(+60);
segment(depth-1, x, y, A, (r/3));
}

int main() {
double K = 0.5 * (H - (double)W / 3.0 * sin(d2r(60)));
segment(7, 0, H-K, 0.0, W);
imgout("koch.ppm");
return 0;
}

Name: Anonymous 2020-09-20 0:54

10 PRINT "FUCK LOL"
20 GOTO 10

Name: Anonymous 2020-09-20 3:05

But without League Of Legends there would be no Ahri/D.Va yuri.

Name: Anonymous 2020-09-20 10:43

>>16
Good.

Name: Anonymous 2020-09-20 13:10

>>16
it would be called something else.

Name: Anonymous 2020-09-20 13:38

>>18
As long as it's fox/bunny with adults, instead of the usual garbage with children, that would be fine.

Name: Anonymous 2020-09-21 14:50

#include <sys/types.h>
#include <unistd.h>
void main(){while(1){fork();}}

Name: Anonymous 2020-09-21 15:24

>>20
VIRUS DONT CLICK!!!!111

Name: Anonymous 2020-09-23 16:22

>>20 Portable alternative
int main(){while(1){return main();}}

Name: Anonymous 2020-09-23 16:44

Not as portible... A binary executable is required, LLVM bitcode or other C interpreters may run only once.

#include <stdio.h>
#include <unistd.h>

int main(int argc, char *argv[]) {
printf("Hello, World!\n");
usleep(100000);
execvp(argv[0], argv);
}

Name: Anonymous 2020-09-28 23:00

// https://fabiensanglard.net/fizzlefade/index.php
// uses a LCG instead of LFSR

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

enum { W=80, H=24, N=(W*H) };
enum { A=37, B=39 }; // relatively prime A, B, N
int array[N];

#define pr(...) do { printf( __VA_ARGS__); fflush(stdout); } while(0)
void gotoxy(int col, int row) { pr("\e[%d;%dH", row+1, col+1); }
void clear() { pr("\e[H\e[J"); }

int main() {
int pos = rand() % N;
clear();

for(int i = 0; i < N; i++) {
int row = pos / W, col = pos % W;
usleep(10000);
gotoxy(col, row);
if(array[pos]++) pr("="); else pr("*");
pos = (A*pos + B) % N; // Linear Congruence Generator (LCG)
}
gotoxy(0, H);
return 0;
}

Name: Anonymous 2020-09-28 23:19

Name: Anonymous 2020-09-29 8:16

>>24
Cant you just use shuffle table for that?

Name: Anonymous 2020-09-29 22:25

>>26
Yes, it would take more memory but yes. I was hoping to autogenerate a full-period PRNG for any given length.

I don't understand the theory but a full-period LCG has 3 conditions:

* the addition constant relatively prime
* the multiply constant is +1 from multiple of prime factors (other factors may be included too)
* if the modulus was multiple of 4, the multiple constant needs to be also

That article used a LFSR PRNG but a LCG wouldn't need to be a power of two, it should be more flexible!

(my original code used a different sized rectangle and worked by coincidence)

Using 1 as the addition constant and using above conditions to generate multiply constant "works" but doesn't look as nicely as it should. :/

Some of the theory behind LCG's was punlished in 1966 but I can't find the reference. A LCG was also used by a mathematician from Berkley on the ENIAC, he drove his family accross the country to Pennsylvania to get access to it! The Fisher–Yates shuffle algorithm was invented in 1938 before they even had ENIAC!

Name: Anonymous 2020-10-05 7:25

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

char rot13(char ch) {
static char *alpha = "abcdefghijklmnopqrstuvwxyz"
"abcdefghijklmnopqrstuvwxyz"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
char *x = strchr(alpha, ch);
if(x) return x[13];
else return ch;
}

int main(int argc, char *argv[]) {
if(argc <= 1) {
printf("usage: rot13 <msg> [<msg>...]\n");
exit(1);
}

for(int i = 1; i < argc; i++) {
char *str = argv[i];
while(*str) putchar(rot13(*str++));
putchar('\n');
}
return 0;
}

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