\n", "" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Project Euler Problem 10\n", "\n", "> https://projecteuler.net/problem=10\n", "\n", "> The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.\n", ">\n", "> Find the sum of all the primes below two million.\n", "\n", "_With the `Primes` package, this one is pretty easy. For extra credit, build your own prime generator. [Here is one good method](https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes)._" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Practicing satisfying tests\n", "\n", "For this exercise, you're going to provided with a 2D minesweeper board (a 2D matrix) of any given dimensions filled with `true`s and `false`s, where `true`s are **mines** and `false`s are **empty space**. It's your job to generate a minesweeper board from this matrix, replacing the `true`s with the character `'X'` to signify mines, and replacing the `false`s with the number of _nearby mines_. A mine is _nearby_ to a space if it is contained in the $3\\times 3$ square around the space.\n", "\n", "Your goal is to pass the `@testset` beneath the function below. Once you have done so, add another couple tests of your choosing with gameboards of your choice." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "using Test\n", "\n", "function generateMineBoard(board::Array{Bool, 2})::Array{Any, 2}\n", " mineBoard = Array{Any, 2}(undef, size(board))\n", " # fill in mineBoard with your code here\n", "end\n", "\n", "@testset \"Minesweeper Tests\" begin\n", " X = 'X'\n", " input = [0 0 0 0 0 0\n", " 0 1 0 0 0 0\n", " 1 0 0 0 1 0\n", " 1 1 0 1 0 0]\n", " expected = [1 1 1 0 0 0\n", " 2 X 1 1 1 1\n", " X 4 3 2 X 1\n", " X X 2 X 2 1]\n", " @test generateMineBoard(convert(Array{Bool,2}, input)) == expected\n", " input2 = [0 0 0 0 0 0 0 0 1 0\n", " 0 0 0 1 0 1 0 0 0 0\n", " 0 0 0 0 1 0 0 0 0 0\n", " 1 0 0 0 0 0 0 0 0 0\n", " 0 0 0 0 0 0 0 0 0 0\n", " 0 0 0 0 1 0 0 0 1 0\n", " 0 0 1 0 1 0 0 0 0 0\n", " 0 0 0 0 0 0 0 0 0 0\n", " 0 0 0 0 0 1 0 0 0 0]\n", " expected2 = [0 0 1 1 2 1 1 1 X 1\n", " 0 0 1 X 3 X 1 1 1 1\n", " 1 1 1 2 X 2 1 0 0 0\n", " X 1 0 1 1 1 0 0 0 0\n", " 1 1 0 1 1 1 0 1 1 1\n", " 0 1 1 3 X 2 0 1 X 1\n", " 0 1 X 3 X 2 0 1 1 1\n", " 0 1 1 2 2 2 1 0 0 0\n", " 0 0 0 0 1 X 1 0 0 0]\n", " @test generateMineBoard(convert(Array{Bool, 2}, input2)) == expected2\n", " @test generateMineBoard(convert(Array{Bool, 2}, [0 0 0; 1 1 1; 0 0 0])) == [2 3 2; X X X; 2 3 2]\n", " @test generateMineBoard(convert(Array{Bool, 2}, [1 0; 0 0; 0 1])) == [X 1; 2 2; 1 X]\n", " @test generateMineBoard(ones(Bool, (5,5))) == fill('X', (5,5))\n", " @test generateMineBoard(zeros(Bool, (5,5))) == zeros(Bool, (5,5))\n", "end" ] } ], "metadata": { "kernelspec": { "display_name": "Julia 1.4.2", "language": "julia", "name": "julia-1.4" }, "language_info": { "file_extension": ".jl", "mimetype": "application/julia", "name": "julia", "version": "1.4.2" } }, "nbformat": 4, "nbformat_minor": 4 }The

\n", "n^{th}term of the sequence of triangle numbers is given by,t= Β½_{n}n(n+1); so the first ten triangle numbers are:1, 3, 6, 10, 15, 21, 28, 36, 45, 55, ...

\n", "By converting each letter in a word to a number corresponding to its alphabetical position and adding these values we form a word value. For example, the word value for SKY is 19 + 11 + 25 = 55 =

\n", "t_{10}. If the word value is a triangle number then we shall call the word a triangle word.Using words.txt (right click and 'Save Link/Target As...'), a 16K text file containing nearly two-thousand common English words, how many are triangle words?

\n", "