Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Triangular number task #627

Merged
merged 1 commit into from Nov 22, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/battle_asserts/issues/triangular_number.clj
@@ -0,0 +1,24 @@
(ns battle-asserts.issues.triangular-number
(:require [clojure.test.check.generators :as gen]))

(def level :elementary)

(def description "Triangular Number Sequence is generated from a pattern of dots that form a triangle.
The first 5 numbers of the sequence, or dots, are: `1, 3, 6, 10, 15`
This means that the first triangle has just one dot, the second one has three dots, the third one has 6 dots and so on.
Write a function that gives the number of dots with its corresponding triangle number of the sequence.")

(def signature
{:input [{:argument-name "n" :type {:name "integer"}}]
:output {:type {:name "integer"}}})

(defn arguments-generator []
(gen/tuple (gen/choose 1 250)))

(def test-data
[{:expected 1 :arguments [1]}
{:expected 21 :arguments [6]}
{:expected 23220 :arguments [215]}])

(defn solution [n]
(int (/ (* n (inc n)) 2)))