8 ms·
Validator seems broken.
by warmfuzzykitten 13y ago
Validator seems broken.
- gamegoblin 13y agoI keep getting various parse errors like Expected assignment, comment or return statement but " " found. When trying to get rid of parse errors, I did something like "return x" and it says Solution did not return correct output for x=1. Expected output: 1, got: 0 Which is clearly not right. Just tried doing "return 1" and still got Solution did not return correct output for x=1. Expected output: 1, got: 0
- dalke 13y agoI get the same thing as you, and I get the same thing when I have "return 0." The puzzle is annoying. For what it's worth, here's my answer: 1>>(x&~(~x+1))&~(1>>x) . (I didn't figure out that the tester was broken before I developed my answer.) I tested it with positive integers on Python. I haven't tried it with negatives in Javascript. The '(x&~(~x+1))' is a work-around to get 'x&(x-1)', which is 0 if x is a power of two. The (1>> value) is a workaround to get "value == 0". Thus, '1>>(x&~(~x+1))' means 'is x a power of two?' The ~(1>>x) means 'is x == 0'. Combine the two together gives 1 if a single bit is set, else 0.
- letney 13y agoThe work-around for 'x&(x-1)' I found is one-character longer: '(x&(~x+x+x))'
- fourspace 13y agoI certainly can't get it to work. For the first problem, I tried: function one_bit(x) { return x & (x-1) == 0 } Only to see this error: Expected "}" or comment but "&" found. WAT
- dalke 13y agoIt appears to have a limited JS validator to prevent you from using anything other than the limited operators it allows.
- sp332 13y agoIt really doesn't like having anything after "return" except a single value or variable.
- dalke 13y agoThat's not it. For example, it accepts "return x|x&x;" . The restriction is that only a handful of Javascript operations are allowed. Anything else gives a hard-to-understand error message.
- wellingtons 13y agoYou can't use '-'.
- warmfuzzykitten 13y agoThat returns true or false, which I believe strictly speaking aren't numeric in Javascript. By definition of problem, probably should be: function one_bit(x) { return x & (x-1) == 0 ? 1 : 0; }
- sachleen 13y agoDefinitely. function one_bit(x) { return 1 } Solution did not return correct output for x=1. Expected output: 1, got: 0 umm... ok
- amenghra 13y ago:( Oops, i'll fix it.
- amenghra 13y agoShould be fixed now...