[Community Puzzle] Create the longest sequence of 1s

What’s your output for testcases 7, 8 and 11 ?
If it works for other languages the problem is your Swift script, not the validators.

Test 7: output is 9.
Test 8: output is 7.
Test 11: output is 7.

If you want, I send you my code and we should have some explanations related to the validators.

The way your validators don’t make sense at all hints for a wrong formula somewhere.

I checked operator precedences in Swift and they are quite unusual, for example the ^ operator (bitwise xor) has a highest level of precedence than in most languages.
If you use bitwise operators somehere in your code, try to add parentheses to make precedence more explicit.

If it doesn’t solve your problem, feel free to send me your code.

I sent you my code. Check it.

Found your error: in most languages, split ‘1001’ with ‘0’ as separator returns [‘1’, ‘’, ‘1’] but in swift it returns [‘1’, ‘1’].
You can had the parameter:

omittingEmptySubsequences: false

in your split to get the behaviour you wanted.

Thank you, it works. You’re definitely right, the split function have an issue. Now my code have 100% score.

Hi, for some reason I can pass all tests but Validator 5. Can anyone provide some insight as to what is the difference between 100 bits testcase vs validator?
Thanks

1 Like

There’s nothing special, really.
Here are the last 50 bits:

01100010101000101000101101111010110110111011001110

Add this in expert mode as a custom testcase and tell us what’s your output.

There’s a longer yet more optimized (memory and speed) solution that doesn’t use the split function.

Same thing here, everything passes except for Validator #5

Hi, for the last 50 bits, it outputs 6.
Thanks for response.

01100010101000101000101101111010110110111011001110

There’s a sequence of 7 in there.

Really enjoy this one - i did see the solution in my head long time before actually coding.
What I particularly liked is the construction of the solution could be simply done in one single loop…

and if the language used allows to play with folding list, there is nt even one loop!
Hope people will enjoy that one as I did

hi, is there a way to see the validators imputs, at the end of the puzzle? They all work for me, exept the 7th… Thanks!

It’s not possible unless your level is 29+
Here it is:
10100001000101011001000010001110

Hi,
I passed all 15 tests, but for some reason, case 12, 13 and 15 are not validated and I end up with a score of 80%, no idea why…

So many ppl can’t pass validator, is it difficult to reduce your code to less than 15 lines?

I got 100% in test cases but when submitting test case 1 (“2 bits Validator 1”) fails saying its “hard coded”, why?

It’s just a general message when a validator fails. It means that there’s a bug in your code :slight_smile:

Based on the title of the validator I would suggest checking how your code handles cases like:

01

or

10

In both cases the answer should be 2.

2 Likes