69 lines
5.6 KiB
Plaintext
69 lines
5.6 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": ["# Triangle\n", "\n", "Determine if a triangle is equilateral, isosceles, or scalene.\n", "\n", "An _equilateral_ triangle has all three sides the same length.\n", "\n", "An _isosceles_ triangle has at least two sides the same length. (It is sometimes\n", "specified as having exactly two sides the same length, but for the purposes of\n", "this exercise we'll say at least two.)\n", "\n", "A _scalene_ triangle has all sides of different lengths.\n", "\n", "## Note\n", "\n", "For a shape to be a triangle at all, all sides have to be of length > 0, and\n", "the sum of the lengths of any two sides must be greater than or equal to the\n", "length of the third side. See [Triangle Inequality](https://en.wikipedia.org/wiki/Triangle_inequality).\n", "\n", "## Dig Deeper\n", "\n", "The case where the sum of the lengths of two sides _equals_ that of the\n", "third is known as a _degenerate_ triangle - it has zero area and looks like\n", "a single line. Feel free to add your own code/tests to check for degenerate triangles.\n", "\n", "## Source\n", "\n", "The Ruby Koans triangle project, parts 1 & 2 [http://rubykoans.com](http://rubykoans.com)\n", "\n", "## Version compatibility\n", "This exercise has been tested on Julia versions >=1.0.\n", "\n", "## Submitting Incomplete Solutions\n", "It's possible to submit an incomplete solution so you can see how others have completed the exercise."]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": ["## Your solution"]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": ["# submit\n", "function is_equilateral(sides)\n", "end\n", "\n", "function is_isosceles(sides)\n", "end\n", "\n", "function is_scalene(sides)\n", "end"]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": ["## Test suite"]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": ["using Test\n", "\n", "# include(\"triangle.jl\")\n", "\n", "@testset \"check equilateral triangles\" begin\n", " @testset \"true if all sides are equal\" begin\n", " @test is_equilateral([2, 2, 2]) == true\n", " @test is_equilateral([0.5, 0.5, 0.5]) == true\n", " end\n", "\n", " @testset \"false if any side is unequal\" begin\n", " @test is_equilateral([2, 3, 2]) == false\n", " end\n", "\n", " @testset \"false if no sides are equal\" begin\n", " @test is_equilateral([5, 4, 6]) == false\n", " end\n", "\n", " @testset \"false if invalid triangle\" begin\n", " @test is_equilateral([0, 0, 0]) == false\n", " end\n", "end\n", "\n", "@testset \"check isosceles triangles\" begin\n", " @testset \"true if at least 2 sides are equal\" begin\n", " @test is_isosceles([3, 4, 4]) == true\n", " @test is_isosceles([4, 3, 4]) == true\n", " @test is_isosceles([4, 4, 3]) == true\n", " @test is_isosceles([4, 4, 4]) == true\n", " @test is_isosceles([0.4, 0.5, 0.5]) == true\n", " @test is_isosceles([0.5, 0.4, 0.5]) == true\n", " @test is_isosceles([0.5, 0.5, 0.4]) == true\n", " end\n", "\n", " @testset \"false if no sides are equal\" begin\n", " @test is_isosceles([2, 3, 4]) == false\n", " end\n", "\n", " @testset \"false if invalid triangle\" begin\n", " @test is_isosceles([1, 1, 3]) == false\n", " end\n", "end\n", "\n", "\n", "@testset \"check scalene triangles\" begin\n", " @testset \"true if no sides are equal\" begin\n", " @test is_scalene([5, 4, 6]) == true\n", " @test is_scalene([0.5, 0.4, 0.6]) == true\n", " end\n", "\n", " @testset \"false if at least 2 sides are equal\" begin\n", " @test is_scalene([3, 4, 4]) == false\n", " @test is_scalene([4, 3, 4]) == false\n", " @test is_scalene([4, 4, 3]) == false\n", " @test is_scalene([4, 4, 4]) == false\n", " @test is_scalene([0.4, 0.5, 0.5]) == false\n", " @test is_scalene([0.5, 0.4, 0.5]) == false\n", " @test is_scalene([0.5, 0.5, 0.4]) == false\n", " end\n", "\n", " @testset \"false if invalid triangle\" begin\n", " @test is_scalene([7, 3, 2]) == false\n", " end\n", "end"]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## Prepare submission\n",
|
|
"To submit your exercise, you need to save your solution in a file called `triangle.jl` before using the CLI.\n",
|
|
"You can either create it manually or use the following functions, which will automatically write every notebook cell that starts with `# submit` to the file `triangle.jl`.\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# using Pkg; Pkg.add(\"Exercism\")\n",
|
|
"# using Exercism\n",
|
|
"# Exercism.create_submission(\"triangle\")"
|
|
]
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "Julia 1.3.0",
|
|
"language": "julia",
|
|
"name": "julia-1.3"
|
|
},
|
|
"language_info": {
|
|
"file_extension": ".jl",
|
|
"mimetype": "application/julia",
|
|
"name": "julia",
|
|
"version": "1.3.0"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 2
|
|
}
|