Skip to content

A set of templates for programming solutions to Project Euler problems

License

Notifications You must be signed in to change notification settings

koomen/eulercli-templates

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

eulercli Templates

Templates for programming solutions to Project Euler problems.

Introduction

This repository contains a set of Project Euler solution templates written in julia and go.

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.

Usage

To use these templates, you'll need to install the eulercli tool.

Next, create a directory for your Project Euler solutions. We'll refer to this as your "project directory" going forward.

mkdir projecteuler
cd projecteuler

"Installing" the eulercli templates

There are several ways to "install" these templates into your project directory.

Installing with eulercli pull

You can copy these templates into your projecteuler directory by running eulercli pull in that directory.

eulercli pull

At this point, your projecteuler directory should look like this

projecteuler/
    eulercli-templates/
        julia/
            [...]
        go/
            [...]

eulercli pull downloads template files directly from this github repository, 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 for instructions.

Installing with git clone

From within your projecteuler directory:

git clone https://github.com/koomen/eulercli-templates

Rendering templates for a specific Project Euler problem

Once you've installed these templates in your project directory, you can use eulercli generate to render them for a specific Project Euler problem.

For example, if you'd like to use the julia programming language to solve Problem #1, run the following from within your project directory:

eulercli generate 1 --language julia

If you're doing this for the first time, you should see a new julia directory in your projecteuler directory:

projecteuler/
    eulercli-templates/
    julia/
        initenv.jl
        README.md
        euler0001/
            solution.jl

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

eulercli generate 2 --language julia

...you should see the following in your projecteuler directory:

projecteuler/
    eulercli-templates/
    julia/
        initenv.jl
        README.md
        euler0001/
            solution.jl
        euler0002/
            solution.jl

Running and Benchmarking your solution program

Once you've used eulercli generate to render your solution files, you can start work on solving your Project Euler problem.

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:

Don't forget you can use eulercli check to check your whether your solution is correct.

Adding your own solution program templates

When you run eulercli generate --language <langauge>, the tool will look for templates in ./eulercli-templates/<language>.

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.

Template solution files and filenames can include text/template package directives with the following fields:

  • {{.ProblemNum}} - the problem number (e.g. "42")
  • {{.PaddedProblemNum}} - the problem number, padded with 0s (e.g. "0042")
  • {{.ProblemText}} - the problem text (e.g. "The nth term of the sequence of triangle...")
  • {{.Answer}} - The correct answer to the problem (e.g. "123")
  • {{.AnswerMD5}} - The correct answer to the problem, hashed using MD5 (e.g. "ba1f2511fc30423bdbb183fe33f3dd0f")

For example, calling

$ eulercli generate 42 --language julia

will render the following template file

./eulercli-templates/julia/src/euler{{.PaddedProblemNum}}/solution.jl

to the target output file

./julia/src/euler0042/solution.jl

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

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.

About

A set of templates for programming solutions to Project Euler problems

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published