Post History
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...
Answer
#2: Post edited
- # [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
# [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.