Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Challenges

Post History

66%
+2 −0
Challenges Length of a Sumac Sequence

Scala, 83 bytes x=>x.init#::Stream.iterate(x)(x=>x++(x,x.tail).zipped.map(_-_))indexWhere(_.last<1) Try it online! Takes input as a list of two numbers. The fact that the length can...

posted 3y ago by user‭  ·  edited 3y ago by user‭

Answer
#2: Post edited by user avatar user‭ · 2021-04-24T23:28:56Z (almost 3 years ago)
  • # [Scala], 83 bytes
  • <!-- language-all: lang-scala -->
  • x=>x.init#::Stream.iterate(x)(x=>x++(x,x.tail).zipped.map(_-_))indexWhere(_.last<1)
  • [Try it online!][TIO-knwd74v6]
  • [Scala]: http://www.scala-lang.org/
  • [TIO-knwd74v6]: https://tio.run/##bc0xa8MwEAXgPb/ioItEZGHZKUlMHMhYaKcOHUox1/hCLyiKsI8iGvLb3aRj0fSGj/feuEeP0/nzSHuBF@QAlIRCP8IuRrjMvtHDoYFnHuX9KcgHtFu4JbRTarfJcmB5aJpXGQhPloUGFFJJq7vO5yqZZAXZa/vDMVJvTxhVV3Rac@gpvX3RQKqzHkfZOD3FgYP4oA7qfqhcVRpYOq317L@UzsCiyshjeess1usM1aulgdxabaBw1SojRWWgzjf@zq/TLw "Scala – Try It Online"
  • Takes input as a list of two numbers. The fact that the length can be 0 makes this a bit longer. Explanation coming soon.
  • # [Scala], 83 bytes
  • <!-- language-all: lang-scala -->
  • x=>x.init#::Stream.iterate(x)(x=>x++(x,x.tail).zipped.map(_-_))indexWhere(_.last<1)
  • [Try it online!][TIO-knwd74v6]
  • [Scala]: http://www.scala-lang.org/
  • [TIO-knwd74v6]: https://tio.run/##bc0xa8MwEAXgPb/ioItEZGHZKUlMHMhYaKcOHUox1/hCLyiKsI8iGvLb3aRj0fSGj/feuEeP0/nzSHuBF@QAlIRCP8IuRrjMvtHDoYFnHuX9KcgHtFu4JbRTarfJcmB5aJpXGQhPloUGFFJJq7vO5yqZZAXZa/vDMVJvTxhVV3Rac@gpvX3RQKqzHkfZOD3FgYP4oA7qfqhcVRpYOq317L@UzsCiyshjeess1usM1aulgdxabaBw1SojRWWgzjf@zq/TLw "Scala – Try It Online"
  • Takes input as a list of two numbers. The fact that the length can be 0 makes this a bit longer.
  • ```
  • x => //List(t1, t2) a.k.a. the second partial sequence
  • x.init //List(t1) a.k.a. the first partial sequence
  • #:: //prepended to
  • Stream //an infinite stream of partial sequences
  • .iterate(x) //starting with the second partial sequence
  • (x => //to which this function is repeatedly applied:
  • x ++ //Concatenate the previous sequence to the next values
  • (x, x.tail).zipped //Zip the previous sequence and its tail
  • .map(_-_)) //And subtract each i-1th element from the ith element
  • indexWhere //Find the index of the sequence where
  • (_.last<1) //The last element is not positive
  • ```
#1: Initial revision by user avatar user‭ · 2021-04-24T23:20:07Z (almost 3 years ago)
# [Scala], 83 bytes

<!-- language-all: lang-scala -->

    x=>x.init#::Stream.iterate(x)(x=>x++(x,x.tail).zipped.map(_-_))indexWhere(_.last<1)

[Try it online!][TIO-knwd74v6]

[Scala]: http://www.scala-lang.org/
[TIO-knwd74v6]: https://tio.run/##bc0xa8MwEAXgPb/ioItEZGHZKUlMHMhYaKcOHUox1/hCLyiKsI8iGvLb3aRj0fSGj/feuEeP0/nzSHuBF@QAlIRCP8IuRrjMvtHDoYFnHuX9KcgHtFu4JbRTarfJcmB5aJpXGQhPloUGFFJJq7vO5yqZZAXZa/vDMVJvTxhVV3Rac@gpvX3RQKqzHkfZOD3FgYP4oA7qfqhcVRpYOq317L@UzsCiyshjeess1usM1aulgdxabaBw1SojRWWgzjf@zq/TLw "Scala – Try It Online"

Takes input as a list of two numbers. The fact that the length can be 0 makes this a bit longer. Explanation coming soon.