├── .editorconfig ├── .eslintrc ├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── gulpfile.js ├── package.json ├── problems.txt ├── solutions ├── 001.js ├── 002.js ├── 003.js ├── 004.js ├── 005.js ├── 006.js ├── 007.js ├── 008.js ├── 009.js └── 010.js └── test ├── answers.json ├── testAnswers.js └── testLastAnswer.js /.editorconfig: -------------------------------------------------------------------------------- 1 | # top-most EditorConfig file 2 | root = true 3 | 4 | # Unix-style newlines with a newline ending every file 5 | [*] 6 | end_of_line = lf 7 | insert_final_newline = true 8 | 9 | # Set default charset 10 | [*.{js,json}] 11 | charset = utf-8 12 | 13 | [*.js] 14 | indent_style = space 15 | indent_size = 4 16 | 17 | [{package.json,.travis.yml}] 18 | indent_style = space 19 | indent_size = 2 -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "eslint:recommended", 3 | "env": { 4 | "mocha": true, 5 | "es6": true, 6 | "node": true 7 | }, 8 | "rules": { 9 | "no-extra-parens": 1, 10 | "no-eval": 2, 11 | "no-multi-spaces": 1, 12 | "no-undef-init": 2, 13 | "no-use-before-define": 2, 14 | "no-process-exit": 2, 15 | "array-bracket-spacing": [1, "never"], 16 | "block-spacing": [1, "always"], 17 | "brace-style": 1, 18 | "camelcase": 1, 19 | "comma-spacing": [2, {"before": false, "after": true}], 20 | "computed-property-spacing": [2, "never"], 21 | "indent": 2, 22 | "key-spacing": [2, {"beforeColon": false, "afterColon": true}], 23 | "max-len": [2, 120, 4, {"ignoreComments": true, "ignoreUrls": true}], 24 | "no-array-constructor": 2, 25 | "no-multiple-empty-lines": 1, 26 | "no-trailing-spaces": 1, 27 | "semi": [2, "always"], 28 | "spaced-comment": [1, "always"], 29 | "no-const-assign": 2, 30 | "no-var": 2, 31 | "prefer-template": 1 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | 5 | # Runtime data 6 | pids 7 | *.pid 8 | *.seed 9 | 10 | # Directory for instrumented libs generated by jscoverage/JSCover 11 | lib-cov 12 | 13 | # Coverage directory used by tools like istanbul 14 | coverage 15 | 16 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 17 | .grunt 18 | 19 | # node-waf configuration 20 | .lock-wscript 21 | 22 | # Compiled binary addons (http://nodejs.org/api/addons.html) 23 | build/Release 24 | 25 | # Dependency directory 26 | # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git 27 | node_modules 28 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "5.0" 4 | - "4.2" 5 | - "4.0" 6 | before_script: 7 | - npm install -g gulp 8 | script: gulp test -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | {description} 294 | Copyright (C) {year} {fullname} 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | {signature of Ty Coon}, 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | 341 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # [Project Euler](https://projecteuler.net/) (JavaScript) [![Build Status](https://travis-ci.org/lucasfcosta/project-euler-javascript.svg?branch=master)](https://travis-ci.org/lucasfcosta/project-euler-javascript) 2 | 3 | **This platform has got everything you need to start solving [Project Euler](https://projecteuler.net/)'s challenges right away.** 4 | 5 | You can use this to compare your solutions to mine's and **you can also use this project as a boilerplate**. 6 | 7 | If you want to read problems offline you can take a look at problems.txt, which is a courtesy of another awesome project called [EulerPy](https://github.com/iKevinY/EulerPy). 8 | 9 | 10 | ## Getting Started 11 | 12 | Please read the instructions below so you can get to know how everything works. 13 | 14 | 15 | ### Installing 16 | 17 | 1. Clone this repository 18 | 19 | ``` 20 | $ git clone https://github.com/lucasfcosta/project-euler-javascript 21 | ``` 22 | 2. Run `npm install` to install project's dependencies 23 | 3. If you want to use this as a boilerplate or a test platform you can delete every single file inside the `solutions` folder 24 | 4. To run gulp tasks you will also need to install [Gulp](https://www.npmjs.com/package/gulp) globally using `npm install -g gulp` 25 | 26 | ### Writing Solutions 27 | 28 | To write a solution for a problem you will need to: 29 | 30 | 1. Create a file with the problem's number (for example: 1.js if you're solving the first one or 3.js if you are solving the third one) 31 | 2. Write your code the way you want it 32 | 3. Assign the final result to `module.exports` 33 | 34 | I think it's very simple but **if you still need an example please take a look at the 001.js file, which is inside the solutions folder.** 35 | 36 | 37 | ### Testing Solutions 38 | 39 | If you don't want to lint your code and check for code-style related issues you can run `gulp mocha`, otherwise just run `gulp test`. 40 | 41 | To check the last solution only you should run `gulp testLast`. 42 | 43 | ### Other Configurations 44 | 45 | You can also **configure the linting rules** using the files [`.jsrsc`](http://jscs.info/rules?q=) and [`.eslintrc`](http://eslint.org/docs/rules/). 46 | 47 | Currently I'm also using a timeout of 60000ms for tests (because that's what Euler Project recommends) but you can change that on the `gulpfile.js` file. Just change 60000 to whatever you want. 48 | 49 | 50 | ### TL;DR 51 | 52 | Clone this, install gulp globally (`npm install -g gulp`) and run `gulp mocha` to check the solutions (name them with them problem's number) inside the solutions folder. 53 | -------------------------------------------------------------------------------- /gulpfile.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | let gulp = require('gulp'); 4 | let eslint = require('gulp-eslint'); 5 | let mocha = require('gulp-mocha'); 6 | let excludeGitignore = require('gulp-exclude-gitignore'); 7 | 8 | gulp.task('mocha', () => { 9 | return gulp.src('test/testAnswers.js') 10 | .pipe(mocha({reporter: 'spec', timeout: '60000'})); 11 | }); 12 | 13 | gulp.task('mochaLast', () => { 14 | return gulp.src('test/testLastAnswer.js') 15 | .pipe(mocha({reporter: 'spec', timeout: '60000'})); 16 | }); 17 | 18 | gulp.task('eslint', () => { 19 | return gulp.src('**/*.js') 20 | .pipe(excludeGitignore()) 21 | .pipe(eslint()) 22 | .pipe(eslint.formatEach()) 23 | .pipe(eslint.failAfterError()); 24 | }); 25 | 26 | gulp.task('default', ['mocha', 'eslint']); 27 | gulp.task('test', ['mocha', 'eslint']); 28 | gulp.task('testLast', ['mochaLast']); 29 | gulp.task('lint', ['eslint']); 30 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "project-euler-javascript", 3 | "version": "1.0.0", 4 | "description": "Code I've written to solve Project Euler's challenges.", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "gulp test", 8 | "lint": "gulp lint" 9 | }, 10 | "repository": { 11 | "type": "git", 12 | "url": "git+https://github.com/lucasfcosta/project-euler-javascript.git" 13 | }, 14 | "keywords": [ 15 | "project", 16 | "euler", 17 | "javascript", 18 | "code", 19 | "challenge", 20 | "solutions" 21 | ], 22 | "author": "Lucas Fernandes da Costa", 23 | "license": "MIT", 24 | "bugs": { 25 | "url": "https://github.com/lucasfcosta/project-euler-javascript/issues" 26 | }, 27 | "homepage": "https://github.com/lucasfcosta/project-euler-javascript#readme", 28 | "devDependencies": { 29 | "chai": "^3.4.1", 30 | "gulp": "^3.9.0", 31 | "gulp-eslint": "^1.1.1", 32 | "gulp-exclude-gitignore": "^1.0.0", 33 | "gulp-mocha": "^2.2.0" 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /solutions/001.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // Multiples of 3 and 5 4 | 5 | // If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. 6 | // Find the sum of all the multiples of 3 or 5 below 1000. 7 | 8 | let sum = 0; 9 | 10 | for (let i = 1; i < 1000; i++) { 11 | if (i % 3 === 0 || i % 5 === 0) { 12 | sum += i; 13 | } 14 | } 15 | 16 | // After solving the problem don't forget to assign the result to module.exports, like this: 17 | module.exports = sum; 18 | -------------------------------------------------------------------------------- /solutions/002.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // Even Fibonacci numbers 4 | 5 | let sum = 0; 6 | 7 | function nextFib(n1, n2) { 8 | if (n1 % 2 === 0) { 9 | sum += n1; 10 | } 11 | 12 | if (n1 <= 4000000) { 13 | nextFib(n2, n1+n2); 14 | } 15 | } 16 | 17 | nextFib(1, 2); 18 | 19 | module.exports = sum; 20 | -------------------------------------------------------------------------------- /solutions/003.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // Largest prime factor 4 | 5 | let number = 600851475143; 6 | 7 | function largestPrimeFactorOf(n) { 8 | let factor = 2; 9 | 10 | while (factor <= n) { 11 | if (n % factor === 0) { 12 | n /= factor; 13 | } else { 14 | factor++; 15 | } 16 | } 17 | 18 | return factor; 19 | } 20 | 21 | module.exports = largestPrimeFactorOf(number); 22 | -------------------------------------------------------------------------------- /solutions/004.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // Largest palindrome product 4 | 5 | function isPalindrome(number) { 6 | return number.toString() === number.toString().split('').reverse().join(''); 7 | } 8 | 9 | function largestPalindrome(digits) { 10 | let n1 = parseInt('9'.repeat(digits), 10); 11 | 12 | let result = 0; 13 | 14 | for (let i = n1; i > 0; i--) { 15 | for (let j = n1; j > 0; j--) { 16 | let currentResult = i * j; 17 | 18 | if (isPalindrome(currentResult) && currentResult > result) { 19 | result = currentResult; 20 | } 21 | } 22 | } 23 | 24 | return result; 25 | } 26 | 27 | module.exports = largestPalindrome(3); 28 | -------------------------------------------------------------------------------- /solutions/005.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // Smallest multiple 4 | 5 | function divisibleByAll(number) { 6 | let i = 2; 7 | while (i <= 20) { 8 | let result = number % i; 9 | 10 | if (result !== 0) { 11 | return false; 12 | } 13 | 14 | i++; 15 | } 16 | 17 | return true; 18 | } 19 | 20 | let n = 20; 21 | 22 | while (!divisibleByAll(n)) { 23 | n += 20; 24 | } 25 | 26 | module.exports = n; 27 | -------------------------------------------------------------------------------- /solutions/006.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // Sum square difference 4 | 5 | function sumSquares() { 6 | let squareSum = 0; 7 | 8 | for (let i = 1; i <= 100; i++) { 9 | squareSum += i * i; 10 | } 11 | 12 | return squareSum; 13 | } 14 | 15 | function squareOfSum() { 16 | let result = 0; 17 | 18 | for (let i = 1; i <= 100; i++) { 19 | result += i; 20 | } 21 | 22 | return result * result; 23 | } 24 | 25 | module.exports = squareOfSum() - sumSquares(); 26 | -------------------------------------------------------------------------------- /solutions/007.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // 10001st prime 4 | 5 | function isPrime(number) { 6 | for (let i = 2; i < number - 1; i++) { 7 | if (number % i === 0) { 8 | return false; 9 | } 10 | } 11 | 12 | return true; 13 | } 14 | 15 | // This holds information about the last prime 16 | let currentPrime = {index: 1, val: 2}; 17 | 18 | let testNumber = 3; 19 | 20 | while (currentPrime.index !== 10001) { 21 | 22 | if (isPrime(testNumber)) { 23 | currentPrime.index++; 24 | currentPrime.val = testNumber; 25 | } 26 | 27 | testNumber += 2; 28 | } 29 | 30 | module.exports = currentPrime.val; 31 | -------------------------------------------------------------------------------- /solutions/008.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // Largest product in a series 4 | 5 | let serie = `73167176531330624919225119674426574742355349194934 6 | 96983520312774506326239578318016984801869478851843 7 | 85861560789112949495459501737958331952853208805511 8 | 12540698747158523863050715693290963295227443043557 9 | 66896648950445244523161731856403098711121722383113 10 | 62229893423380308135336276614282806444486645238749 11 | 30358907296290491560440772390713810515859307960866 12 | 70172427121883998797908792274921901699720888093776 13 | 65727333001053367881220235421809751254540594752243 14 | 52584907711670556013604839586446706324415722155397 15 | 53697817977846174064955149290862569321978468622482 16 | 83972241375657056057490261407972968652414535100474 17 | 82166370484403199890008895243450658541227588666881 18 | 16427171479924442928230863465674813919123162824586 19 | 17866458359124566529476545682848912883142607690042 20 | 24219022671055626321111109370544217506941658960408 21 | 07198403850962455444362981230987879927244284909188 22 | 84580156166097919133875499200524063689912560717606 23 | 05886116467109405077541002256983155200055935729725 24 | 71636269561882670428252483600823257530420752963450`; 25 | 26 | // Removes newlines 27 | serie = serie.replace(/\n/g, ''); 28 | 29 | function multiplyNext13(startIndex) { 30 | let currentProduct = 1; 31 | for (let i = 0; i < 13; i++) { 32 | currentProduct *= parseInt(serie.charAt(i + startIndex), 10); 33 | } 34 | 35 | return currentProduct; 36 | } 37 | 38 | let greatestProduct = 0; 39 | 40 | for (let i = 0; i < serie.length; i++) { 41 | let result = multiplyNext13(i); 42 | 43 | if (result > greatestProduct) { 44 | greatestProduct = result; 45 | } 46 | } 47 | 48 | module.exports = greatestProduct; 49 | -------------------------------------------------------------------------------- /solutions/009.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | // Special Pythagorean triplet 4 | 5 | function calculateResult() { 6 | for (let a = 1; a < 334; a++) { 7 | for (let b = a; b < 1000 - a; b++) { 8 | let c = 1000 - a - b; 9 | 10 | if (Math.pow(a, 2) + Math.pow(b, 2) === Math.pow(c, 2)) { 11 | return a * b * c; 12 | } 13 | } 14 | } 15 | } 16 | 17 | module.exports = calculateResult(); 18 | -------------------------------------------------------------------------------- /solutions/010.js: -------------------------------------------------------------------------------- 1 | 2 | 'use strict'; 3 | 4 | // Summation of primes 5 | 6 | 7 | // This solution uses the Sieve of Eratosthenes algorithm. 8 | // Please see: https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes to understand how this works 9 | 10 | // Prime Number to use as limit 11 | let limit = 2000000; 12 | 13 | // Holds the sum 14 | let total = 0; 15 | 16 | // The indexes of this array will be used to identify prime numbers 17 | let primeNumbers = []; 18 | 19 | // Current prime 20 | let p = 2; 21 | 22 | // The biggest number we've gotta use to find its multiples is the floor of the square root of the number used as limit 23 | let upperLimit = Math.floor(Math.sqrt(limit)); 24 | 25 | while (p <= upperLimit) { 26 | // Here we mark every index which is a multiple of P as false 27 | for (let i = p + p; i < limit; i += p) { 28 | primeNumbers[i] = false; 29 | } 30 | 31 | // Now we find the next non-marked number 32 | // It is a prime and we will mark all its multiples 33 | for (let j = p + 1; j < limit; j++) { 34 | if (primeNumbers[j] === undefined) { 35 | p = j; 36 | break; 37 | } 38 | } 39 | } 40 | 41 | // Now every non-marked number is a prime number 42 | for (let k = 2; k < limit; k++) { 43 | if (primeNumbers[k] === undefined) { 44 | total += k; 45 | } 46 | } 47 | 48 | module.exports = total; 49 | -------------------------------------------------------------------------------- /test/answers.json: -------------------------------------------------------------------------------- 1 | { 2 | "problem1": 233168, 3 | "problem2": 4613732, 4 | "problem3": 6857, 5 | "problem4": 906609, 6 | "problem5": 232792560, 7 | "problem6": 25164150, 8 | "problem7": 104743, 9 | "problem8": 23514624000, 10 | "problem9": 31875000, 11 | "problem10": 142913828922, 12 | "problem11": 70600674, 13 | "problem12": 76576500, 14 | "problem13": 5537376230, 15 | "problem14": 837799, 16 | "problem15": 137846528820, 17 | "problem16": 1366, 18 | "problem17": 21124, 19 | "problem18": 1074, 20 | "problem19": 171, 21 | "problem20": 648, 22 | "problem21": 31626, 23 | "problem22": 871198282, 24 | "problem23": 4179871, 25 | "problem24": 2783915460, 26 | "problem25": 4782, 27 | "problem26": 983, 28 | "problem27": -59231, 29 | "problem28": 669171001, 30 | "problem29": 9183, 31 | "problem30": 443839, 32 | "problem31": 73682, 33 | "problem32": 45228, 34 | "problem33": 100, 35 | "problem34": 40730, 36 | "problem35": 55, 37 | "problem36": 872187, 38 | "problem37": 748317, 39 | "problem38": 932718654, 40 | "problem39": 840, 41 | "problem40": 210, 42 | "problem41": 7652413, 43 | "problem42": 162, 44 | "problem43": 16695334890, 45 | "problem44": 5482660, 46 | "problem45": 1533776805, 47 | "problem46": 5777, 48 | "problem47": 134043, 49 | "problem48": 9110846700, 50 | "problem49": 296962999629, 51 | "problem50": 997651, 52 | "problem51": 121313, 53 | "problem52": 142857, 54 | "problem53": 4075, 55 | "problem54": 376, 56 | "problem55": 249, 57 | "problem56": 972, 58 | "problem57": 153, 59 | "problem58": 26241, 60 | "problem59": 107359, 61 | "problem60": 26033, 62 | "problem61": 28684, 63 | "problem62": 127035954683, 64 | "problem63": 49, 65 | "problem64": 1322, 66 | "problem65": 272, 67 | "problem66": 661, 68 | "problem67": 7273, 69 | "problem68": 6531031914842725, 70 | "problem69": 510510, 71 | "problem70": 8319823, 72 | "problem71": 428570, 73 | "problem72": 303963552391, 74 | "problem73": 7295372, 75 | "problem74": 402, 76 | "problem75": 161667, 77 | "problem76": 190569291, 78 | "problem77": 71, 79 | "problem78": 55374, 80 | "problem79": 73162890, 81 | "problem80": 40886, 82 | "problem81": 427337, 83 | "problem82": 260324, 84 | "problem83": 425185, 85 | "problem84": 101524, 86 | "problem85": 2772, 87 | "problem86": 1818, 88 | "problem87": 1097343, 89 | "problem88": 7587457, 90 | "problem89": 743, 91 | "problem90": 1217, 92 | "problem91": 14234, 93 | "problem92": 8581146, 94 | "problem93": 1258, 95 | "problem94": 518408346, 96 | "problem95": 14316, 97 | "problem96": 24702, 98 | "problem97": 8739992577, 99 | "problem98": 18769, 100 | "problem99": 709, 101 | "problem100": 756872327473, 102 | "problem101": 37076114526, 103 | "problem102": 228, 104 | "problem103": 20313839404245, 105 | "problem104": 329468, 106 | "problem105": 73702, 107 | "problem106": 21384, 108 | "problem107": 259679, 109 | "problem108": 180180, 110 | "problem109": 38182, 111 | "problem110": 9350130049860600, 112 | "problem111": 612407567715, 113 | "problem112": 1587000, 114 | "problem113": 51161058134250, 115 | "problem114": 16475640049, 116 | "problem115": 168, 117 | "problem116": 20492570929, 118 | "problem117": 100808458960497, 119 | "problem118": 44680, 120 | "problem119": 248155780267521, 121 | "problem120": 333082500, 122 | "problem121": 2269, 123 | "problem122": 1582, 124 | "problem123": 21035, 125 | "problem124": 21417, 126 | "problem125": 2906969179, 127 | "problem126": 18522, 128 | "problem127": 18407904, 129 | "problem128": 14516824220, 130 | "problem129": 1000023, 131 | "problem130": 149253, 132 | "problem131": 173, 133 | "problem132": 843296, 134 | "problem133": 453647705, 135 | "problem134": 18613426663617118, 136 | "problem135": 4989, 137 | "problem136": 2544559, 138 | "problem137": 1120149658760, 139 | "problem138": 1118049290473932, 140 | "problem139": 10057761, 141 | "problem140": 5673835352990, 142 | "problem141": 878454337159, 143 | "problem142": 1006193, 144 | "problem143": 30758397, 145 | "problem144": 354, 146 | "problem145": 608720, 147 | "problem146": 676333270, 148 | "problem147": 846910284, 149 | "problem148": 2129970655314432, 150 | "problem149": 52852124, 151 | "problem150": -271248680, 152 | "problem151": 0.464399, 153 | "problem152": 301, 154 | "problem153": 17971254122360635, 155 | "problem154": 479742450, 156 | "problem155": 3857447, 157 | "problem156": 21295121502550, 158 | "problem157": 53490, 159 | "problem158": 409511334375, 160 | "problem159": 14489159, 161 | "problem160": 16576, 162 | "problem161": 20574308184277971, 163 | "problem162": "3D58725572C62302", 164 | "problem163": 343047, 165 | "problem164": 378158756814587, 166 | "problem165": 2868868, 167 | "problem166": 7130034, 168 | "problem167": 3916160068885, 169 | "problem168": 59206, 170 | "problem169": 178653872807, 171 | "problem170": 9857164023, 172 | "problem171": 142989277, 173 | "problem172": 227485267000992000, 174 | "problem173": 1572729, 175 | "problem174": 209566, 176 | "problem175": "1,13717420,8", 177 | "problem176": 96818198400000, 178 | "problem177": 129325, 179 | "problem178": 126461847755, 180 | "problem179": 986262, 181 | "problem180": 285196020571078987, 182 | "problem181": 83735848679360680, 183 | "problem182": 399788195976, 184 | "problem183": 48861552, 185 | "problem184": 1725323624056, 186 | "problem185": 4640261571849533, 187 | "problem186": 2325629, 188 | "problem187": 17427258, 189 | "problem188": 95962097, 190 | "problem189": 10834893628237824, 191 | "problem190": 371048281, 192 | "problem191": 1918080160, 193 | "problem192": 57060635927998347, 194 | "problem193": 684465067343069, 195 | "problem194": 61190912, 196 | "problem195": 75085391, 197 | "problem196": 322303240771079935, 198 | "problem197": 1.710637717, 199 | "problem198": 52374425, 200 | "problem199": 0.00396087, 201 | "problem200": 229161792008, 202 | "problem201": 115039000, 203 | "problem202": 1209002624, 204 | "problem203": 34029210557338, 205 | "problem204": 2944730, 206 | "problem205": 0.5731441, 207 | "problem206": 1389019170, 208 | "problem207": 44043947822, 209 | "problem208": 331951449665644800, 210 | "problem209": 15964587728784, 211 | "problem210": 1598174770174689458, 212 | "problem211": 1922364685, 213 | "problem212": 328968937309, 214 | "problem213": 330.721154, 215 | "problem214": 1677366278943, 216 | "problem215": 806844323190414, 217 | "problem216": 5437849, 218 | "problem217": 6273134, 219 | "problem218": 0, 220 | "problem219": 64564225042, 221 | "problem220": "139776,963904", 222 | "problem221": 1884161251122450, 223 | "problem222": 1590933, 224 | "problem223": 61614848, 225 | "problem224": 4137330, 226 | "problem225": 2009, 227 | "problem226": 0.11316017, 228 | "problem227": 3780.618622, 229 | "problem228": 86226, 230 | "problem229": 11325263, 231 | "problem230": 850481152593119296, 232 | "problem231": 7526965179680, 233 | "problem232": 0.83648556, 234 | "problem233": 271204031455541309, 235 | "problem234": 1259187438574927161, 236 | "problem235": 1.002322108633, 237 | "problem236": "123/59", 238 | "problem237": 15836928, 239 | "problem238": 9922545104535661, 240 | "problem239": 0.001887854841, 241 | "problem240": 7448717393364181966, 242 | "problem241": 482316491800641154, 243 | "problem242": 997104142249036713, 244 | "problem243": 892371480, 245 | "problem244": 96356848, 246 | "problem245": 288084712410001, 247 | "problem246": 810834388, 248 | "problem247": 782252, 249 | "problem248": 23507044290, 250 | "problem249": 9275262564250418, 251 | "problem250": 1425480602091519, 252 | "problem251": 18946051, 253 | "problem252": 104924.0, 254 | "problem253": 11.492847, 255 | "problem254": 8184523820510, 256 | "problem255": 4.4474011180, 257 | "problem256": 85765680, 258 | "problem257": 139012411, 259 | "problem258": 12747994, 260 | "problem259": 20101196798, 261 | "problem260": 167542057, 262 | "problem261": 238890850232021, 263 | "problem262": 2531.205, 264 | "problem263": 2039506520, 265 | "problem264": 2816417.1055, 266 | "problem265": 209110240768, 267 | "problem266": 1096883702440585, 268 | "problem267": 0.999992836187, 269 | "problem268": 785478606870985, 270 | "problem269": 1311109198529286, 271 | "problem270": 82282080, 272 | "problem271": 4617456485273129588, 273 | "problem272": 8495585919506151122, 274 | "problem273": 2032447591196869022, 275 | "problem274": 1601912348822, 276 | "problem275": 15030564, 277 | "problem276": 5777137137739632912, 278 | "problem277": 1125977393124310, 279 | "problem278": 1228215747273908452, 280 | "problem279": 416577688, 281 | "problem280": 430.088247, 282 | "problem281": 1485776387445623, 283 | "problem282": 1098988351, 284 | "problem283": 28038042525570324, 285 | "problem284": "5a411d7b", 286 | "problem285": 157055.80999, 287 | "problem286": 52.6494571953, 288 | "problem287": 313135496, 289 | "problem288": 605857431263981935, 290 | "problem289": 6567944538, 291 | "problem290": 20444710234716473, 292 | "problem291": 4037526, 293 | "problem292": 3600060866, 294 | "problem293": 2209, 295 | "problem294": 789184709, 296 | "problem295": 4884650818, 297 | "problem296": 1137208419, 298 | "problem297": 2252639041804718029, 299 | "problem298": 1.76882294, 300 | "problem299": 549936643, 301 | "problem300": 8.0540771484375, 302 | "problem301": 2178309, 303 | "problem302": 1170060, 304 | "problem303": 1111981904675169, 305 | "problem304": 283988410192, 306 | "problem305": 18174995535140, 307 | "problem306": 852938, 308 | "problem307": 0.7311720251, 309 | "problem308": 1539669807660924, 310 | "problem309": 210139, 311 | "problem310": 2586528661783, 312 | "problem311": 2466018557, 313 | "problem312": 324681947, 314 | "problem313": 2057774861813004, 315 | "problem314": 132.52756426, 316 | "problem315": 13625242, 317 | "problem316": 542934735751917735, 318 | "problem317": 1856532.8455, 319 | "problem318": 709313889, 320 | "problem319": 268457129, 321 | "problem320": 278157919195482643, 322 | "problem321": 2470433131948040, 323 | "problem322": 999998760323313995, 324 | "problem323": 6.3551758451, 325 | "problem324": 96972774, 326 | "problem325": 54672965, 327 | "problem326": 1966666166408794329, 328 | "problem327": 34315549139516, 329 | "problem328": 260511850222, 330 | "problem329": "199740353/29386561536000", 331 | "problem330": 15955822, 332 | "problem331": 467178235146843549, 333 | "problem332": 2717.751525, 334 | "problem333": 3053105, 335 | "problem334": 150320021261690835, 336 | "problem335": 5032316, 337 | "problem336": "CAGBIHEFJDK", 338 | "problem337": 85068035, 339 | "problem338": 15614292, 340 | "problem339": 19823.542204, 341 | "problem340": 291504964, 342 | "problem341": 56098610614277014, 343 | "problem342": 5943040885644, 344 | "problem343": 269533451410884183, 345 | "problem344": 65579304332, 346 | "problem345": 13938, 347 | "problem346": 336108797689259276, 348 | "problem347": 11109800204052, 349 | "problem348": 1004195061, 350 | "problem349": 115384615384614952, 351 | "problem350": 84664213, 352 | "problem351": 11762187201804552, 353 | "problem352": 378563.260589, 354 | "problem353": 1.2759860331, 355 | "problem354": 58065134, 356 | "problem355": 1726545007, 357 | "problem356": 28010159, 358 | "problem357": 1739023853137, 359 | "problem358": 3284144505, 360 | "problem359": 40632119, 361 | "problem360": 878825614395267072, 362 | "problem361": 178476944, 363 | "problem362": 457895958010, 364 | "problem363": 0.0000372091, 365 | "problem364": 44855254, 366 | "problem365": 162619462356610313, 367 | "problem366": 88351299, 368 | "problem367": 48271207, 369 | "problem368": 253.6135092068, 370 | "problem369": 862400558448, 371 | "problem370": 41791929448408, 372 | "problem371": 40.66368097, 373 | "problem372": 301450082318807027, 374 | "problem373": 727227472448913, 375 | "problem374": 334420941, 376 | "problem375": 7435327983715286168, 377 | "problem376": 973059630185670, 378 | "problem377": 732385277, 379 | "problem378": 147534623725724718, 380 | "problem379": 132314136838185, 381 | "problem380": 6.3202e25093, 382 | "problem381": 139602943319822, 383 | "problem382": 697003956, 384 | "problem383": 22173624649806, 385 | "problem384": 3354706415856332783, 386 | "problem385": 3776957309612153700, 387 | "problem386": 528755790, 388 | "problem387": 696067597313468, 389 | "problem388": 831907372805129931, 390 | "problem389": 2406376.3623, 391 | "problem390": 2919133642971, 392 | "problem391": 61029882288, 393 | "problem392": 3.1486734435, 394 | "problem393": 112398351350823112, 395 | "problem394": 3.2370342194, 396 | "problem395": 28.2453753155, 397 | "problem396": 173214653, 398 | "problem397": 141630459461893728, 399 | "problem398": 2010.59096, 400 | "problem399": "1508395636674243,6.5e27330467", 401 | "problem400": 438505383468410633, 402 | "problem401": 281632621, 403 | "problem402": 356019862, 404 | "problem403": 18224771, 405 | "problem404": 1199215615081353, 406 | "problem405": 237696125, 407 | "problem406": 36813.12757207, 408 | "problem407": 39782849136421, 409 | "problem408": 299742733, 410 | "problem409": 253223948, 411 | "problem410": 799999783589946560, 412 | "problem411": 9936352, 413 | "problem412": 38788800, 414 | "problem413": 3079418648040719, 415 | "problem414": 552506775824935461, 416 | "problem415": 55859742, 417 | "problem416": 898082747, 418 | "problem417": 446572970925740, 419 | "problem418": 1177163565297340320, 420 | "problem419": "998567458,1046245404,43363922", 421 | "problem420": 145159332, 422 | "problem421": 2304215802083466198, 423 | "problem422": 92060460, 424 | "problem423": 653972374, 425 | "problem424": 1059760019628, 426 | "problem425": 46479497324, 427 | "problem426": 31591886008, 428 | "problem427": 97138867, 429 | "problem428": 747215561862, 430 | "problem429": 98792821, 431 | "problem430": 5000624921.38, 432 | "problem431": 23.386029052, 433 | "problem432": 754862080, 434 | "problem433": 326624372659664, 435 | "problem434": 863253606, 436 | "problem435": 252541322550, 437 | "problem436": 0.5276662759, 438 | "problem437": 74204709657207, 439 | "problem438": "undefined", 440 | "problem439": "undefined", 441 | "problem440": "undefined", 442 | "problem441": 5000088.8395, 443 | "problem442": 1295552661530920149, 444 | "problem443": 2744233049300770, 445 | "problem444": 1.200856722e263, 446 | "problem445": "undefined", 447 | "problem446": "undefined", 448 | "problem447": "undefined", 449 | "problem448": 106467648, 450 | "problem449": 103.37870096, 451 | "problem450": "undefined", 452 | "problem451": 153651073760956, 453 | "problem452": 345558983, 454 | "problem453": "undefined", 455 | "problem454": 5435004633092, 456 | "problem455": 450186511399999, 457 | "problem456": 333333208685971546, 458 | "problem457": 2647787126797397063, 459 | "problem458": "undefined", 460 | "problem459": "undefined", 461 | "problem460": 18.420738199, 462 | "problem461": 159820276, 463 | "problem462": "undefined", 464 | "problem463": 808981553, 465 | "problem464": "undefined", 466 | "problem465": "undefined", 467 | "problem466": "undefined", 468 | "problem467": "undefined", 469 | "problem468": "undefined", 470 | "problem469": 0.56766764161831, 471 | "problem470": "undefined", 472 | "problem471": "undefined", 473 | "problem472": "undefined", 474 | "problem473": 35856681704365, 475 | "problem474": "undefined", 476 | "problem475": 75780067, 477 | "problem476": 110242.87794 478 | } 479 | -------------------------------------------------------------------------------- /test/testAnswers.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | let fs = require('fs'); 4 | let assert = require('chai').assert; 5 | let answers = require('./answers'); 6 | 7 | // This needs to be synchronous for Mocha to behaviour correctly 8 | let files = fs.readdirSync(`${__dirname}/../solutions`); 9 | 10 | for (let i = 1; i <= files.length; i++) { 11 | describe(`Problem ${i}`, () => { 12 | let startTime = new Date(); 13 | let answer = require(`../solutions/${`00${i}`.slice(-3)}`); 14 | let endTime = new Date(); 15 | 16 | let elapsedTime = endTime - startTime; 17 | 18 | it(`Your answer: ${answer} (${elapsedTime}ms)`, () => { 19 | let correctAnswer = answers[`problem${i}`]; 20 | 21 | assert.strictEqual(answer, correctAnswer); 22 | }); 23 | }); 24 | } 25 | -------------------------------------------------------------------------------- /test/testLastAnswer.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | let fs = require('fs'); 4 | let assert = require('chai').assert; 5 | let answers = require('./answers'); 6 | 7 | // This needs to be synchronous for Mocha to behaviour correctly 8 | let files = fs.readdirSync(`${__dirname}/../solutions`); 9 | 10 | describe(`Problem ${files.length}`, () => { 11 | let startTime = new Date(); 12 | let answer = require(`../solutions/${`00${files.length}`.slice(-3)}`); 13 | let endTime = new Date(); 14 | 15 | let elapsedTime = endTime - startTime; 16 | 17 | it(`Your answer: ${answer} (${elapsedTime}ms)`, () => { 18 | let correctAnswer = answers[`problem${files.length}`]; 19 | 20 | assert.strictEqual(answer, correctAnswer); 21 | }); 22 | }); 23 | --------------------------------------------------------------------------------