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

added 15 characters in body
Source Link
Kevin Cruijssen
  • 136.2k
  • 14
  • 154
  • 394

Java 8, 280(削除) 280 (削除ここまで) 274 bytes

-6 bytes thanks to @ceilingcat.

Try it here. Try it here.

interface M{ // Class
 static void main(String[]a){ // Mandatory main-method
 String x="", // String for row 1, starting empty
 y=x, // String for row 2, starting empty
 z=x; // String for row 3, starting empty
 for(int c:a[0].getBytes()){ // Loop over the bytes of the input
 c-=48; // Convert the byte to integer
 x+= // Append to row 1:
 " " // a space
 +(c==4|c==1? // +IfIf the digit is a 1 or 4:
 " " " // Append athree spacespaces
 : // Else:
 "_")" _ "; // Append an underscore
 +" ";  // a space + underscore + another space instead
 y+= // Append to row 2:
 (c==7|c>0&c<4? // If the digit is 1, 2, 3, or 7:
 " " // Append a space
 : // Else:
 "|") // Append a pipe
 +(c==7|c<2? // +If the digit is 0, 1, or 7:
 " " // Append a space
 : // Else:
 "_") // Append an underscore
 +(c>4&c<7? // +If the digit is 5 or 6:
 " " // Append a space
 : // Else:
 "|"); // Append a pipe
 z+= // Append to row 3:
 (c%2<1&c!=4? // If the digit is 0, 2, 6 or 8:
 "|" // Append a pipe
 : // Else:
 " ") // Append a space
 +(c%3==1? // +If the digit is 1, 4, or 7:
 " " // Append a space
 : // Else:
 "_") // Append a pipe
 +(c==2? // +If the digit is 2:
 " " // Append a space
 : // Else:
 "|"); // Append a pipe
 } // End of loop
 System.out.print(x+"\n"+y+"\n"+z);
 // Print the three rows
 } // End of main-method
} // End of class

As function this would be 218 bytes 212 bytes instead.

Java 8, 280 bytes

Try it here.

interface M{ // Class
 static void main(String[]a){ // Mandatory main-method
 String x="", // String for row 1, starting empty
 y=x, // String for row 2, starting empty
 z=x; // String for row 3, starting empty
 for(int c:a[0].getBytes()){ // Loop over the bytes of the input
 c-=48; // Convert the byte to integer
 x+= // Append to row 1:
 " " // a space
 +(c==4|c==1? // +If the digit is a 1 or 4:
 " " // Append a space
 : // Else:
 "_") // Append an underscore
 +" ";  //  + another space
 y+= // Append to row 2:
 (c==7|c>0&c<4? // If the digit is 1, 2, 3, or 7:
 " " // Append a space
 : // Else:
 "|") // Append a pipe
 +(c==7|c<2? // +If the digit is 0, 1, or 7:
 " " // Append a space
 : // Else:
 "_") // Append an underscore
 +(c>4&c<7? // +If the digit is 5 or 6:
 " " // Append a space
 : // Else:
 "|"); // Append a pipe
 z+= // Append to row 3:
 (c%2<1&c!=4? // If the digit is 0, 2, 6 or 8:
 "|" // Append a pipe
 : // Else:
 " ") // Append a space
 +(c%3==1? // +If the digit is 1, 4, or 7:
 " " // Append a space
 : // Else:
 "_") // Append a pipe
 +(c==2? // +If the digit is 2:
 " " // Append a space
 : // Else:
 "|"); // Append a pipe
 } // End of loop
 System.out.print(x+"\n"+y+"\n"+z);
 // Print the three rows
 } // End of main-method
} // End of class

As function this would be 218 bytes instead.

Java 8, (削除) 280 (削除ここまで) 274 bytes

-6 bytes thanks to @ceilingcat.

Try it here.

interface M{ // Class
 static void main(String[]a){ // Mandatory main-method
 String x="", // String for row 1, starting empty
 y=x, // String for row 2, starting empty
 z=x; // String for row 3, starting empty
 for(int c:a[0].getBytes()){ // Loop over the bytes of the input
 c-=48; // Convert the byte to integer
 x+= // Append to row 1:
 c==4|c==1? // If the digit is a 1 or 4:
 " " // Append three spaces
 : // Else:
 " _ "; // Append a space + underscore + space instead
 y+= // Append to row 2:
 (c==7|c>0&c<4? // If the digit is 1, 2, 3, or 7:
 " " // Append a space
 : // Else:
 "|") // Append a pipe
 +(c==7|c<2? // +If the digit is 0, 1, or 7:
 " " // Append a space
 : // Else:
 "_") // Append an underscore
 +(c>4&c<7? // +If the digit is 5 or 6:
 " " // Append a space
 : // Else:
 "|"); // Append a pipe
 z+= // Append to row 3:
 (c%2<1&c!=4? // If the digit is 0, 2, 6 or 8:
 "|" // Append a pipe
 : // Else:
 " ") // Append a space
 +(c%3==1? // +If the digit is 1, 4, or 7:
 " " // Append a space
 : // Else:
 "_") // Append a pipe
 +(c==2? // +If the digit is 2:
 " " // Append a space
 : // Else:
 "|"); // Append a pipe
 } // End of loop
 System.out.print(x+"\n"+y+"\n"+z);
 // Print the three rows
 } // End of main-method
} // End of class

As function this would be 212 bytes instead.

Commonmark migration
Source Link

#Java 8, 280 bytes

Java 8, 280 bytes

#Java 8, 280 bytes

Java 8, 280 bytes

Source Link
Kevin Cruijssen
  • 136.2k
  • 14
  • 154
  • 394

#Java 8, 280 bytes

interface M{static void main(String[]a){String x="",y=x,z=x;for(int c:a[0].getBytes()){c-=48;x+=" "+(c==4|c==1?" ":"_")+" ";y+=(c==7|c>0&c<4?" ":"|")+(c==7|c<2?" ":"_")+(c>4&c<7?" ":"|");z+=(c%2<1&c!=4?"|":" ")+(c%3==1?" ":"_")+(c==2?" ":"|");}System.out.print(x+"\n"+y+"\n"+z);}}

Explanation:

Try it here.

interface M{ // Class
 static void main(String[]a){ // Mandatory main-method
 String x="", // String for row 1, starting empty
 y=x, // String for row 2, starting empty
 z=x; // String for row 3, starting empty
 for(int c:a[0].getBytes()){ // Loop over the bytes of the input
 c-=48; // Convert the byte to integer
 x+= // Append to row 1:
 " " // a space
 +(c==4|c==1? // +If the digit is a 1 or 4:
 " " // Append a space
 : // Else:
 "_") // Append an underscore
 +" "; // + another space
 y+= // Append to row 2:
 (c==7|c>0&c<4? // If the digit is 1, 2, 3, or 7:
 " " // Append a space
 : // Else:
 "|") // Append a pipe
 +(c==7|c<2? // +If the digit is 0, 1, or 7:
 " " // Append a space
 : // Else:
 "_") // Append an underscore
 +(c>4&c<7? // +If the digit is 5 or 6:
 " " // Append a space
 : // Else:
 "|"); // Append a pipe
 z+= // Append to row 3:
 (c%2<1&c!=4? // If the digit is 0, 2, 6 or 8:
 "|" // Append a pipe
 : // Else:
 " ") // Append a space
 +(c%3==1? // +If the digit is 1, 4, or 7:
 " " // Append a space
 : // Else:
 "_") // Append a pipe
 +(c==2? // +If the digit is 2:
 " " // Append a space
 : // Else:
 "|"); // Append a pipe
 } // End of loop
 System.out.print(x+"\n"+y+"\n"+z);
 // Print the three rows
 } // End of main-method
} // End of class

As function this would be 218 bytes instead.

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