Skip to main content
added 219 characters in body
Source Link
Dominic van Essen
  • 36.4k
  • 2
  • 22
  • 60

Husk, 5 66 5 bytes

€ḣ¹tẊ€¹tẊ-

Try it online!Try it online!

Outputs 1 for truthy (it's a fibonacci-like sequence), any other non-negative integer for falsy (it isn't a fibonacci-like sequence).

Get the pairwise differences (Ẋ-), remove the first one (t), and check if this is ancheck if this is an ordered sublist of the input one offind the prefixesindex of this sublist in the input (€ḣ¹), or 0 if not present.

Of course, it needs to be a prefix of the input (rather than a sublist at any other position), but I think this should be ensured since the input is increasing. Edit: the fact that the input is increasing does not ensure that sublists must be prefixes (consider 1 2 4 with difference sublist 2), so we need to specifycheck this directly, atby requiring that the costindex of 1-bytethe sublist must be 1.

Husk, 5 6 bytes

€ḣ¹tẊ-

Try it online!

Get the pairwise differences (Ẋ-), remove the first one (t), and check if this is an ordered sublist one of the prefixes of the input (€ḣ¹).

Of course, it needs to be a prefix of the input (rather than a sublist at any other position), but I think this should be ensured since the input is increasing. Edit: the fact that the input is increasing does not ensure that sublists must be prefixes (consider 1 2 4 with difference sublist 2), so we need to specify this directly, at the cost of 1-byte.

Husk, 5 6 5 bytes

€¹tẊ-

Try it online!

Outputs 1 for truthy (it's a fibonacci-like sequence), any other non-negative integer for falsy (it isn't a fibonacci-like sequence).

Get the pairwise differences (Ẋ-), remove the first one (t), and check if this is an ordered sublist of the input find the index of this sublist in the input (€ḣ¹), or 0 if not present.

Of course, it needs to be a prefix of the input (rather than a sublist at any other position), but I think this should be ensured since the input is increasing. Edit: the fact that the input is increasing does not ensure that sublists must be prefixes (consider 1 2 4 with difference sublist 2), so we check this by requiring that the index of the sublist must be 1.

added 285 characters in body
Source Link
Dominic van Essen
  • 36.4k
  • 2
  • 22
  • 60

Husk, 55 6 bytes

€¹tẊ€ḣ¹tẊ-

Try it online!Try it online!

Get the pairwise differences (Ẋ-), remove the first one (t), and check if this is an ordered sublistan ordered sublist one of the prefixes of the input (€¹€ḣ¹).
 

Of course, it needs to be a prefix of the input (rather than a sublist at any other position), but I think this should be ensured since the input is increasing. Of course, it needs to be a prefixEdit: of the fact that the input is increasing does not ensure that sublists must be prefixes (rather than aconsider 1 2 4 with difference sublist at any other position2), but I thinkso we need to specify this should be ensured sincedirectly, at the input is increasingcost of 1-byte.

Husk, 5 bytes

€¹tẊ-

Try it online!

Get the pairwise differences (Ẋ-), remove the first one (t), and check if this is an ordered sublist of the input (€¹).
  Of course, it needs to be a prefix of the input (rather than a sublist at any other position), but I think this should be ensured since the input is increasing.

Husk, 5 6 bytes

€ḣ¹tẊ-

Try it online!

Get the pairwise differences (Ẋ-), remove the first one (t), and check if this is an ordered sublist one of the prefixes of the input (€ḣ¹).

Of course, it needs to be a prefix of the input (rather than a sublist at any other position), but I think this should be ensured since the input is increasing. Edit: the fact that the input is increasing does not ensure that sublists must be prefixes (consider 1 2 4 with difference sublist 2), so we need to specify this directly, at the cost of 1-byte.

Source Link
Dominic van Essen
  • 36.4k
  • 2
  • 22
  • 60

Husk, 5 bytes

€¹tẊ-

Try it online!

Get the pairwise differences (Ẋ-), remove the first one (t), and check if this is an ordered sublist of the input (€¹).
Of course, it needs to be a prefix of the input (rather than a sublist at any other position), but I think this should be ensured since the input is increasing.