A makefile and some random fixes
This commit is contained in:
parent
6f7482b9f3
commit
1c210b879d
7 changed files with 47 additions and 13 deletions
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
*.o
|
||||
build/
|
||||
26
Makefile
Normal file
26
Makefile
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
|
||||
CC = gcc
|
||||
CFLAGS = -Wall -pedantic -ansi
|
||||
LDFLAGS = -lm -lgmp
|
||||
BUILDDIR = build
|
||||
LIBDIR = lib
|
||||
|
||||
STRIP = strip
|
||||
RMDIR = rm -fr
|
||||
RM = rm -f
|
||||
|
||||
p% : p%.c
|
||||
mkdir -p $(BUILDDIR)
|
||||
$(CC) $(CFLAGS) $(LDFLAGS) $^ -o $(BUILDDIR)/$@
|
||||
$(STRIP) $(BUILDDIR)/$@
|
||||
|
||||
p7 : p7.c $(LIBDIR)/prime.o
|
||||
p10 : p10.c $(LIBDIR)/prime.o
|
||||
p12 : p12.c $(LIBDIR)/prime.o
|
||||
|
||||
$(LIBDIR)/%.o : $(LIBDIR)/%.c
|
||||
$(CC) $(CFLAGS) -c $< -o $@
|
||||
|
||||
clean :
|
||||
$(RMDIR) $(BUILDDIR)
|
||||
$(RM) $(LIBDIR)/*.o
|
||||
2
p10.c
2
p10.c
|
|
@ -19,7 +19,7 @@ int main() {
|
|||
if (is_prime(i))
|
||||
s += i;
|
||||
}
|
||||
printf("%lli\n", s); /* this format throws som warnings but works so whatever */
|
||||
printf("%li\n", s);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
14
p11.c
14
p11.c
|
|
@ -20,6 +20,7 @@
|
|||
/* macro for checking all directions of a square x,y */
|
||||
#define check_square(x, y) \
|
||||
do { \
|
||||
int p; \
|
||||
if (x < 17) \
|
||||
setprod(px(x, y)); \
|
||||
if (y < 17) \
|
||||
|
|
@ -30,6 +31,13 @@
|
|||
setprod(prd(x, y)); \
|
||||
} while(0)
|
||||
|
||||
#define setprod(x) \
|
||||
do { \
|
||||
p = x; \
|
||||
if (p > result) \
|
||||
result = p; \
|
||||
} while(0)
|
||||
|
||||
int grid[20][20] = {
|
||||
{ 8, 2, 22, 97, 38, 15, 0, 40, 0, 75, 4, 5, 7, 78, 52, 12, 50, 77, 91, 8 },
|
||||
{ 49, 49, 99, 40, 17, 81, 18, 57, 60, 87, 17, 40, 98, 43, 69, 48, 4, 56, 62, 0 },
|
||||
|
|
@ -55,12 +63,6 @@ int grid[20][20] = {
|
|||
|
||||
unsigned int result = 0;
|
||||
|
||||
void inline setprod(int p) {
|
||||
|
||||
if (p > result)
|
||||
result = p;
|
||||
}
|
||||
|
||||
int main() {
|
||||
|
||||
int x, y;
|
||||
|
|
|
|||
12
p2.c
12
p2.c
|
|
@ -11,16 +11,18 @@
|
|||
|
||||
int main() {
|
||||
|
||||
int c = 0, a = 1, b = 1, r = 0;
|
||||
int a = 1, b = 1, r = 0;
|
||||
|
||||
while(c < 4000000) {
|
||||
for(;;) {
|
||||
|
||||
c = a + b;
|
||||
int c = a + b;
|
||||
a = b;
|
||||
b = c;
|
||||
|
||||
if (!(c & 1))
|
||||
|
||||
if (~c & 1)
|
||||
r += c;
|
||||
if (c >= 4000000)
|
||||
break;
|
||||
}
|
||||
|
||||
printf("%i\n", r);
|
||||
|
|
|
|||
2
p4.c
2
p4.c
|
|
@ -50,7 +50,7 @@ int main() {
|
|||
if (!ispalindrom(r) || !(a = factor(r)))
|
||||
continue;
|
||||
|
||||
printf("%i * %i = %i\n", r/a, a, r);
|
||||
printf("%i\n", r);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
|||
2
p6.c
2
p6.c
|
|
@ -19,4 +19,6 @@ int main() {
|
|||
}
|
||||
|
||||
printf("%i\n", s2*s2 - s1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue