7 kyu
Vampire Numbers
2,790 of 7,096AlejandorLazaro
Loading description...
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.
hi, I would reccomand having a small edge case section in the code for (0,0), (1,1), (0,1), (-1, 0), (-1, 1) etc preferably in the sample test also also, maybe adding some random testing would be a good idea, however make sure you genrate random ints and cast them to longs, as dealing with the edges of representable numbers was not defined. best of luck :)
This comment has been hidden.
JavaScript Fork
Approved
Python:
test.expect
is usedPython fork
test.expect
=>test.assert_equals
.
In JS the function name should be in camelCase.
fork provided above in recent suggestion fixing case
Good job!
Please use new python test framework.
Done.
enjoyable!
No random tests in any language.
fork provided above in recent suggestion adding random tests to JavaScript
Python function name should use
snake_case
, notPascalCase
. MixedCase is only used for compatibility purposes.Already fixed.
C#: Translation does not follow naming/bracket conventions.
Method names should be
PascalCase
, notsnake_case
, and opening brackets should be on new lines.should be
All test passed beside test5: Large: 2947050 * 8469153 = 24959017348650 should return True Expected: True But was: False
In my IDE it returns "true". What I'm doing wrong
test8: Large: 2947050 * 8469153 = 24959017348650 should return True Expected: False But was: True
test5: Large: 2947050 * 8469153 = 24959017348650 should return True Expected: True But was: False
Fix it please.
It will return false. Because the result contains only one digit 9. It must contain two 9
✘ Large: 2947050 * 8469153 = 24959017348650 should return True Expected: False But was: True
My Code Begin with public static bool vampire_test(long x, long y){ Console.WriteLine(x); Console.WriteLine(y);
The Result is test8 Log 0 0 ✘ Large: 2947050 * 8469153 = 24959017348650 should return True Expected: False But was: True Completed in 0.009067ms
Why Log is Zero?
Something is wrong with test8: test8 Large: 2947050 * 8469153 = 24959017348650 should return True Expected: False But was: True
Expected value should be True
Yeah, I have the same problem.
Javascript version of Kata could include random tests :)
Re-raised as an issue.
Getting this error, although, my code runs fine in fiddlesalad:
kata: Unterminated string constant:61 Test.assertEquals(vampire_test(2947051,8469153) , false,
Did you edit the test examples? It sounds like in the final test: "Large: 2947051 * 8469153 = 24959025817803 should return false <- doesn't have an end-quote (i.e. unterminated).
Try either fixing the tests, or copying your solution, then resetting the kata (next to "Run Tests" button) and pasting your solution back in.
This comment has been hidden.
Hi again!
I don't have much experience using JS, but I copied your code to test. It didn't pass the first time I tried it, and after some testing, it seems that whether your solution passes or not is pretty much random. I'm not sure exactly why that is, but I do know (from the error, and reducing the solution down to those lines) that it has something to do with the
JSON.stringify()
calls.Not sure if this is an isolated case of strigify conflicts on this site since I haven't done many JS katas. But when I replaced them with
e.g.: a.toString()
, it passed every time I ran it. So I don't think it has much to do with your actual solution.Cheers! Hopefully you don't run into too many problems like that in the future. :)
Thanks so much! I just started teaching myself to code about 2 months back and I noticed it is hard for me to "unsee" my solutions. I didn't even think to use .toString and I have used it tons of times...
Unfortunately, I have encountered a ton of problems where I can't really pinpoint why my code won't pass. Like I said, I have posted several comments but you are the first person to actually respond.
I will go back through my other problems and check the test cases and see if I can figure this out.
Again, thank you so much for your feedback. It is very much appreciated.
My pleasure, good luck on your journey!
Not true vampire # test. A vampire # can not be odd number of digits, the fangs have to be split evenly, it's the first sentence of the wikipedia article...
" vampire number is a composite natural number v, with an even number of digits n, that can be factored into two integers x and y each with n/2 digits and not both with trailing zeroes.
So 126 isn't a vampire number.
Agree! Description needs an update)
This comment has been hidden.
The kata works fine. If this code is failing, it's wrong.
When I check up this wiith my Jetbrains IDE , it works, but does not work here . Please suggest. result = sorted(list(str(x*y))) key = sorted(list(str(x))+list(str(y))) if result == key: return("True") else: return("False")
This comment has been hidden.
Well, your "test" for a vampire number is wrong. You return
True
, but2947051 * 8469153
(which is24959025817803
) isn't a vampire number. The product contains two0
, wheras the numbers only contain one0
in total:oh ok, misunderstood the condition for the 0s, thanks
This comment has been hidden.
According to the description of the kata, this isn't allowed:
c = a * b
is a vampire number if and only if all digits ofc
are present in the concatenation ofa
andb
with the same multiplicity, and only those digits.Anyone else has a solution passing for every test but
Large: 2947051 * 8469153 = 24959025817803 should return False
?Large: 2947050 * 8469153 = 24959017348650 should return True Expected: False But was: True
My code passes all the test except for this one. It's a simple algorithm so I have no idea why it would fail for this one test.
Check the part of your code that compares the digits of each array - the problem's probably there. If you're comparing the lengths of each array properly, but not the content, you'll pass every test except this one.
Thanks for kata. But not all rules from article in Wikipedia are observed in tests. For example it's string from article: "For example: 1260 is a vampire number, with 21 and 60 as fangs, since 21 × 60 = 1260. However, 126000 (which can be expressed as 21 × 6000 or 210 × 600) is not, as 21 and 6000 do not have the correct length, and both 210 and 600 have trailing zeroes" But last test vampire_test(210,600) returned true - it's not correct. Thanks for your kata.
After saving solution and running the test, the error is : "Unknown error". Has anybody seen this issue?
See the wiki page. One would need more information to help you if the problem persists.
Something is wrong with this. I cannot test or submit anything because I am getting the following error:
File "", line 7 test.expect(vampire_test(21,6) == True, "Basic: 21 * 6 = 126 should return True") ^ SyntaxError: invalid syntax 0 Passed 0 Failed 0 Errors Process took 27ms to complete
Well after some time passed I actually found a mistake in my solution and corrected it :) Still this Kata seems to have some problems. The example test case has a typo (I'm not quite sure if it is my typo or author's typo): vambire instead of vampire. Also the example test case does not work properly: it evaluates to True but shows it did not pass. (Python version).
Glad to hear that you were able to correct your solution.
I checked the Python example and could not seem to find the typo you mentioned. I'll go ahead and mark the issue as solved.
It was my first kata, so I probably messed up myself :) Sorry for disturbance.
Cut and paste my solution into a shell and tried each of the tests, all cases seem to be accounted for. The site times out both testing and submitting however. Perhaps something is broken with the site? Will try to resubmit later.
This was fun. Thank you! One thing to note that isn't specific to the kata itself but may be helpful to those new to code wars, I tried multiple times to submit via firefox and was unable to and had to copy/paste the link to chrome in order to succesfully submit.
I have a program that I am very sure it should pass (passes all tests under Chrome console) but doesn't seem to be accepted. How can I understand what's wrong?
Hi, when checking the wikipedia page, it seems that each fang should have the same length, the lowest one being 1260. Any idea why 21 * 6 should be a vampire number?
The use a simplified definition for the exercise. They say: "Our loose definition of Vampire Numbers can be described as follows:"
Emphasis on 'loose'
They're Pseudovampire Numbers
Pseudovampire numbers are similar to vampire numbers, except that the fangs of an n-digit pseudovampire number need not be of length n/2 digits. Pseudovampire numbers can have an odd number of digits, for example 126 = 6×21.
Straight from the Wikipedia page (http://en.wikipedia.org/wiki/Vampire_number)
Today I had other things to do, but as it expected it only to take few minutes and as I both enjoyed it and wanted to refresh my Ruby a bit, here you have it translated into Ruby :)
Note: I added a js one, but it is still lacking a Haskell example in the description.
Interesting kata. There's a couple of tweaks you could make to make it that little bit better:
Other than that, good job. I enjoyed writing this ;P
In regards to the randomized tests, those were added later by a translated kumite. Although not bad in principle, I think I'll use this as a suggestion to simply go ahead and translate over my original comprehensive test cases.
I'll also fix the typo. :)
Did you just remove all random tests? :(
...yes. There weren't very high odds that an actual vampire number would be generated. And the test cases seem to cover all the bases pretty well. :/
Of course that's only my opinion.
Cool. ^^
JS and Haskell translations kumited.
I will attempt to add those as soon as possible. Sadly, I am not familiar with the translation approval process, so it may be a while. Thanks for your help in translating this common interview-style problem!
This comment has been hidden.
Added in a false case to the description. If more comments show up regarding clarity of accepted numbers then I will also add more information about the correct digit format. Thanks for your feedback!
This comment has been hidden.
Added in stricter test cases that remove the exploitation of simply parsing through each char in both the product and the combined multiplicands. Thanks for your feedback!
This comment has been hidden.