- peN.c : template to start your solution
- projecteuler.h : a library to set up things easy
- projecteuler.c : functions you collect while learning
- To create your first exercise using
make. Suppose you are programming exercise number 1154. Then do:- make euler N=1154
This will copy and correct automatically the name of the exercise. It would be the same as manually do:
- Copy peN.c as your new exercise. Suppose your are now solving the exercise number 1154, then do:
$ cp peN.c pe1154.c Now open it with your preferred text editor that I'm sure is vi:
$ vi pe1154.c -
In the file
pe1154.c:- In the comments, right at the second line, don't forget to correct the file name by changing
PEN.ctope1154.c - Line number 32, you will find a
#definethat needs also to reflect the exercise number you are solving.
- In the comments, right at the second line, don't forget to correct the file name by changing
Change it from:
#define PEN pe ## N to:
#define PEN pe ## 1154 -
What now?
- Don't change anything in function
main(). Let it there as is. Your project starts in the functionPEN()bellowmain(). - Immediately before function
PEN(), copy and paste as a comment the Project Euler Question Text, that is, the description of the problem you need to solve. - Go for it! You can write your code all inside
PEN()or create bellow it as many auxiliary functions as you need.
- Don't change anything in function
-
File
projecteuler.candprojecteuler.h:- If, while solving one hard problem, you come up with a nice math function that you suppose you will need again soon, don't hesitate to update the library and add your contribution to it. Next exercise you do, you will be able to just use whatever you created before.
- There is a makefile there to help you. To compile, use:
$ make pe1154.x SRC=projecteuler.c - If you are into
versions, you can set them as:
$ make pe1154.x SRC=projecteuler.c MAJOR=4 MINOR=2 - If
scanf()gives you warnings you don't care about (return value ignored forscanfor such), you can easy it by:
$ make pe1154.x SRC=projecteuler.c MAJOR=4 MINOR=2 FORTIFY=0 - There are other options you might want:
- Turn off
DEBUGmode and compile with fast optimizations with:DEBUG=0 - Define something on your own.
- If it is an integer, just do: D=SOMETHING=INTEGER
- If you want a char, then: D="SOMETHING='A'"
- To see more options,
vi makefileand look the variables there.
- Turn off
- This document and templates were created by:
- Prof. Ruben Carlo Benante
- Email. rcb at beco dot cc
- Date: 2017-11-30
- License: GPL v3