Skip to main content
Golfin'
Source Link
seequ
  • 1.7k
  • 1
  • 11
  • 21

Python 2.x - 49 23 2322 bytes

This is assuming variable input is okay. Both strings can be of any length.

Shortened @avall.

a='s'
b='aaaabbbbsssffhd'
print print~-len(b.split(a))-1

49 bytes version, counts every instance of the substring ('aba' is in 'ababa' twice).

a='s'
b='aaaabbbbsssffhd'
print sum(a==b[i:i+len(a)]for i in range(len(b)))

Python 2.x - 49 23 bytes

This is assuming variable input is okay. Both strings can be of any length.

a='s'
b='aaaabbbbsssffhd'
print len(b.split(a))-1

49 bytes version, counts every instance of the substring ('aba' is in 'ababa' twice).

a='s'
b='aaaabbbbsssffhd'
print sum(a==b[i:i+len(a)]for i in range(len(b)))

Python 2.x - 49 23 22 bytes

This is assuming variable input is okay. Both strings can be of any length.

Shortened @avall.

a='s'
b='aaaabbbbsssffhd'
print~-len(b.split(a))

49 bytes version, counts every instance of the substring ('aba' is in 'ababa' twice).

a='s'
b='aaaabbbbsssffhd'
print sum(a==b[i:i+len(a)]for i in range(len(b)))
Better version
Source Link
seequ
  • 1.7k
  • 1
  • 11
  • 21

Python 2.x - 4949 23 bytes

This is assuming variable input is okay. Both strings can be of any length.

a='s'
b='aaaabbbbsssffhd'
print len(b.split(a))-1

49 bytes version, counts every instance of the substring ('aba' is in 'ababa' twice).

a='s'
b='aaaabbbbsssffhd'
print sum(a==b[i:i+len(a)]for i in range(len(b)))

Python 2.x - 49 bytes

This is assuming variable input is okay. Both strings can be of any length.

a='s'
b='aaaabbbbsssffhd'
print sum(a==b[i:i+len(a)]for i in range(len(b)))

Python 2.x - 49 23 bytes

This is assuming variable input is okay. Both strings can be of any length.

a='s'
b='aaaabbbbsssffhd'
print len(b.split(a))-1

49 bytes version, counts every instance of the substring ('aba' is in 'ababa' twice).

a='s'
b='aaaabbbbsssffhd'
print sum(a==b[i:i+len(a)]for i in range(len(b)))
deleted 155 characters in body
Source Link
seequ
  • 1.7k
  • 1
  • 11
  • 21

Python 2.x - 49 bytes

This is assuming variable input is okay. Both strings can be of any length.

a='s'
b='aaaabbbbsssffhd'
print sum(a==b[i:i+len(a)]for i in range(len(b)))

Because I'm not sure what "language's API" exactly means, have an alternative 16 bytes version.

print b.count(a)

Python 2.x - 49 bytes

This is assuming variable input is okay. Both strings can be of any length.

a='s'
b='aaaabbbbsssffhd'
print sum(a==b[i:i+len(a)]for i in range(len(b)))

Because I'm not sure what "language's API" exactly means, have an alternative 16 bytes version.

print b.count(a)

Python 2.x - 49 bytes

This is assuming variable input is okay. Both strings can be of any length.

a='s'
b='aaaabbbbsssffhd'
print sum(a==b[i:i+len(a)]for i in range(len(b)))
added 157 characters in body
Source Link
seequ
  • 1.7k
  • 1
  • 11
  • 21
Loading
Source Link
seequ
  • 1.7k
  • 1
  • 11
  • 21
Loading