Dividing Strings
Division with numbers is great: 6 / 3 = 2
, but have you ever wanted to divide strings? In this challenge you will, given two strings (s
and t
) divide s
by t
Challenge
Given a string, s
, find the substring in which t
is repeated the most times (non-overlapping), return the amount of times t
is repeated, example:
s = "HiFooFooFooFoo"
t = "Foo"
n = 4
Seems easy enough? Well if the substring ends with the first m
characters of t
, you should add what fraction of the string t
was in the substring (m/t.len
):
s = "12121"
t = "12"
n = 2.5
Rules
- You only need to output to the precision your language supports. The minimum precision is two decimal places.
Examples
First line is s
, second line is m
, last line is output. Examples are double-newline seperated
FooFooFoo
Foo
3
GoatGoatGoatGo
Goat
3.5
SheepSheepSheep
Goat
0
GoGoatGoatGoat
Goat
3
GoatGoGoatGo
Goat
1.5
ab111cd
1
3
PigPigPi
Pig
2.666666
aabaabaaaba
aaba
2
aabaaaabaaa
a
4