6 kyu

Triangle number check

1,140 of 5,502user8012989

Description:

Description:

A triangle number is a number where n objects form an equilateral triangle (it's a bit hard to explain). For example, 6 is a triangle number because you can arrange 6 objects into an equilateral triangle:

  1
 2 3
4 5 6

8 is not a triangle number because 8 objects do not form an equilateral triangle:

   1
  2 3
 4 5 6
7 8

In other words, the nth triangle number is equal to the sum of the n natural numbers from 1 to n.

Your task:

Check if a given input is a valid triangle number. Return true if it is, false if it is not (note that any non-integers, including non-number types, are not triangle numbers).

You are encouraged to develop an effective algorithm: test cases include really big numbers.

Assumptions:

You may assume that the given input, if it is a number, is always positive.

Notes:

0 and 1 are triangle numbers.

Mathematics
Algorithms

Stats:

CreatedJun 15, 2015
PublishedJun 15, 2015
Warriors Trained9500
Total Skips1261
Total Code Submissions25425
Total Times Completed5502
JavaScript Completions1140
CoffeeScript Completions43
Python Completions1384
Ruby Completions342
C# Completions875
Java Completions1525
Haskell Completions135
Clojure Completions125
Swift Completions262
Rust Completions95
Total Stars155
% of votes with a positive feedback rating92% of 620
Total "Very Satisfied" Votes532
Total "Somewhat Satisfied" Votes75
Total "Not Satisfied" Votes13
Ad
Contributors
  • user8012989 Avatar
  • jhoffner Avatar
  • Bodigrim Avatar
  • g964 Avatar
  • anter69 Avatar
  • naithar Avatar
  • imjasonmiller Avatar
  • JohanWiltink Avatar
  • Voile Avatar
  • hobovsky Avatar
  • user8436785 Avatar
Ad