Back
Close

Looking for bit matches

Statement

 Goal

You need to output the probability of finding a given sequence of bits in a randomly generated sequence of N bits.

Example:
Given sequence is 11,
N is 3
There are 8 possible bit sequences of the length of 3
000 - doesn't contain 11
001 - doesn't contain 11
010 - doesn't contain 11
011 - contains 11
100 - doesn't contain 11
101 - doesn't contain 11
110 - contains 11
111 - contains 11
So 3 out of 8 (3/8=0.375) are the odds of finding the given sequence "11" in the sequence of 3 random bits.
You need to output 0.375 in this case.
Input
Line 1: A given sequence of bits.
Line 2: An integer N for the number of bits in a random sequence.
Output
A single line with the probability of finding a given sequence in a random sequence of N bits.
Constraints
0 ≤ N ≤ 15
0 < Length of the given sequence ≤ 15
Example
Input
1
1
Output
0.5

Game modes
Fastest, Shortest

Test cases
Test 1 Test
Input
1 1
Output
0.5

Validator 1 Validator
Input
0 1
Output
0.5

Test 11 Test
Input
11 3
Output
0.375

Validator 111 Validator
Input
111 3
Output
0.125

Exemple Test
Input
01 3
Output
0.5

Validator of the Exemple Validator
Input
10 3
Output
0.5

I can't find anything Test
Input
0 0
Output
0

I'm blind Validator
Input
1 0
Output
0

Only one Test
Input
01110110010111 15
Output
0.0001220703125

Only one: electric boogaloo Validator
Input
10001001101000 15
Output
0.0001220703125

Just casual check Test
Input
0000001 15
Output
0.07012939453125

Just casual validation Validator
Input
1111110 15
Output
0.07012939453125

What if it had 1 in the front instead of 0 Test
Input
1000001 15
Output
0.06976318359375

What if it had 0 in the front instead of 1 Validator
Input
0111110 15
Output
0.06976318359375

Solution language

Solution

Stub generator input