7 kyu
You're a square!
91,623 of 292,002bkaes
Loading description...
Fundamentals
Mathematics
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.
awh good
This comment has been hidden.
> =
is wrong, it's>=
I’ve never heard of square numbers.
it's funny that the expression int i{} doesn't pass
Olá, fui fazer em python e nao funciona, tempo excedido, ao parecer como o valor não tem limite o sistema cai
why is my kata not being submitted? it loads for a while and gives this error Execution Timed Out (12000 ms)
See of this helps: https://docs.codewars.com/training/troubleshooting#timeout
Lua fork
Approved, thanks!
This comment has been hidden.
the js attemp doesnt not work :b
Execution Timed Out (12000 ms)
yes it does
Yeah, i guess i just had a momentary glitch on the page.
What was the point of the building blocks? It felt redudant to be in the exercise
This comment has been hidden.
Lua:
Random tests always (as in 99% of the time) return non-square numbers
Fixed in latest fork by PetitLu117 here
This comment has been hidden.
This comment has been hidden.
Are you testing it there with that input value?
Anyway, it is a question, not an issue (yet).
Sorry about that issue mark, I'm first time here.
As I understood problem is that here interpreter shows kind of mistake which never happens at least with my local Python interpreter.
But what numbers do you test in your local Python interpreter? Do you test the same numbers as Codewars does? Did you test
is_square(-1)
(which you can see in the error message)?No I tested different numbers, because I haven't noticed test numbers... I tested 5, 27, 9, 25, 81, and few similar examples and they all worked correct and now actually tried with -1 and there is a bug, thanks.
At the end I can say that there was only one exception for -1 and the rest works correct... Thanks for your answer, I finally solved!
This comment has been hidden.
groovy baby
Approved
This comment has been hidden.
your code is unreadable please follow these steps to write proper comments : https://docs.codewars.com/references/markdown
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
Tried your code and it worked. Not a kata issue. Also, next time please use markdown formatting when posting code, otherwise, all indentation is lost.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
when I was trying to import math it didn't let me, strange!
Maybe it already exists there and you don't need to import it
works fine in Python
para este taka no veo necesario importar la libreria, solo tienes que multiplicar numero x numero, mira mi solucion, espero te ayude
This comment has been hidden.
Your code being too slow is not a kata issue. Try to improve it.
This comment has been hidden.
Of course, as long as the tests do not prohibit it and your code obeys the Code of Conduct
having issues with n=3...
check your solution.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This is a problem with your code, the tests don't change what your function returns. If your function works differently on your computer (which is unlikely but happens sometimes), it's another problem and not a kata issue. Please read this documentations carefully: https://docs.codewars.com/training/troubleshooting/
L no math module
This comment has been hidden.
It's an issue with your logic, yes.
This comment has been hidden.
Oh, forgot to add, the "issue" tag is for problems that you know are with the kata, not for issues with your logic or when you're unsure. Please use the "question" tag for things like this in the future - I'll resolve this one.
Thank you for the in depth explanation -- that makes a lot of sense and certainly is interesting!
of
Code works just not for 256941707?? How is that possible?
Posting as an
issue
is reserved for when here is a demonstrable problem with the kata code, not when you have a question. Otherwise, next time post as aquestion
.Your code is incorrect, so it is failing on random tests. The testing stops at the first failed test, so you will see one wrong example each time. You'll need to re-assess how to solve the kata corerctly and fix your code.
This comment has been hidden.
Please read this: https://docs.codewars.com/training/troubleshooting#expected-the-same and this: https://docs.codewars.com/training/troubleshooting#post-discourse
This comment has been hidden.
We mark a message as "Suggestion" to ask the authors and contributors to make some non-critical improvements to a kata.
This comment has been hidden.
No Python version on here gives you that message.
Please read the actual error message from Python on Codewars ( and not on any other Python environment, please ). That should tell you exactly where you're going wrong.
With input n = -1 in devtools in browser and in Microsoft Visual Studio Code i get a result false, but here test get me an error. Please help.
Read this: https://docs.codewars.com/training/troubleshooting#expected-the-same
The square root can't be negative. Because It hasn't a reel root. If n<0, you should return false. It is simple.
This comment has been hidden.
why have no
succ
function on preloaded (lc)?There is no standard library for LC ( yet ).
You get variables, abstractions, applications, you even get recursion, and you get a Reference Guide for Binary Scott number encoding.
From there, you'll have to write your own
succ
function. ( Save it for later, and you'll have your own standard library. )Most LC kata do not preload any functions, you have to build them yourself.
Also, as some advice, this particular kata is fairly hard in LC. I am not sure how familiar you are, but you might want to start with this collection to warm up.
He's #9 on the LC leaderboard. Doesn't say everything, but he's not a total beginner.
Joao, if you are missing specific information on datatypes, try the Encodings Guide. If you are missing necessary information in the Wiki, let us know on
Discord:#lambda-calculus
.This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
Yes, your code is too slow. Not a kata issue.
This comment has been hidden.
That's a problem with your code, not a kata issue, please read this: https://docs.codewars.com/training/troubleshooting
You're creating a too big array, there is no need for that. Rethink your code.
This comment has been hidden.
No, it isn't.
https://en.m.wikipedia.org/wiki/Square_number
it is literally in Wikipedia
9 is a square number, 3 isn't, please read that better. Which integer multiplied by itself gives you 3? None.
ooooohh! right 😅
Can you show me pls how it should be an example ?
LC translation
this translation modifies the description
Approvalisationized.
Lol, why are they using 0 square. You can't make block from nothing
The actual task uses the mathematical definition - which is helpfully given to you. So
0
is square.This comment has been hidden.
Don't be so inefficient. The approach can work, but you're doing much more work than necessary with this approach.
Help! The code works, but it's slow. What to do?
Use a faster algorithm, if it's timing out, then the current one doesn't really work.
This comment has been hidden.
Hi @r1zhok - it seems you are working in C++ ? I just solved the kata in that language to see if there are any restrictions, and I was able to use
sqrt
- make sure you#include
anything that you may need for your solution?you must import math
pls ignore (can't seem to delete comment)
This comment has been hidden.
Issue with your code is not a kata issue! When I ran your code, there's
division by zero
error, so your logic is wrong! And you don't need to includemain
in your solution, FYI!the test is broken i think so cause when i test the kata it works and it also works on vscode but when i submit it shows true to equal false
Obviously, it's not. The problem is in your code. Read this: https://docs.codewars.com/training/troubleshooting/#print-input
Why x%x dosent work here?
It might work but X%X will always be 0, because X is able to go into X exactly once without a remainder value. I have a hunch that modulo will be part of the solution but unsure how to use it yet. Still working on it.
This comment has been hidden.
Read this and this
You don't use
main
here, just use the initial code, and don't rename it. Its name should beis_square
, notisPerfectSquare
for C++This comment has been hidden.
HFH nah u square!
F# translation with tests adapted to new F# setup.
Approved by someone
im new to coding, i need help with this
am new too having issues with it as well
This comment has been hidden.
I'm just gonna put this here... " % "
hahaha so this is what i am doing but do you have any idea why 25 and 26 is not working for me?
all other tests are returning the correct boolian apart from those two...
This comment has been hidden.
No, but you're trying to use a method with an input value that's out of its domain.
This comment has been hidden.
This comment has been hidden.
In your
except
there is no return.This comment has been hidden.
Because it's too slow. Not a kata issue.
good kata +1
Your answer was wrong for 34: expected true to equal false ???
This comment has been hidden.
This comment has been hidden.
Don't post solutions in Discourse please. Suggestions are expected to be suggestions of improvement of the kata.
D translation
Approved!
This comment has been hidden.
Do you know that once you solved the kata you can all the submitted solutions in the
Solutions
tab? This is a better place to discuss about the solutions. The Discourse page is rather used to discuss the kata in general, and not to exchange about the solutions.akar-0, I was not aware of that, thanks.
first solve the equation . . .
This comment has been hidden.
in what computer language did you write this code?
python
i did it, don't worry. I should have left only return in my case
NASM translation
I would mark as a 6 kyu rather than a 7 kyu.
Please stop complaining about kata ranks being off by one (not you specifically, just everyone). Changing ranks is expensive, not worth it, and not going to happen. Just enjoy the cheap points.
How "Expensive" could it possibly be ( ̄。。 ̄) + Nobody cares about the points, so just change it (=
This comment has been hidden.
Don't spoil the kata.
facil
Lua translation available here, reviews welcome!: https://www.codewars.com/kumite/62c00126d7d193497ecbd91c?sel=62c00126d7d193497ecbd91c
approved
This comment has been hidden.
But what exactly is your suggestion?
@mkyd-kill: the discourses pages aren't used to post working code. Solutions are already visible in the solutions pages.
Cheers
This comment has been hidden.
Maybe you're doing it wrong, maybe you're not using a language where it's simple, and definitely please don't complain about kata ranks that are up or down by one in your opinion.
Reranking kata is a very expensive process, so it's not going to happen unless it's a really big problem ( though it has been known to happen ), and in that case the place to raise the problem is not here, but on a github repo the name of which I don't have at hand right now - but if you really want I can find out.
Here, this comment is just not very useful, and a slight bit aggravating for people who know the cost of reranking kata. You didn't know, fine, just please don't do it again.
Your kata huh
No, not the kata author, just someone telling you the truth.
"Please stop having opinions"
If you can express your opinion, why should't others too?
I'm not the one telling others to not express their opinion. Wrong guy
Using Python In VSCode my solution is returning the correct value, yet the test says it's not returning it. For example, in VSCode when I run my function with 25 it returns True, but the test cases say that 25 is returning False.
No, your code's problem is it fails for negative input values.
Rust translation
approved
This comment has been hidden.
.
This comment has been hidden.
My code passes all the test cases. When I submit it passes MOST of the random tests, but fails some. The test doesn't say what numbers it fails on, so it's hard to determine what is going wrong.
You can print the input, and it shows up in the log.
That was a huge help, thank you!
This comment has been hidden.
Please use a spoiler flag when you post code, so that users who didn´t solve the kata cannot see it; I put the flag for you this time. Also use markdown tags to format your code or it's not usable. Refer to the documentation about this and more: https://docs.codewars.com/training/troubleshooting/#post-discourse
This comment has been hidden.
This comment has been hidden.
What you see is the template used to print a log to the user in case he gave a bad answer. This is necessarily a string. The expected answer is the boolean.
Hello coders! I have wrote the code, it passes two tests but fails the last one. It says expected true for 47 but answer is false. 47 is not a perfect square so my solution returns false. I don't know where the problem is?
It's because in 2009 the International Mathematical Union declared 47 a perfect square
I think you've got things backwards. Your code returns true for 47 but should return false.
This comment has been hidden.
Probably because floats have intrinsic imprecision issues, see: https://en.wikipedia.org/wiki/Floating-point_arithmetic#Accuracy_problems
Please use a spoiler flag when you post code somewhere.
sqrt returns a float type. And you are asking if a float number is_int.
This comment has been hidden.
需要返回一个值(结果)!!!
This comment has been hidden.
What you do makes no sense in Python. You must just
return True
orreturn False
.For some reason I get wrong results when using type comparison. It works fine in DartPad.
It's a problem with your code, not a kata issue (= a bug). Maybe the language version is different, or something else. Please read the documentation before raising issues.
This comment has been hidden.
This comment has been hidden.
Wikipedia cites A000290 which shows
0, 1, 4, 9, 16, 25, 36, 49...
as the first numbers that are squares. Anyway,3
is simply not a "product of some integer with itself".Yeah, I took a break and figured this out, for some reason I thougth that I need to confirm if argument is square number and I could not understand why 3 is not square number if it gives 9, lmao.
Even 3 has a number 1.7xxx that when multiplied with itself = 3 however this number is not a perfect square because (1.7xxx) it's not an integer, it's a float.
This comment has been hidden.
Kata solution != kata suggestion
IN METHOD shouldWorkForRandomSquareNumbers()
THIS LINE
assertEquals(String.format("%d is a square number (%d * %d)", randomSq, randomSq, randomSq), true, Square.isSquare(randomSq));
SHOULD BE
assertEquals(String.format("%d is a square number (%d * %d)", randomSq, randomNum, randomNum), true, Square.isSquare(randomSq));
This comment has been hidden.
negative numbers can't be square numbers
what language are you using?
I am using C++
Nevermind, I've made the mistake
Honestly i think that the visible test from down-right are confusing because it seems like what the method return must be something like "true, "x is a perfect square (x*x)"
The tests are fine:
You can also see the examples in the kata description:
This comment has been hidden.
you need to make your solution faster. Ideally, without any loop.
This comment has been hidden.
The logic of your code is wrong. Work through it again, speaking it out loud.
Please mark your post as having spoiler content next time. Read this: https://docs.codewars.com/training/troubleshooting/
but whats wrong thats why im asking for in discussion board
bro return true, not the integer itself, in one case ur returning an integer and in the other case ur returning a boolean
the desc isn't asking you to return the number, rather if it is a square number or not
0 is a square number? Crazy!
This comment has been hidden.
You must be doing something wrong, because this throws no error:
Traceback (most recent call last): File "/workspace/default/src/codewars-test/codewars_test/test_framework.py", line 111, in wrapper func() File "tests.py", line 8, in basic_test_cases test.assert_equals(is_square(-1), False, "-1: Negative numbers cannot be square numbers") File "/workspace/default/solution.py", line 3, in is_square print(math.sqrt(n)) ValueError: math domain error
Does this line:
print(math.sqrt(n))
come from your solution? It blows up ifn
is negative, becausemath.sqrt
does not like negative numbers and you feed it with such.nevermind, my bad
you can use exception handling in it
you get a domain error if you try to square root a negative number, so this needs to be caught first
This comment has been hidden.
because your x is undefined ?
can anybody suggest other platforms/easier ones, these JS exercises seem hard to me
Try Geeks4Geeks
COBOL translation (author inactive)
Team COBOL ;-)
Yeahhh! Join guys!
In Scala one basic test is bad (attempt tests are ok):
should be
Fixed.
/home/codewarrior/node/test.js:50 }); ^
SyntaxError: Unexpected token )
I think this one is broken? Can anyone help me?
I've just ran both sample and random tests and they worked fine ~~ Maybe you miscopied-pasted one closing bracket
I'm getting the same thing for js:28 but can't for the life of me figure out where the issue is. Were you able to find the issue? How did you fix it? Thank you for any help you can give!
Check your code isn't missing some parentheses.
This comment has been hidden.
This comment has been hidden.
Don't use
input
, use the initial code:Read this: https://docs.codewars.com/training/troubleshooting
This comment has been hidden.
Please mark your post as having spoiler content next time and read this too: https://docs.codewars.com/training/troubleshooting#post-discourse
I am so sorry, I have been careless. I will be very careful the next time
i need help with this because im somewhat new to this type of stuff
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
Print the input to the console: https://docs.codewars.com/training/troubleshooting/#print-input
In the future, don't use "Issue" for questions like this. "Issue" is for when you're sure the kata is broken.
(also note that the Python translation has over 36K solves)
I have the same problem and I don't know why it's like that :/
I literally formatted it perfectly to what was on the bottom right. I understand that a little bit of trial and error is fine, but wasting time formatting because the bottom right examples had different formatting than the answer is confusing.
I would suggest being a bit more clear on what an answer actually is somewhere on the page, and not "Example:" because that wasn't really representative in this case.
This comment has been hidden.
We don't know either, but maybe this paragraph will explain some things: https://docs.codewars.com/training/troubleshooting#test-attempt
This comment has been hidden.
Please mark your post as having spoiler content next time, read this: https://docs.codewars.com/training/troubleshooting
Check out the error message:
Youd didn't test your code with negative numbers in your IDE, didn't you?
Thanks for explaining. I'll be careful about spoiler content next time!
Is anybody else coding the perfect square rules? I'm having a really hard time with large numbers that end in 56.
This comment has been hidden.
Hi, read this: https://docs.codewars.com/training/troubleshooting#print-input
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
Probably. Or your code gets lost in an infinite loop in some cases. Maybe this helps: Troubleshooting Your Solution.
Some numbers tested are really big. You need to find an efficient mathematical way to solve this kata, you should use no loop in your code.
This comment has been hidden.
Because in the random number tests, n can be incredibly large. I ran your code on a local machine and it took 2 minutes to finish running for n=2000000000. There are about 200 random number tests and you need to get your execution time down under 12 seconds.
This comment has been hidden.
I get this weird error spewing out.
./src/main/java/Square.java:26: error: illegal start of expression public static void main(String[] args) throws java.io.IOException ^ 1 error
Any suggestions what might have happened?
That's the initial code, don't write a
main
method here, only your code inside that function.thanks!! Will try that now!!
using a library makes things a lot easier - perhaps too easy. try getting it done without any libraries
Not a kata suggestion.
This comment has been hidden.
This comment has been hidden.
Yes.
Yes and by a lot
and how to do that?
I can't tell the solution here. But think if you can first reduce the range. That would be the first optimization. And then see if you're seeing some mathematical pattern.
ive tried my best and i dont see any other way to improve this
This comment has been hidden.
This problem can be cheesed easily with default libraries. I would suggest attempting this problem without using the Math library. Or else there's nothing there to learn from it.
Too late to make such changes, it's a 7kyu after all, hence no restrictions required!
This comment has been hidden.
This comment has been hidden.
Are random tests currently broken for Python 3.8? I've tried multiple algorithms, that should all work, but I consistently pass 100 (non perfect squares) and fail 99 (random perfect square). To test the random tests, I decided to "simplify" the algorithm: return True regardless of input. As expected, the non perfect square tests all fail, as they are expecting False, and the test result even states "True should equal False." What doesn't make sense is that the random perfect square tests all fail, without giving a reason. If the input is a perfect square, the function should return True, so all of the tests for random perfect squares should pass. The fixed tests behave as expected; the tests pass when it returns True for a perfect square and False for a non-perfect square.
Just did some further testing. Added a print(n) before it returns anything. The log does show what the input is in the case of random non-perfect squares and in the fixed tests, but there is no log in the case of the random perfect squares
When I run my attempt, it says that 0, 1, 4 and 9 should be equal False, but those are perfect squares, aren't they? Also, my attempt returns 5 and 6 as True, but when I run the code outside codewars, it works correctly and returns them as False.
Read this: https://docs.codewars.com/training/troubleshooting/
This comment has been hidden.
Don't post solution in discourse (it's visible from dashboard)
This comment has been hidden.
why can't import math to workplace and it doesn't work
This comment has been hidden.
Not a kata suggestion, and please, don't post solutions in Discourse.
This comment has been hidden.
This comment has been hidden.
Because your code does unnecessary calculations every time.
This comment has been hidden.
Your for loop isn't executing since you've defined the range based off of n. If n is equal to 0, then the for loop doesn't run. This means that sqr += 1 will not occur and sqr will be equal to 0, thus returning False.
Completed in 0.04ms
Completed in 0.04ms
This comment has been hidden.
This comment has been hidden.
use if statements, they are not loops
This comment has been hidden.
This comment has been hidden.
Error in the python test:
should be
Fixed.
This is still erroneous, I just had to update this test for my solution.
On 2021-04-08 (YYYY-MM-DD), this error is still present (at least for Python). Running in a local installation with Thonny and Python 3.9.2, I get the expected assertion messages, but not here.
That is the test, no idea what are you saying is still present.
Indeed, I thought I've seen it fixed. But looking at it now, the text is wrong again. I reset to initial state before. https://i.imgur.com/BH9FRh0.png
Ok, that's weird, click reset again, it should be ok both in sample and attempt tests now.
It's fixed (again). Thanks!
This comment has been hidden.
You should be able to import? I had no issues with mine.
I receive "True should equal False" error on random tests. I cannot see what inputs cause this error. Can you help me ?
'
Print the input using
print()
This comment has been hidden.
This comment has been hidden.
did you capatilize the s in .Sqrt?
This comment has been hidden.
you need to return the value (
bool
notstr
) instead of printing itThank you
This comment has been hidden.
On posting code: https://github.com/codewars/codewars.com/wiki/Troubleshooting-your-solution#how-do-i-post-to-a-kata-discourse On debugging your solution: https://github.com/codewars/codewars.com/wiki/Troubleshooting-your-solution#how-can-i-see-which-input-causes-my-solution-to-fail
They are both super helpfull thanks.
I have "Execution Timed Out (12000 ms)" whereas my programm isn't as long
This comment has been hidden.
Loop makes your solution slow. You should try to solve it without loops.
Integral number -> integer number
Please use new python test framework.
C translation: Error messages don't make sense.
Click me for details
^^^ responds with
13368 is not a square number
but13368
wasn't the input or^^^ gives
370081406 is a square number (19238 * 19238)
.. no. it is not.Wow! I'm a bit surprised these wonky error messages made it through 1,734 completions! Thanks for the notice. Should be good now.
Maybe they're used to figuring things out x)
it's keep showing this error (188609022 is a square number (13734 * 13734)) meanwhile sqrt(188609022)=13733.5 which means 188609022 isn't a square
Thanks to @rowcased this ought to be fixed now. To my understanding your code was indeed wrong, but the wrong error message was used.
This comment has been hidden.
use Math ^^
This comment has been hidden.
x ** 1 / 2 is evaluated as (x ** 1) / 2, and not as x ** (1 / 2).
Though, I'm not sure if this approach will really work because of floating point precision errors.
This comment has been hidden.
Your code is too slow, that's not a kata issue, look for a faster algorithm.
Okay, Thank you!
you're forgetting when n is equal to 1. There's a simpler mathematical solution. I gave my answer with one for loop and two if statements.
I passed the samples tests but i can't pass the full test suite.Can anyone help me?(java)
I got the error
330530580 is a square number (18181 * 18181)
but when I tested on a calculator, the square root of 330530580 is 22860.499 and 18181 * 18181 is 330548761. I pass all other tests but the random large number keeps failing.What language?
C
Error messages have been fixed. (1)
Need some help I am passing all of the samples but when I attempt I am getting an error (java)
I guess spaming the attempt button is a good fix
Needs Random Tests (Java)
This comment has been hidden.
This comment has been hidden.
OP solved it, closing
Needs Random Tests
You need to specify a language for things like this - for example, JavaScript and Python look like they have random tests implemented
Oh,yes. Thank you)
This comment has been hidden.
I kept getting this error for the random number test. This makes no sense to me.
"19570487 is a square number (19570487 * 19570487)"
Is it just me?
Error messages have been fixed. (2)
This comment has been hidden.
This comment has been hidden.
Please don't post solutions in Discourse.
ok, thanks
For some reason it is expecting the actual value "true"/"false" but my function is returning "0"/"1"... I'm so confused, my code should be working. What am I missing here?
As far as I remember, testing framework used by c++ has some issues when presenting boolean values in assertion messages.it always displays them as numbers, 0/1. you do not have to try to get 1 instead of true, your solution simply returns invalid answer, but assertion message is Not good.
In C++
true
andfalse
are aliases of1
and0
. Your function is returning a wrong result for some input value. Read this: https://github.com/codewars/codewars.com/wiki/Troubleshooting-your-solutionThis comment has been hidden.
When you first begin the kata, the setup is prepared. It's possible you've altered something about it.
Also, how do the tests compare? Did you use correct tests with correctly matching expected outcomes? Not sure how to help you, so if you wish you may post code if you use the spoiler tag and use proper code markdown. Then we can help you further. (Because you haven't solved the kata, you won't be able to see the comment that's marked with a spoiler tag)
Read this: https://github.com/codewars/codewars.com/wiki/Troubleshooting-your-solution
This comment has been hidden.
look at the error message:
-1: Negative numbers cannot be square numbers: (False, "negative numbers can't be squared") should equal False
what comes after
should equal
is the correct result (False
). You are returning a tuple, which includes the boolean PLUS a comment. So your vscode setup is incorrect. Simply replace the,
after the boolean answer with a#
, then it will work.so, always read error messages. BTW, did you read what Chrono79 linked you to? Because if you haven't yet, you should.
Thank you! It worked. I thought my solutions were supposed to match the test answers completely, including the text after True/False. I'll definitely read through Chrono79's link.
You're welcome. That text you see there is the error message you'd get if you failed the test. EDIT: kinda ironic that that's why your code didn't work! ;)
This comment has been hidden.
For
n = 1000000
your solution raisesRecursionError: maximum recursion depth exceeded in comparison
so it won't work and it's not a kata problem, it's a problem with your code.This comment has been hidden.
And what exactly is your suggestion?
Please do not post solutions in discourse, there's no need for this. If anyone would be interested in your solution, they can always see it in "Solutions" tab.
omg so many comments been hidden XD
This comment has been hidden.
It doesn't say in description that you can't, so you probably can.
This issue is i've run my code in visual studio community and it works. However, it will not test in Codewars. My assumption is Math.Sqrt() will not work, because of seen post in others about the same issue.
It is allowed, just had to add another step.
What step?
Math.sqrt(n) worked for me!
@aol574: d20master was using C# and you javascript (note the difference in capitalization of both methods's name).
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
Since it's intended to be an easy, 7 kyu kata, there are no 'difficult' things expected. Using a built-in function should be enough.
This comment has been hidden.
Please don't post code without marking it as having spoiler content. Read this: https://github.com/codewars/codewars.com/wiki/Troubleshooting-your-solution
Your recursive code exceeds the maximum recursion depth.
Yes. If it is 10000 ** 2, then your program runs 10000 times recursively. You can a ->
import sys; sys.setrecursionlimit(...)
, but it will prob be too slow. You have to use a diff approachThis comment has been hidden.
Not a kata issue, your code is too slow for big values of n.
Test Crashed Caught unexpected signal: SIGFPE (8). Erroneous arithmetic operation. can anyone help me with this pls??
FPE == floating point exception, so look for a line in your code that could have division by zero error or similar problem with modulo
This comment has been hidden.
Then make sure the value is valid before calling the method.
This comment has been hidden.
isqrt is new in Python 3.8, this kata isn't available in 3.8 yet, only 3.6.
I can't fucking understand what conclusion they want from me I solved this kata, but don't understand - what output wants from me
Who are "they"?, anyway You've solved this kata, you task is complete. Outputs are lifeless and they don't have any desires, they cannot "want" anything.
I do not speak English from Russia (only with the help of a translator), but I understood your message.
When I wrote that message I was a little angry and now I apologize.
I solved the problem in 5 minutes, but could not figure out how to formulate the answer: "False", "false", "-1: Negative number bla bla bla" - all this did not work. Didn't accept it as an answer.
In any case, I am already calm and would like to delete this comment, but I do not know how.
You can't delete your comment after someone has replied to it, but there's other option: Click on Edit => Replace everything with one single dot (
.
), none can see what you've written there.Здарова
This comment has been hidden.
Hi, read this
'Looks like you've solved it'
This comment has been hidden.
Read this. Without seeing your code we can only guess.
This comment has been hidden.
Your code is too slow, it uses too many cycles for bigger values of n. Next time you post code, please, read the page I linked, and use code markdown and mark your post as having spoiler content.
I see. I'm still struggling to understand why does it become too slow in the server side. Anyway I apologise, I'm learning to use this platform. Thank you for your help
This comment has been hidden.
Please, don't post solutions in Discourse, there is a Solutions section where you can comment your own solution or other's solution.
How do I get rid of this comment?
After a post has a reply you can't.
Thank you for replying.
This comment has been hidden.
This comment has been hidden.
I followed the exact path you followed. I kept getting this error:
19570487 is a square number (19570487 * 19570487)
Which makes absolutely no sense to me. n * n = n ... What?
This comment has been hidden.
Hi,
You actually need to find a better way to solve this. Your code is pretty slow on big inputs (imagine if
n=10**20
?). Advise: completely drop the loop part and find something better.Note: this is actually a "question", not an "issue" => closing the "issue" aspect (the "issue" label is used for a problem with the kata itself, not for a user having troubles with his solution)
cheers
Thank you!
Pleae add this as a default test:
The he/she would need to make sure it doesn't overflow. Also the code for the challange would have to be rewritten a but. Tho, it would be cool to have as an extre or something you can use in the test like if it was // out at the start.
This is not a performance or advanced version, so no need such tests with such huge inputs & different languages have different overflow boundaries so unapplicable.
The codeblock function's name in the description should be language specific.
I made the examples language agnostic instead (most o the languages were missing anyway... :/ )
This comment has been hidden.
Not a kata issue, the value is passed as an argument of your function, not read from the keyboard. There are more than 22k solutions in Python, when your code doesn't work (and the kata does work), use
Question
label instead. Also mark your post as having spoiler content when posting code like that next time.Attempts are timing out. Testing shows all passing. I have tried a couple different solutions (all pass test but time out in attempts)
This comment has been hidden.
Hi acbahr, an
issue
is only for when the kata has a problem. You could instead post as aquestion
. Your code is timing out because your loops method is inefficient. You will need to find another approach.This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
Not using loops.
This comment has been hidden.
Use spoiler flag next time.
This comment has been hidden.
This comment has been hidden.
Please, don't post solutions in Discourse, it's not allowed.
This comment has been hidden.
Please, don't post solutions in Discourse, it's not allowed. It's not the first time you've been told this either.
This comment has been hidden.
snippet which you saw is not a final solution but just idea, your code must transform result of first expression to integer number
Okay thanks.
This comment has been hidden.
Please, mark your post as having spoiler content next time. Your code should return, not print the result.
This comment has been hidden.
This comment has been hidden.
The real challenge is to solve problem without built-in function .
Good comment, found a solution in C using newton's square method.
This comment has been hidden.
gays? he?
Please don't post your solutions in the discourse--it's forbidden.
This comment has been hidden.
Please don't post your solutions in the discourse--it's forbidden.
For some reason the Ruby version wouldn't let me use Math::sqrt. Had to do it the long way around.
This comment has been hidden.
This comment has been hidden.
can't give it away, only a
hint
: you're gonna facepalm when you find itthere you go
🤦
This comment has been hidden.
Hi, it's not a kata issue if your code doesn't work, issues are for when the kata has some problem. you need a faster algorithm to pass, cheers
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
This comment has been hidden.
It couldn't have been a better first kata