nixify
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
void *malloc();
|
||||
|
||||
main()
|
||||
{
|
||||
int n;
|
||||
int nv;
|
||||
int c;
|
||||
int cmax;
|
||||
int *mem;
|
||||
|
||||
mem = malloc(sizeof(int) * 4000);
|
||||
|
||||
cmax = 0;
|
||||
for (nv = 1; nv < 1000; nv++) {
|
||||
n = nv;
|
||||
c = 0;
|
||||
while (n != 1) {
|
||||
if (n < nv) {
|
||||
c = c + mem[n];
|
||||
break;
|
||||
}
|
||||
if (n & 1)
|
||||
n = 3*n + 1;
|
||||
else
|
||||
n = n / 2;
|
||||
c++;
|
||||
}
|
||||
mem[nv] = c;
|
||||
if (c > cmax)
|
||||
cmax = c;
|
||||
}
|
||||
printf("should print 178: %d\n", cmax);
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
#include <stdio.h>
|
||||
|
||||
main()
|
||||
{
|
||||
int i;
|
||||
int a;
|
||||
int b;
|
||||
int c;
|
||||
int d;
|
||||
|
||||
for (a = 1; a < 1000; a++) {
|
||||
for (b = a + 1; b < 1000; b++) {
|
||||
d = a*a + b*b;
|
||||
for (i = 0; i < 1000; i++) {
|
||||
if (i * i == d) {
|
||||
c = i;
|
||||
if (b < c && a+b+c == 1000) {
|
||||
printf("%d\n", a*b*c);
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
void *calloc();
|
||||
|
||||
int N;
|
||||
int **b;
|
||||
|
||||
board()
|
||||
{
|
||||
int x;
|
||||
int y;
|
||||
|
||||
for (y=0; y<8; y++) {
|
||||
for (x=0; x<8; x++)
|
||||
printf(" %02d", b[x][y]);
|
||||
printf("\n");
|
||||
}
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
chk(int x, int y)
|
||||
{
|
||||
if (x < 0 || x > 7 || y < 0 || y > 7)
|
||||
return 0;
|
||||
return b[x][y] == 0;
|
||||
}
|
||||
|
||||
go(int k, int x, int y)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
|
||||
b[x][y] = k;
|
||||
if (k == 64) {
|
||||
if (x != 2 && y != 0 && abs(x-2) + abs(y) == 3) {
|
||||
board();
|
||||
N++;
|
||||
if (N == 10)
|
||||
exit(0);
|
||||
}
|
||||
} else
|
||||
for (i=-2; i<=2; i++)
|
||||
for (j=-2; j<=2; j++)
|
||||
if (abs(i) + abs(j) == 3 && chk(x+i, y+j))
|
||||
go(k+1, x+i, y+j);
|
||||
b[x][y] = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
main()
|
||||
{
|
||||
int i;
|
||||
|
||||
b = calloc(8, sizeof (int *));
|
||||
for (i=0; i<8; i++)
|
||||
b[i] = calloc(8, sizeof (int));
|
||||
go(1, 2, 0);
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
void *malloc();
|
||||
void *SDL_CreateWindow();
|
||||
void *SDL_CreateRenderer();
|
||||
int SDL_SetRenderDrawColor();
|
||||
int SDL_RenderDrawPoint();
|
||||
int SDL_RenderClear();
|
||||
int SDL_RenderPresent();
|
||||
int SDL_PollEvent();
|
||||
int SDL_DestroyRenderer();
|
||||
int SDL_DestroyWindow();
|
||||
int SDL_Quit();
|
||||
int SDL_Init();
|
||||
|
||||
void *win;
|
||||
void *rnd;
|
||||
int W;
|
||||
int H;
|
||||
int *col;
|
||||
|
||||
plot(int x, int y)
|
||||
{
|
||||
int n;
|
||||
int fx;
|
||||
int fy;
|
||||
int zx;
|
||||
int zy;
|
||||
int nx;
|
||||
int ny;
|
||||
|
||||
fx = (x - W/2)*4000 / W;
|
||||
fy = (y - H/2)*4000 / H;
|
||||
zx = fx;
|
||||
zy = fy;
|
||||
|
||||
for (n=0; n<200; n++) {
|
||||
if (zx*zx + zy*zy > 4000000)
|
||||
break;
|
||||
nx = (zx*zx)/1000 - (zy*zy)/1000 + fx;
|
||||
ny = zx*zy/500 + fy;
|
||||
zx = nx;
|
||||
zy = ny;
|
||||
}
|
||||
n = col[n];
|
||||
SDL_SetRenderDrawColor(rnd, 100, n, n, 255);
|
||||
SDL_RenderDrawPoint(rnd, x, y);
|
||||
return 0;
|
||||
}
|
||||
|
||||
main() {
|
||||
int c;
|
||||
int n;
|
||||
int x;
|
||||
int y;
|
||||
void *e;
|
||||
int *ie;
|
||||
|
||||
W = 800;
|
||||
H = 800;
|
||||
SDL_Init(32);
|
||||
win = SDL_CreateWindow("Mandelbrot MiniC", 0, 0, W, H, 0);
|
||||
rnd = SDL_CreateRenderer(win, -1, 0);
|
||||
e = malloc(56);
|
||||
ie = e;
|
||||
col = malloc(201 * sizeof (int));
|
||||
c = 20;
|
||||
for (n=0; n<200; n++) {
|
||||
col[n] = c;
|
||||
c = c + (255-c)/8;
|
||||
}
|
||||
col[n] = 30;
|
||||
|
||||
SDL_RenderClear(rnd);
|
||||
for (x=0; x<W; x++)
|
||||
for (y=0; y<H; y++)
|
||||
plot(x, y);
|
||||
SDL_RenderPresent(rnd);
|
||||
|
||||
for (;;) {
|
||||
if (SDL_PollEvent(e)) {
|
||||
if (ie[0] == 769)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
SDL_DestroyRenderer(rnd);
|
||||
SDL_DestroyWindow(win);
|
||||
SDL_Quit();
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
#include <stdio.h>
|
||||
|
||||
main() {
|
||||
int n;
|
||||
int t;
|
||||
int c;
|
||||
int p;
|
||||
|
||||
c = 0;
|
||||
n = 2;
|
||||
while (n < 5000) {
|
||||
t = 2;
|
||||
p = 1;
|
||||
while (t*t <= n) {
|
||||
if (n % t == 0)
|
||||
p = 0;
|
||||
t++;
|
||||
}
|
||||
if (p) {
|
||||
if (c && c % 10 == 0)
|
||||
printf("\n");
|
||||
printf("%4d ", n);
|
||||
c++;
|
||||
}
|
||||
n++;
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
int printf();
|
||||
void *calloc();
|
||||
int atoi();
|
||||
|
||||
int Q;
|
||||
int N;
|
||||
int **t;
|
||||
|
||||
print() {
|
||||
int x;
|
||||
int y;
|
||||
|
||||
for (y=0; y<Q; y++) {
|
||||
for (x=0; x<Q; x++)
|
||||
if (t[x][y])
|
||||
printf(" Q");
|
||||
else
|
||||
printf(" .");
|
||||
printf("\n");
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
chk(int x, int y) {
|
||||
int i;
|
||||
int r;
|
||||
|
||||
for (r=i=0; i<Q; i++) {
|
||||
r = r + t[x][i];
|
||||
r = r + t[i][y];
|
||||
if (x+i < Q & y+i < Q)
|
||||
r = r + t[x+i][y+i];
|
||||
if (x+i < Q & y-i >= 0)
|
||||
r = r + t[x+i][y-i];
|
||||
if (x-i >= 0 & y+i < Q)
|
||||
r = r + t[x-i][y+i];
|
||||
if (x-i >= 0 & y-i >= 0)
|
||||
r = r + t[x-i][y-i];
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
go(int y) {
|
||||
int x;
|
||||
|
||||
if (y == Q) {
|
||||
print();
|
||||
N++;
|
||||
return 0;
|
||||
}
|
||||
for (x=0; x<Q; x++)
|
||||
if (chk(x, y) == 0) {
|
||||
t[x][y]++;
|
||||
go(y+1);
|
||||
t[x][y]--;
|
||||
}
|
||||
}
|
||||
|
||||
main(int ac, void **av) {
|
||||
int i;
|
||||
|
||||
Q = 8;
|
||||
if (ac >= 2)
|
||||
Q = atoi(av[1]);
|
||||
t = calloc(Q, sizeof(int *));
|
||||
for (i=0; i<Q; i++)
|
||||
t[i] = calloc(Q, sizeof(int));
|
||||
go(0);
|
||||
printf("found %d solutions\n", N);
|
||||
}
|
||||
Reference in New Issue
Block a user