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 »

Review Suggested Edit

You can't approve or reject suggested edits because you haven't yet earned the Edit Posts ability.

Approved.
This suggested edit was approved and applied to the post about 1 year ago by H_H‭.

35 / 255
Is it part of the mandelbrot set?
  • Input is a number, you have to decide if it is part of the mandelbrot set or not, after at least 16 iterations.
  • This is done by applying this formula: $z_n = z_{n-1}^2 + c$ repeatedly. $c$ is the input number and $z_0 = 0$. Therefore:
  • - $z_1 = c$
  • - $z_2 = c^2 + c$
  • - $z_3 = ( c^2 + c )^2 +c$
  • - $z_4 = ( ( c^2 + c )^2 +c )^2 +c$
  • - ...
  • If $|z_{16}|>2$, then the input $c$ is not part of the mandelbrot set. If $|z_{16}| ≤ 2$, then we consider it part of the mandelbrot set for this challenge.
  • ## Rules
  • - The input is a complex number $|c|≤2$
  • - At least up to 16 iterations have to be checked. If more is easier to do, do more.
  • - If it is easier, you can check for the real part $Re(z_{n})$ to be $Re(z_{n})>2$ or $|Re(z_{n})|>2$ instead of $|z_{n}|>2$. But then it should be checked for each iteration. This includes some numbers that are not part of the mandelbrot set but we ignore that for this challenge.
  • - If it is easier, the limit can be anywhere between 2-6 and doesn't have to be 2, for example you could check for $|z_{16}|>4$ instead of $|z_{16}|>2$.
  • - If it is easier, a additional input for the number of iterations can be given, but then at least 3-64 iterations (chosen by the input) have to be supported.
  • - If it is easier, a additional input for $z_0$ or $z_1$ can be given.
  • - The input format can be chosen how it is best for you, but input has to be representable with a error of $|E|≤ { 1 \over 1024} $ on each axis i.e. you need at least 11 bit for each axis.
  • - Output one value for inputs in the mandelbrot set (after 16 iterations) and a different value for inputs outside the mandelbrot set. If it is easier you can return the number of iterations till $|z_{n}|>2$ is reached.
  • - Not halting vs halting is a valid form of output (for example you can create a program that loops forever when the input is inside the mandelbrot set but end the loop when the input is not part of the mandelbrot set).
  • Shortest code wins.
  • ## Non-golfed Examples
  • Python example using native complex number
  • ```
  • def isPartOfMandelbrot(c):
  • z=c
  • for i in range(16):
  • z=z**2+c
  • if abs(z)>2:
  • return 0
  • return 1
  • print( isPartOfMandelbrot( float(input()) + float(input())*1j ) )
  • ```
  • C example using fractions:
  • ```
  • #include <stdio.h>
  • #include <stdlib.h>
  • /*
  • Return 0 when the input is not in the mandelbrot set
  • Return 1 when the input is in the mandelbrot set
  • cr: real part of the input, as numerator of a fraction
  • ci: imaginary part of the input, as numerator of a fraction
  • denominator: the denominator of all fractions
  • iterations: Up to how many iterations we check.
  • */
  • int insideMandelbrot(int cr, int ci, int denominator, int iterations)
  • {
  • int zr=cr;
  • int zi=ci;
  • while( zr<2*denominator )
  • {
  • int t = zr*zr/denominator - zi*zi/denominator;
  • zi = zr*zi/denominator*2 + ci;
  • zr = t + cr;
  • if( !iterations-- )
  • { return 1; }
  • }
  • return 0;
  • }
  • int main(int argc, char **argv)
  • {
  • if( argc<3 )
  • { return 0; }
  • //We use 2 fraction to store the complex number
  • //One fraction for the real one fraction for the imaginary part
  • //The fraction have a fixed denominator of 512.
  • //Both are expected to be between -1024 (for -2) and 1024 (for 2)
  • //cr is the real part. ci the imaginary part
  • int cr = atoi( argv[1] );
  • int ci = atoi( argv[2] );
  • puts( insideMandelbrot(cr,ci,512,16) ? "Inside" : "Outside" );
  • }
  • ```
  • Input is a number, you have to decide if it is part of the mandelbrot set or not, after at least 16 iterations.
  • This is done by applying this formula: $z_n = z_{n-1}^2 + c$ repeatedly. $c$ is the input number and $z_0 = 0$. Therefore:
  • - $z_1 = c$
  • - $z_2 = c^2 + c$
  • - $z_3 = ( c^2 + c )^2 +c$
  • - $z_4 = ( ( c^2 + c )^2 +c )^2 +c$
  • - ...
  • If $|z_{16}|>2$, then the input $c$ is not part of the mandelbrot set. If $|z_{16}| ≤ 2$, then we consider it part of the mandelbrot set for this challenge.
  • ## Rules
  • - The input is a complex number $|c|≤2$
  • - At least up to 16 iterations have to be checked. If more is easier to do, do more.
  • - If it is easier, you can check for the real part $Re(z_{n})$ to be $Re(z_{n})>2$ or $|Re(z_{n})|>2$ instead of $|z_{n}|>2$. But then it should be checked for each iteration. This includes some numbers that are not part of the mandelbrot set but we ignore that for this challenge.
  • - If it is easier, the limit can be anywhere between 2-6 and doesn't have to be 2, for example you could check for $|z_{16}|>4$ instead of $|z_{16}|>2$.
  • - If it is easier, an additional input for the number of iterations can be given, but then at least 3-64 iterations (chosen by the input) have to be supported.
  • - If it is easier, an additional input for $z_0$ or $z_1$ can be given.
  • - The input format can be chosen how it is best for you, but input has to be representable with an error of $|E|≤ { 1 \over 1024} $ on each axis i.e. you need at least 11 bit for each axis.
  • - Output one value for inputs in the mandelbrot set (after 16 iterations) and a different value for inputs outside the mandelbrot set. If it is easier you can return the number of iterations till $|z_{n}|>2$ is reached.
  • - Not halting vs halting is a valid form of output (for example you can create a program that loops forever when the input is inside the mandelbrot set but end the loop when the input is not part of the mandelbrot set).
  • Shortest code wins.
  • ## Non-golfed Examples
  • Python example using native complex number
  • ```
  • def isPartOfMandelbrot(c):
  • z=c
  • for i in range(16):
  • z=z**2+c
  • if abs(z)>2:
  • return 0
  • return 1
  • print( isPartOfMandelbrot( float(input()) + float(input())*1j ) )
  • ```
  • C example using fractions:
  • ```
  • #include <stdio.h>
  • #include <stdlib.h>
  • /*
  • Return 0 when the input is not in the mandelbrot set
  • Return 1 when the input is in the mandelbrot set
  • cr: real part of the input, as numerator of a fraction
  • ci: imaginary part of the input, as numerator of a fraction
  • denominator: the denominator of all fractions
  • iterations: Up to how many iterations we check.
  • */
  • int insideMandelbrot(int cr, int ci, int denominator, int iterations)
  • {
  • int zr=cr;
  • int zi=ci;
  • while( zr<2*denominator )
  • {
  • int t = zr*zr/denominator - zi*zi/denominator;
  • zi = zr*zi/denominator*2 + ci;
  • zr = t + cr;
  • if( !iterations-- )
  • { return 1; }
  • }
  • return 0;
  • }
  • int main(int argc, char **argv)
  • {
  • if( argc<3 )
  • { return 0; }
  • //We use 2 fraction to store the complex number
  • //One fraction for the real one fraction for the imaginary part
  • //The fraction have a fixed denominator of 512.
  • //Both are expected to be between -1024 (for -2) and 1024 (for 2)
  • //cr is the real part. ci the imaginary part
  • int cr = atoi( argv[1] );
  • int ci = atoi( argv[2] );
  • puts( insideMandelbrot(cr,ci,512,16) ? "Inside" : "Outside" );
  • }
  • ```

Suggested about 1 year ago by trichoplax‭