Skip to main content
deleted 6 characters in body
Source Link
Jonathan Allan
  • 115.5k
  • 8
  • 68
  • 293

Jelly, 13 bytes

ẇ⁹Ƥ⁵o¬{Ṛḣ¥Ƥ§Ạ 

A full program accepting B n A that prints 1 if B is composable from substrings of length n (or more) of A, or 0 if not.

Try it online!

Or see a test-suite (Altered to a functional form & using the register, ®, populated with A in the footer.)

How?

ẇ⁹Ƥ⁵o¬{Ṛḣ¥Ƥ§Ạ - Main Link: B, n ⁹Ƥ - for infixes (of B) of length n: ẇ ⁵ - is a sublist of A? o - logical OR (vectorised) with: ¬{ - logical NOT B (a vector of zeros the same length as B) (o¬{ has the effect of adding n-1 zeros) Ƥ - for prefxesprefixes: ¥ - last two links as a dyad - f(prefix, n): Ṛ - reverse (the prefix) ḣ - head to length (n) (a no-op if less than length n) § - sums Ạ - all non-zero? 

Jelly, 13 bytes

ẇ⁹Ƥ⁵o¬{Ṛḣ¥Ƥ§Ạ 

A full program accepting B n A that prints 1 if B is composable from substrings of length n (or more) of A, or 0 if not.

Try it online!

Or see a test-suite (Altered to a functional form & using the register, ®, populated in the footer.)

How?

ẇ⁹Ƥ⁵o¬{Ṛḣ¥Ƥ§Ạ - Main Link: B, n ⁹Ƥ - for infixes (of B) of length n: ẇ ⁵ - is a sublist of A? o - logical OR (vectorised) with: ¬{ - logical NOT B (a vector of zeros the same length as B) (o¬{ has the effect of adding n-1 zeros) Ƥ - for prefxes: ¥ - last two links as a dyad - f(prefix, n): Ṛ - reverse (the prefix) ḣ - head to length (n) § - sums Ạ - all non-zero? 

Jelly, 13 bytes

ẇ⁹Ƥ⁵o¬{Ṛḣ¥Ƥ§Ạ 

A full program accepting B n A that prints 1 if B is composable from substrings of length n (or more) of A, or 0 if not.

Try it online!

Or see a test-suite (Altered to a functional form & using the register, ®, populated with A in the footer.)

How?

ẇ⁹Ƥ⁵o¬{Ṛḣ¥Ƥ§Ạ - Main Link: B, n ⁹Ƥ - for infixes (of B) of length n: ẇ ⁵ - is a sublist of A? o - logical OR (vectorised) with: ¬{ - logical NOT B (a vector of zeros the same length as B) (o¬{ has the effect of adding n-1 zeros) Ƥ - for prefixes: ¥ - last two links as a dyad - f(prefix, n): Ṛ - reverse (the prefix) ḣ - head to length (n) (a no-op if less than length n) § - sums Ạ - all non-zero? 
deleted 6 characters in body
Source Link
Jonathan Allan
  • 115.5k
  • 8
  • 68
  • 293

Jelly, 13 bytes

ẇ⁹Ƥ⁵o¬{Ṛḣ¥Ƥ§Ạ 

A full program accepting B n A whichthat prints 1 if B is composable from substrings of length n (or more) of A, or 0 if not.

Try it online!

Or see a test-suitetest-suite (Altered to a functional form & using the register, ®, populated in the footer.)

How?

ẇ⁹Ƥ⁵o¬{Ṛḣ¥Ƥ§Ạ - Main Link: B, n ⁹Ƥ - for infixes (of B) of length n: ẇ ⁵ - is a sublist of A? o - logical OR (vectorised) with: ¬{ - logical NOT B (a vector of zeros the same length as B) (o¬{ has the effect of adding n-1 zeros) Ƥ - for prefxes: ¥ - last two links as a dyad - f(prefix, n): Ṛ - reverse (the prefix) ḣ - head to length (n) § - sums Ạ - all non-zero? 

Jelly, 13 bytes

ẇ⁹Ƥ⁵o¬{Ṛḣ¥Ƥ§Ạ 

A full program accepting B n A which prints 1 if B is composable from substrings of length n (or more) of A, or 0 if not.

Try it online!

Or see a test-suite (Altered to a functional form & using the register, ®, populated in the footer.)

How?

ẇ⁹Ƥ⁵o¬{Ṛḣ¥Ƥ§Ạ - Main Link: B, n ⁹Ƥ - for infixes (of B) of length n: ẇ ⁵ - is a sublist of A? o - logical OR (vectorised) with: ¬{ - logical NOT B (a vector of zeros the same length as B) Ƥ - for prefxes: ¥ - last two links as a dyad - f(prefix, n): Ṛ - reverse (the prefix) ḣ - head to length (n) § - sums Ạ - all non-zero? 

Jelly, 13 bytes

ẇ⁹Ƥ⁵o¬{Ṛḣ¥Ƥ§Ạ 

A full program accepting B n A that prints 1 if B is composable from substrings of length n (or more) of A, or 0 if not.

Try it online!

Or see a test-suite (Altered to a functional form & using the register, ®, populated in the footer.)

How?

ẇ⁹Ƥ⁵o¬{Ṛḣ¥Ƥ§Ạ - Main Link: B, n ⁹Ƥ - for infixes (of B) of length n: ẇ ⁵ - is a sublist of A? o - logical OR (vectorised) with: ¬{ - logical NOT B (a vector of zeros the same length as B) (o¬{ has the effect of adding n-1 zeros) Ƥ - for prefxes: ¥ - last two links as a dyad - f(prefix, n): Ṛ - reverse (the prefix) ḣ - head to length (n) § - sums Ạ - all non-zero? 
Source Link
Jonathan Allan
  • 115.5k
  • 8
  • 68
  • 293

Jelly, 13 bytes

ẇ⁹Ƥ⁵o¬{Ṛḣ¥Ƥ§Ạ 

A full program accepting B n A which prints 1 if B is composable from substrings of length n (or more) of A, or 0 if not.

Try it online!

Or see a test-suite (Altered to a functional form & using the register, ®, populated in the footer.)

How?

ẇ⁹Ƥ⁵o¬{Ṛḣ¥Ƥ§Ạ - Main Link: B, n ⁹Ƥ - for infixes (of B) of length n: ẇ ⁵ - is a sublist of A? o - logical OR (vectorised) with: ¬{ - logical NOT B (a vector of zeros the same length as B) Ƥ - for prefxes: ¥ - last two links as a dyad - f(prefix, n): Ṛ - reverse (the prefix) ḣ - head to length (n) § - sums Ạ - all non-zero?