Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

deleted 205 characters in body
Source Link

C++ (gcc), 143(削除) 143 (削除ここまで) 125 bytes

-18 bytes thanks to @ceilingcat

Explanation: it uses the constructor of a class to do the Fibonacci increment operation, and then sets up a variable number of global instances of that class to be initialized before main. The catch being that all those variables have to be named differently, and there's a bit of preprocessor magic needed to get the __LINE__ macro combined into the variable names.

(And then, since I couldn't see any way to be able to do a #include before the line which had to be commented in all occurrences but one, it ended up being a bit expensive to manually define a close-enough printf prototype.)

int m,n=1;struct A{A(){m+=n;n=m-n;}};extern"C" int printf(...);int main(){printf__builtin_printf("%d",m);}
#define Y(x)A a##x;
#define X(x)Y(x)
X(__LINE__)//

Try it online! Try it online!

C++ (gcc), 143 bytes

Explanation: it uses the constructor of a class to do the Fibonacci increment operation, and then sets up a variable number of global instances of that class to be initialized before main. The catch being that all those variables have to be named differently, and there's a bit of preprocessor magic needed to get the __LINE__ macro combined into the variable names.

(And then, since I couldn't see any way to be able to do a #include before the line which had to be commented in all occurrences but one, it ended up being a bit expensive to manually define a close-enough printf prototype.)

int m,n=1;struct A{A(){m+=n;n=m-n;}};extern"C" int printf(...);int main(){printf("%d",m);}
#define Y(x)A a##x;
#define X(x)Y(x)
X(__LINE__)//

Try it online!

C++ (gcc), (削除) 143 (削除ここまで) 125 bytes

-18 bytes thanks to @ceilingcat

Explanation: it uses the constructor of a class to do the Fibonacci increment operation, and then sets up a variable number of global instances of that class to be initialized before main. The catch being that all those variables have to be named differently, and there's a bit of preprocessor magic needed to get the __LINE__ macro combined into the variable names.

int m,n=1;struct A{A(){m+=n;n=m-n;}};int main(){__builtin_printf("%d",m);}
#define Y(x)A a##x;
#define X(x)Y(x)
X(__LINE__)//

Try it online!

Source Link

C++ (gcc), 143 bytes

Explanation: it uses the constructor of a class to do the Fibonacci increment operation, and then sets up a variable number of global instances of that class to be initialized before main. The catch being that all those variables have to be named differently, and there's a bit of preprocessor magic needed to get the __LINE__ macro combined into the variable names.

(And then, since I couldn't see any way to be able to do a #include before the line which had to be commented in all occurrences but one, it ended up being a bit expensive to manually define a close-enough printf prototype.)

int m,n=1;struct A{A(){m+=n;n=m-n;}};extern"C" int printf(...);int main(){printf("%d",m);}
#define Y(x) A a##x;
#define X(x) Y(x)
X(__LINE__)//

Try it online!

AltStyle によって変換されたページ (->オリジナル) /