7 kyu
Sum of Triangular Numbers
5,642 of 17,598ThomasL
Loading description...
Mathematics
Fundamentals
View
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Spoiler
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}
-
-
Your rendered github-flavored markdown will appear here.
-
Label this discussion...
-
No Label
Keep the comment unlabeled if none of the below applies.
-
Issue
Use the issue label when reporting problems with the kata.
Be sure to explain the problem clearly and include the steps to reproduce. -
Suggestion
Use the suggestion label if you have feedback on how this kata can be improved.
-
Question
Use the question label if you have questions and/or need help solving the kata.
Don't forget to mention the language you're using, and mark as having spoiler if you include your solution.
-
No Label
- Cancel
Commenting is not allowed on this discussion
You cannot view this solution
There is no solution to show
Please sign in or sign up to leave a comment.
Neat kata. I did look up the formula however.
I do not understand how to submit it properly in postgresql. I created a function but sample data does not see it. It is working only if I manually SELECT * FROM function. What should I do?
For SQL katas, you shouldn't create functions, normally it's just a select statement what you should write:
oh ok, thanks a lot
What's with all these kata lately requiring complex mathematical theory and not including the calculation? bro, I just want to code
This comment has been hidden.
I'm a total novice I can't figure out where to answer the katas...
Read this then: https://docs.codewars.com/training/training-example
SQL Translation
Approved!
This kata is a subject to deduplication process here: https://github.com/codewars/content-issues/issues/140.
Please join the discussion to help us identify duplicate kata and retire them.
This kata was decided to stay.
I think the best practice for theese kind of problems is just to check for an formula. Dont look for solution, look for formula to solve the problem. Ofc not always. Learning how to google things and use is also important. I tried with loop, but that is so unnecesary. And u cant solve this without math brains. With loop yes, without? Nah.
Factor translation (Author inactive)
Approved
This comment has been hidden.
COBOL translation updated.
approved
This comment has been hidden.
Hi. Please use markdown format tags to format your code or it's very discomfortable to read. See: https://docs.codewars.com/references/markdown/#code-block
I recommend you to read this help page to overcome your problem: https://docs.codewars.com/training/troubleshooting/
COBOL translation kumited <3
approved by
Typescript 3.3 or above should be enabled
fixed
R translation (author inactive)
Thanks :)
I'm getting a recursion error, Is it possible to increase the recursion limit ?
No.
Dear creator, I'm attempting this Kata in C, the Test section passes all green but on Attempt the last test returns this:
The expression (myAnswer) == (theirAnswer) is false.
I'm a bit puzzled by this message because all other tests pass the argument given, for example:
The expression (sumTriangularNumbers(6)) == (56) is false.
But this last test in the Attempt section is unique. Could you please let me know if this is intended so I know if I'm on the right track or not?
Thank you, and great kata!
I edited the kata and hopefully made error messages clearer. Please refesh the page, reset the trainer (back up your code first!) and please check if error messages are better.
Thank you, much clearer!
Prolog translation
Julia translation
for C
Very small issue: tests generate one warning of
[-Wimplicit-function-declaration]
.Fixed
Can somebody explain what the prompt is asking in Laymans terms? I don't understand it.
C++ tests are missing some headers.
Can't edit the C++ tests directly, it's locked. I've read that happens after 500+ solutions. So I've published a kumite with the requested changes. See if you can approve it. Otherwise, this issue is unsatisifiable and should just be resolved. If you do the latter then please reject my kumite so it'll leave my queue. Thanks.
approved.
about the 500 solutions, you're right except that 10k honor users can still edit the tests.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
I am so confused as to what to do after reading the descritpion. Could someone elaborate please?
1+2=3 (1th triangular number) 1+2+3=6 (2dn triangular number) 1+2+3+4=10 (3d triangular number) 1+2+3+4+5=15 (4th triangular number) 1+2+3+4+5+6=21 (5th triangular number) 1+2+...+13+14 = 105 (13th triangular number)
given n, return the sum of the triangular numbers 1 to n. n=2 gives 3+6=9.
Thanks! This was very helpful for me.
Great kata, but do wish the tests were more demanding.
This comment has been hidden.
NASM translation available.
Approved
This comment has been hidden.
Fixed
This comment has been hidden.
The Kata is nice except that in Haskell the types are Double instead of some Integral. This leads to the problem that the random tests expect fractions sometimes (eg. 1.0e-323) after giving a fraction in the same range as a parameter. I have no idea how others managed to pass this Kata in Haskell.
Yes it's pretty strange -- a fairly easy problem made almost (or really) impossible by broken random tests. Maybe the Quickcheck tests were added after those people passed? Or they figured out how to predict the floating point error in the expected answer, although I've been trying for the whole day and still not cracked it.
Ok, I solved it, but not by predicting the floating point error. I realised that the small variation in floating point error must indicate that the Quickcheck tests generate the answer in a different way than the iterative solution I used -- in fact if the iterative solution were used, it should expect zeroes for any input
0 < n < 1
. There is a non-iterative solution to this problem which produces identical results and passes the tests. But it'd be good to restrict Quickcheck tests in future, and at the very least use an epsilon test (i.e. instead of assertingx == y
, assertabs (x - y) < 1.0e-100
or similar.Fixed
This is a very good kata for beginners.
This comment has been hidden.
The argument type shouldn't be Double in Haskell.
Agreed. The type should either be Int or Integer, depending on how big the tests get. It uses int in C, C++, C#, and Java.
Thanks for report, I have just corrected it, but no sure why it doesn't show up.
After a change like that sometimes you have to click Reset to see it.
Fixed
Crystal translation offered :+1:
Approved
A bit more clear explanation of triangular numbers would be nice -- or at least a link to wikipedia.
Looks like somebody already added it ;-)
Can someone futher explain what a triangular number is? I don't fully understand it.
Same smh
1 2 3 4 5 6 7 8 9 10
the trangualar number starts from 1, it's the first triangular number. and to get the second traingular number, we add 2 to the first number (1 + 2) which is 3. the same way, to get the third number, we need to add 3 to the second number, so (3 + 3), we have 6. and the forth number, is the third number + 4, (6 + 4) = 10. I think the reason why they call it triangular number is, when we dispaly only one traingular number at one line and put it at the end of the line, the shape we get looks like a triangle.
I hope my explaination will help you :)
https://en.wikipedia.org/wiki/Triangular_number
https://www.youtube.com/watch?v=X3_h4w3jVsk
Something is wrong with the test code for this kata.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
It looks like you're overcomplicating the solution; it's not as hard as you're making it.
And now in TypeScript:
https://www.codewars.com/kumite/5808d0fb7cedaadc0500004b
Please check and approve it. ;-)
And your great kata in Java!
https://www.codewars.com/kumite/5808cc48254062e21d0000c2
Please check and approve it! ;-)
C-Translation kumited!
https://www.codewars.com/kumite/5808ca682540620e140000b2
Please check and approve it! ;-)
Approved; thanks.
I C what you did there, Steffen! :D
All for the best language ever! :-)
Every time you write C, the gods of programming are smiling upon you!
:D :D Very good. God would use C ;-)
...Dat feel when you accidentally figure out how to format output in
cr_assert
...cr_assert_eq(a, b, "Received: %d, expected: %d.", a, b)
Nice, but then all method calls have to taken in an variable before.
Sadly criterion does not do this better visualization on his own...
C#-Translation kumited!
https://www.codewars.com/kumite/5808bc7a69f912634b0000ca
Please check and approve it! ;-)
It looks like it works and has been approved. Thanks!
This comment has been hidden.
Both have been approved. Thanks!