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

77%
+5 −0
Challenges Juggler sequences

Scala, 78 67 64 bytes Saved 3 bytes thanks to Razetime Stream.iterate(_)(x=>math.pow(x,x%2+.5).toInt).takeWhile(_>1):+1 Try it in Scastie! Stream.iterate(_) //Make an infinite list by r...

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

Answer
#3: Post edited by user avatar user‭ · 2021-05-10T21:26:14Z (over 3 years ago)
I'm an idiot
  • # Scala, <s>78</s> 67 bytes
  • ```scala
  • Stream.iterate(_)(x=>math.pow(x,x%2+1/2.0).toInt).takeWhile(_>1):+1
  • ```
  • [Try it in Scastie!](https://scastie.scala-lang.org/dQO2Rb8sRFiG5HT78jdryg)
  • ```
  • Stream.iterate(_) //Make an infinite list by repeatedly applying
  • (x=> //the following function to the input
  • math.pow(x, //Raise x to the power of
  • x%2 //x%2 (0 or 1)
  • +1/2.0 //plus .5 (.5 or 1.5)
  • ).toInt //Floor it
  • ).takeWhile(_>1) //Take all elements until it hits 1
  • :+1 //Append a 1
  • ```
  • # Scala, <s>78 67</s> 64 bytes
  • Saved 3 bytes thanks to Razetime
  • ```scala
  • Stream.iterate(_)(x=>math.pow(x,x%2+.5).toInt).takeWhile(_>1):+1
  • ```
  • [Try it in Scastie!](https://scastie.scala-lang.org/Ihm2Gb3UQRWIoiv7fEW1rg)
  • ```
  • Stream.iterate(_) //Make an infinite list by repeatedly applying
  • (x=> //the following function to the input
  • math.pow(x, //Raise x to the power of
  • x%2 //x%2 (0 or 1)
  • +.5 //plus .5 (.5 or 1.5)
  • ).toInt //Floor it
  • ).takeWhile(_>1) //Take all elements until it hits 1
  • :+1 //Append a 1
  • ```
#2: Post edited by user avatar user‭ · 2021-05-09T14:52:28Z (over 3 years ago)
  • # Scala, 78 bytes
  • ```scala
  • Stream.iterate(_)(x=>math.sqrt(if(x%2<1)x else x*x*x).toInt).takeWhile(_>1):+1
  • ```
  • [Try it in Scastie!](https://scastie.scala-lang.org/UUEIWCugQSOUr2gTfFLo7w)
  • ```
  • Stream.iterate(_) //Make an infinite list by repeatedly applying
  • (x=> //the following function to the input
  • math.sqrt( //Take the square root of
  • if(x%2<1)x else x*x*x //x or x^3, depending on the parity
  • ).toInt //Floor it
  • ).takeWhile(_>1) //Take all elements until it hits 1
  • :+1 //Append a 1
  • ```
  • # Scala, <s>78</s> 67 bytes
  • ```scala
  • Stream.iterate(_)(x=>math.pow(x,x%2+1/2.0).toInt).takeWhile(_>1):+1
  • ```
  • [Try it in Scastie!](https://scastie.scala-lang.org/dQO2Rb8sRFiG5HT78jdryg)
  • ```
  • Stream.iterate(_) //Make an infinite list by repeatedly applying
  • (x=> //the following function to the input
  • math.pow(x, //Raise x to the power of
  • x%2 //x%2 (0 or 1)
  • +1/2.0 //plus .5 (.5 or 1.5)
  • ).toInt //Floor it
  • ).takeWhile(_>1) //Take all elements until it hits 1
  • :+1 //Append a 1
  • ```
#1: Initial revision by user avatar user‭ · 2021-05-05T14:02:40Z (over 3 years ago)
# Scala, 78 bytes
```scala
Stream.iterate(_)(x=>math.sqrt(if(x%2<1)x else x*x*x).toInt).takeWhile(_>1):+1
```
[Try it in Scastie!](https://scastie.scala-lang.org/UUEIWCugQSOUr2gTfFLo7w)

```
Stream.iterate(_) //Make an infinite list by repeatedly applying
(x=>              //the following function to the input
  math.sqrt(      //Take the square root of
    if(x%2<1)x else x*x*x //x or x^3, depending on the parity
  ).toInt         //Floor it
).takeWhile(_>1)  //Take all elements until it hits 1
:+1               //Append a 1
```