|
| 1 | +# eulercli Templates |
| 2 | + |
| 3 | +Templates for programming solutions to [Project Euler] problems. |
| 4 | + |
| 5 | +## Introduction |
| 6 | + |
| 7 | +This repository contains a set of [Project Euler] solution templates written in [julia] and [go]. |
| 8 | + |
| 9 | +These templates are designed to be used with [eulercli] to generate ready-to-use "starting points" for solving Project Euler problems. This is a time-saver, especially if you plan on solving multiple problems. |
| 10 | + |
| 11 | +## Usage |
| 12 | + |
| 13 | +To use these templates, you'll need to install the [eulercli] tool. |
| 14 | + |
| 15 | +Next, create a directory for your Project Euler solutions. We'll refer to this as your "project directory" going forward. |
| 16 | + |
| 17 | +```sh |
| 18 | +mkdir projecteuler |
| 19 | +cd projecteuler |
| 20 | +``` |
| 21 | + |
| 22 | +### "Installing" the eulercli templates |
| 23 | + |
| 24 | +There are several ways to "install" these templates into your project directory. |
| 25 | + |
| 26 | +#### Installing with `eulercli pull` |
| 27 | + |
| 28 | +You can copy these templates into your `projecteuler` directory by running `eulercli pull` in that directory. |
| 29 | + |
| 30 | +```sh |
| 31 | +eulercli pull |
| 32 | +``` |
| 33 | + |
| 34 | +At this point, your `projecteuler` directory should look like this |
| 35 | + |
| 36 | +```sh |
| 37 | +projecteuler/ |
| 38 | + eulercli-templates/ |
| 39 | + julia/ |
| 40 | + [...] |
| 41 | + go/ |
| 42 | + [...] |
| 43 | +``` |
| 44 | + |
| 45 | +`eulercli pull` downloads template files directly from [this github repository](https://github.com/koomen/eulercli-templates), and you can always update your templates by rerunning `eulercli pull`. You can also modify these templates locally or add your own--see the [eulercli README][eulercli] for instructions. |
| 46 | + |
| 47 | +#### Installing with `git clone` |
| 48 | + |
| 49 | +From within your `projecteuler` directory: |
| 50 | + |
| 51 | +```sh |
| 52 | +git clone https://github.com/koomen/eulercli-templates |
| 53 | +``` |
| 54 | + |
| 55 | +### Rendering templates for a specific Project Euler problem |
| 56 | + |
| 57 | +Once you've installed these templates in your project directory, you can use `eulercli generate` to render them for a specific Project Euler problem. |
| 58 | + |
| 59 | +For example, if you'd like to use the [julia programming language][julia] to solve [Problem #1](https://projecteuler.net/problem=1), run the following from within your project directory: |
| 60 | + |
| 61 | +```sh |
| 62 | +eulercli generate 1 --language julia |
| 63 | +``` |
| 64 | + |
| 65 | +If you're doing this for the first time, you should see a new `julia` directory in your `projecteuler` directory: |
| 66 | + |
| 67 | +```sh |
| 68 | +projecteuler/ |
| 69 | + eulercli-templates/ |
| 70 | + julia/ |
| 71 | + initenv.jl |
| 72 | + README.md |
| 73 | + euler0001/ |
| 74 | + solution.jl |
| 75 | +``` |
| 76 | + |
| 77 | +When you run `eulercli generate` again, eulercli will skip existing files as long as they are unchanged by the operation. So, for example, if you run |
| 78 | + |
| 79 | +```sh |
| 80 | +eulercli generate 2 --language julia |
| 81 | +``` |
| 82 | + |
| 83 | +...you should see the following in your `projecteuler` directory: |
| 84 | + |
| 85 | +```sh |
| 86 | +projecteuler/ |
| 87 | + eulercli-templates/ |
| 88 | + julia/ |
| 89 | + initenv.jl |
| 90 | + README.md |
| 91 | + euler0001/ |
| 92 | + solution.jl |
| 93 | + euler0002/ |
| 94 | + solution.jl |
| 95 | +``` |
| 96 | + |
| 97 | +### Running and Benchmarking your solution program |
| 98 | + |
| 99 | +Once you've used `eulercli generate` to render your solution files, you can start work on solving your Project Euler problem. |
| 100 | + |
| 101 | +The process of building, running, and benchmarking your solution programs is different for each language. You can find language-specific instructions in the language README.md files: |
| 102 | + |
| 103 | +- [julia README.md](julia/README.md) |
| 104 | +- [go README.md](go/README.md) |
| 105 | + |
| 106 | +Don't forget you can use `eulercli check` to [check your whether your solution is correct](https://github.com/koomen/eulercli/#check-your-answers-using-pipes). |
| 107 | + |
| 108 | +### Adding your own solution program templates |
| 109 | + |
| 110 | +When you run `eulercli generate --language <langauge>`, the tool will look for templates in `./eulercli-templates/<language>`. |
| 111 | + |
| 112 | +If you'd like to create templates for a new language or modify the templates for an existing language, you can do so by saving them in the `./eulercli-templates/<language>` directory. |
| 113 | + |
| 114 | +Template solution files and filenames can include [text/template package](https://golang.org/pkg/text/template/) directives with the following fields: |
| 115 | + |
| 116 | +- `{{.ProblemNum}}` - the problem number (e.g. "42") |
| 117 | +- `{{.PaddedProblemNum}}` - the problem number, padded with 0s (e.g. "0042") |
| 118 | +- `{{.ProblemText}}` - the problem text (e.g. "The nth term of the sequence of triangle...") |
| 119 | +- `{{.Answer}}` - The correct answer to the problem (e.g. "123") |
| 120 | +- `{{.AnswerMD5}}` - The correct answer to the problem, hashed using [MD5](https://en.wikipedia.org/wiki/MD5) (e.g. "ba1f2511fc30423bdbb183fe33f3dd0f") |
| 121 | + |
| 122 | +For example, calling |
| 123 | + |
| 124 | +```sh |
| 125 | +$ eulercli generate 42 --language julia |
| 126 | +``` |
| 127 | + |
| 128 | +will render the following template file |
| 129 | + |
| 130 | +``` |
| 131 | +./eulercli-templates/julia/src/euler{{.PaddedProblemNum}}/solution.jl |
| 132 | +``` |
| 133 | + |
| 134 | +to the target output file |
| 135 | + |
| 136 | +``` |
| 137 | +./julia/src/euler0042/solution.jl |
| 138 | +``` |
| 139 | + |
| 140 | +If you find ways to improve existing template files or create useful new template files for an as-yet-unsupported language, consider [contributing to this project](#contributing) |
| 141 | + |
| 142 | +## Contributing |
| 143 | + |
| 144 | +Code contributions to eulercli-templates are encouraged and appreciated! If you'd like to contribute, clone this repository, commit your proposed changes, and create a pull request. |
| 145 | + |
| 146 | +<!-- Links --> |
| 147 | + |
| 148 | +[eulercli]: https://github.com/koomen/eulercli |
| 149 | +[go]: https://golang.org |
| 150 | +[julia]: https://julialang.org |
| 151 | +[Project Euler]: https://projecteuler.net |
| 152 | + |
| 153 | + |
| 154 | + |
| 155 | + |
| 156 | + |
| 157 | + |
| 158 | + |
| 159 | + |
0 commit comments