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

71%
+3 −0
Challenges Is it part of the mandelbrot set?

Haskell, 66 bytes -7 bytes thanks to Razetime‭ import Data.Complex (\c->(<2).magnitude$(iterate(\z->z*z+c)c)!!16) I use the fact, that if the result is bigger than 2, it will be fore...

posted 1y ago by Arpad Horvath‭  ·  edited 1y ago by Arpad Horvath‭

Answer
#7: Post edited by user avatar Arpad Horvath‭ · 2023-11-13T02:02:39Z (about 1 year ago)
Shorter
  • Haskell, 73 bytes
  • ```
  • import Data.Complex
  • (\c->(<2).magnitude$last$take 16$iterate(\z->z*z+c)c)
  • ```
  • I use the fact, that if the result is bigger than 2, it will be forever then, so I don't need to check this relation in each iterations. It is enough to check it in the end.
  • `iterate(\z->z*z+c)c` gives us a list of the results, the original `c` is the first, then I take 16 elements from the list, so with the `last` function I get the last element which was iterated 15 times, that is $z_{16}$ (the first 0 times, the nth element n-1 times). Then I get the absolute value, and compare it with 2.
  • Testing:
  • ```
  • import Data.Complex
  • f=(\c->(<2).magnitude $ last $ take 16$ iterate (\z -> z*z+c) c)
  • map f [(-1.862069) :+ (-0.3448276),0.3448276 :+ 0.3448276,0.2068966 :+ 0.7586207]
  • ```
  • gives
  • ```
  • [False,True,False]
  • ```
  • Or if you like it better to print to the standard output:
  • ```
  • main = do print $ map f [(-1.8620690) :+ (-0.3448276), 0.3448276 :+ 0.3448276, 0.2068966 :+ 0.7586207]
  • main
  • ```
  • Haskell, 66 bytes
  • -7 bytes thanks to Razetime‭
  • ```
  • import Data.Complex
  • (\c->(<2).magnitude$(iterate(\z->z*z+c)c)!!16)
  • ```
  • I use the fact, that if the result is bigger than 2, it will be forever then, so I don't need to check this relation in each iterations. It is enough to check it in the end.
  • `iterate(\z->z*z+c)c` gives us a list of the results, the original `c` is the first, then I take 16 elements from the list, so with the `last` function I get the last element which was iterated 15 times, that is $z_{16}$ (the first 0 times, the nth element n-1 times). Then I get the absolute value, and compare it with 2.
  • Testing:
  • ```
  • import Data.Complex
  • f=(\c->(<2).magnitude $ last $ take 16$ iterate (\z -> z*z+c) c)
  • map f [(-1.862069) :+ (-0.3448276),0.3448276 :+ 0.3448276,0.2068966 :+ 0.7586207]
  • ```
  • gives
  • ```
  • [False,True,False]
  • ```
  • Or if you like it better to print to the standard output:
  • ```
  • main = do print $ map f [(-1.8620690) :+ (-0.3448276), 0.3448276 :+ 0.3448276, 0.2068966 :+ 0.7586207]
  • main
  • ```
#6: Post edited by user avatar Arpad Horvath‭ · 2023-11-11T11:25:47Z (about 1 year ago)
+import
  • Haskell, 53 bytes
  • ```
  • (\c->(<2).magnitude$last$take 16$iterate(\z->z*z+c)c)
  • ```
  • I use the fact, that if the result is bigger than 2, it will be forever then, so I don't need to check this relation in each iterations. It is enough to check it in the end.
  • `iterate(\z->z*z+c)c` gives us a list of the results, the original `c` is the first, then I take 16 elements from the list, so with the `last` function I get the last element which was iterated 15 times, that is $z_{16}$ (the first 0 times, the nth element n-1 times). Then I get the absolute value, and compare it with 2.
  • Testing:
  • ```
  • import Data.Complex
  • f=(\c->(<2).magnitude $ last $ take 16$ iterate (\z -> z*z+c) c)
  • map f [(-1.862069) :+ (-0.3448276),0.3448276 :+ 0.3448276,0.2068966 :+ 0.7586207]
  • ```
  • gives
  • ```
  • [False,True,False]
  • ```
  • Or if you like it better to print to the standard output:
  • ```
  • main = do print $ map f [(-1.8620690) :+ (-0.3448276), 0.3448276 :+ 0.3448276, 0.2068966 :+ 0.7586207]
  • main
  • ```
  • Haskell, 73 bytes
  • ```
  • import Data.Complex
  • (\c->(<2).magnitude$last$take 16$iterate(\z->z*z+c)c)
  • ```
  • I use the fact, that if the result is bigger than 2, it will be forever then, so I don't need to check this relation in each iterations. It is enough to check it in the end.
  • `iterate(\z->z*z+c)c` gives us a list of the results, the original `c` is the first, then I take 16 elements from the list, so with the `last` function I get the last element which was iterated 15 times, that is $z_{16}$ (the first 0 times, the nth element n-1 times). Then I get the absolute value, and compare it with 2.
  • Testing:
  • ```
  • import Data.Complex
  • f=(\c->(<2).magnitude $ last $ take 16$ iterate (\z -> z*z+c) c)
  • map f [(-1.862069) :+ (-0.3448276),0.3448276 :+ 0.3448276,0.2068966 :+ 0.7586207]
  • ```
  • gives
  • ```
  • [False,True,False]
  • ```
  • Or if you like it better to print to the standard output:
  • ```
  • main = do print $ map f [(-1.8620690) :+ (-0.3448276), 0.3448276 :+ 0.3448276, 0.2068966 :+ 0.7586207]
  • main
  • ```
#5: Post edited by user avatar Arpad Horvath‭ · 2023-11-11T06:50:20Z (about 1 year ago)
Back to 16, ay z_1 is the original
  • Haskell, 53 bytes
  • ```
  • (\c->(<2).magnitude$last$take 17$iterate(\z->z*z+c)c)
  • ```
  • I use the fact, that if the result is bigger than 2, it will be forever then, so I don't need to check this relation in each iterations. It is enough to check it in the end.
  • `iterate(\z->z*z+c)c` gives us a list of the results, the original `c` is the first, then I take 17 elements from the list, so with the `last` function I get the last element which was iterated 16 times (the first 0 times, the nth element n-1 times). Then I get the absolute value, and compare it with 2.
  • Testing:
  • ```
  • import Data.Complex
  • f=(\c->(<2).magnitude $ last $ take 17$ iterate (\z -> z*z+c) c)
  • map f [(-1.862069) :+ (-0.3448276),0.3448276 :+ 0.3448276,0.2068966 :+ 0.7586207]
  • ```
  • gives
  • ```
  • [False,True,False]
  • ```
  • Or if you like it better to print to the standard output:
  • ```
  • main = do print $ map f [(-1.8620690) :+ (-0.3448276), 0.3448276 :+ 0.3448276, 0.2068966 :+ 0.7586207]
  • main
  • ```
  • Haskell, 53 bytes
  • ```
  • (\c->(<2).magnitude$last$take 16$iterate(\z->z*z+c)c)
  • ```
  • I use the fact, that if the result is bigger than 2, it will be forever then, so I don't need to check this relation in each iterations. It is enough to check it in the end.
  • `iterate(\z->z*z+c)c` gives us a list of the results, the original `c` is the first, then I take 16 elements from the list, so with the `last` function I get the last element which was iterated 15 times, that is $z_{16}$ (the first 0 times, the nth element n-1 times). Then I get the absolute value, and compare it with 2.
  • Testing:
  • ```
  • import Data.Complex
  • f=(\c->(<2).magnitude $ last $ take 16$ iterate (\z -> z*z+c) c)
  • map f [(-1.862069) :+ (-0.3448276),0.3448276 :+ 0.3448276,0.2068966 :+ 0.7586207]
  • ```
  • gives
  • ```
  • [False,True,False]
  • ```
  • Or if you like it better to print to the standard output:
  • ```
  • main = do print $ map f [(-1.8620690) :+ (-0.3448276), 0.3448276 :+ 0.3448276, 0.2068966 :+ 0.7586207]
  • main
  • ```
#4: History hidden by user avatar Arpad Horvath‭ · 2023-11-11T06:02:22Z (about 1 year ago)
Detailed history before this event is hidden because of a redaction.
Haskell, 53 bytes

```
(\c->(<2).magnitude$last$take 17$iterate(\z->z*z+c)c)
```

I use the fact, that if the result is bigger than 2, it will be forever then, so I don't need to check this relation in each iterations. It is enough to check it in the end.

`iterate(\z->z*z+c)c` gives us a list of the results, the original `c` is the first, then I take 17 elements from the list, so with the `last` function I get the last element which was iterated 16 times (the first 0 times, the nth element n-1 times). Then I get the absolute value, and compare it with 2.

Testing:

```
import Data.Complex

f=(\c->(<2).magnitude $ last $ take 17$ iterate (\z -> z*z+c) c)
map f [(-1.862069) :+ (-0.3448276),0.3448276 :+ 0.3448276,0.2068966 :+ 0.7586207]
```

gives

```
[False,True,False]
```


Or if you like it better to print to the standard output:


```
main = do   print $ map f [(-1.8620690) :+ (-0.3448276),  0.3448276 :+ 0.3448276, 0.2068966 :+ 0.7586207]
main
```
#3: Post edited by user avatar Arpad Horvath‭ · 2023-11-11T06:02:22Z (about 1 year ago)
Some hints how does it work

The detailed changes of this event are hidden because of a redaction.

#2: Post edited by user avatar Arpad Horvath‭ · 2023-11-11T05:44:03Z (about 1 year ago)
print version

The detailed changes of this event are hidden because of a redaction.

#1: Initial revision by user avatar Arpad Horvath‭ · 2023-11-11T05:24:50Z (about 1 year ago)

The detailed changes of this event are hidden because of a redaction.