Posts by General Sebast1an
Java (JDK), 88 83 bytes static void f(String s){for(int i=s.length();i>0;System.out.print(s.charAt(--i)));} Try it online!
Java (JDK), 51 50 23 21 bytes x->y->x==y&y==2?5:x+y Try it online! Golfed 27 bytes thanks to @Moshi's advice. Golfed 2 bytes thanks to @user's advice on Discord.
A clever way to replace Math functions You can shorten if-else statements through the a?b:c syntax, where a is the statement of if, b is the result of if, and c is the result of else. static vo...
Booleans are replaceable Java, like Python, has pretty convenient yet nasty ways to golfing down code through comparison operators. Especially this case, this time with booleans. You can compare i...
Java (JDK), 150 bytes interface M{static void main(String[]a){int i=new java.util.Scanner(System.in).nextInt(),j=0;for(;i!=1;j++){i=i%2==1?i*3+1:i/2;}System.out.print(j);}} Try it online! Fr...
Java (JDK), 311 301 296 bytes interface A{static void main(String[]x){String a=" bottle",b=" of beer",c=" on the wall. ",e;for(int i=99;i>0;i--){e=i>1?"s":"";System.out.println(i+a+e+b+c+(...
Use interface The special thing about this is that it lets you drop public when you originally call a class to run the main function. class F{public static void main(String[]a{}} interface M{sta...
Use for(;;) instead of while(true) The title's self-explanatory. A byte saver.
This is a list of golfing tips for the language known as Java. If you have a tip, add it in!
Challenge Make a program that takes input of 3 non-negative integers: a result and 2 other values that once calculated results to the 3rd value. The program must figure out how to get the 2 fir...
shortC, 78 bytes i,j;f(Ix,Iy,I*p){R"[");O;i<x;i++)Oj=0;j<y;j++)*p++&&R"[%d,%d],",i,j);J"\b]");} Try it online! From @Lundin's C (gcc) answer.
shortC, 38 bytes Bs){Rs="Bs){Rs=%c%s%c,34,s,34",34,s,34 Try it online! From GeeksForGeeks's C implementation.
shortC, 47 bytes a,b;AOK"%d",&b);b-1;b=b%2?b*3+1:b/2)a++;R"%d",a Try it online! From @ugoren's C answer from CGCC.
shortC, 223 bytes AOC*w=" bottles of beer on the wall",i=100;--i;)R"%d%.*s%s, %d%.*s%.8s.\n%s, %d%.*s%s.\n\n",i,i-1?8:7,w,w+8,i,i-1?8:7,w,w+8,i^1?"Take one down and pass it around":"Go to the stor...
shortC, 40 37 bytes i;f(C*s,In){O;*s;s++)Oi=n;i--;P*s));} Try it online! A shortC conversion of @Lundin's C (gcc) implementation.
shortC, 24 bytes f(C*s){*s&&f(s+1)^P*s);} Try it online! A shortC conversion of @Sisyphus's C (gcc) implementation.
Python 3, 268 250 235 233 210 197 148 bytes def a(n):e=(n>>6).bit_length();f=2**e;l=n&(f-1);N=(n>>e)&31;return((e+(n>31))<<5)+N+(2*l+N%2>f) def b(r):E=r>>5...
| == or This bitwise operator can sometimes be used as the replacement for or. a=-2;b=3 if(a>0)|(b>0):print(a+b) Try it online!
shortC, 95 93 91 bytes AIi;Wi++<100){C*h[]={"%d "," "},**p=h;i%3||(*p++="Fizz%2$s");i%5||(*p="Buzz ");R*h,i,h[1]); Try it online! From @celtschk's C (gcc) answer.
Python 3, 596 589 585 482 468 467 429 bytes def f(x): s="";i="r fif six seven eigh nine";a=f"zero one two three four five six seven eight nine ten eleven twelve thir fou{i} twen thir fo{i}".sp...