Skip to main content
-2 bytes
Source Link
Kevin Cruijssen
  • 136.3k
  • 14
  • 155
  • 394

Java 8, 420 418 402 373 359 357 341341 339 bytes

import java.util.*;s->f(s,new Stack());void f(String s,Stack<Integer>S){for(int i=0,c,t,u;i++<su;i<s.length();){if((c=s.charAt(i-1i++))<42&&S.peek()!=0)f(s.substring(40/c*i),S);if(c==46)System.out.println(S.peek());if(c>57)S.add(c>99?new Random().nextInt():S.peek());if(c<44|c==45|c==47){t=S.pop();u=S.pop();S.add(c<43?u*t:c<45?u+t:c<46?u-t:u/t);}}} 

-2 bytes thanks to @Grimy.
-1618 bytes thanks to @ceilingcat.

Try it online.Try it online.

import java.util.*; // Required import for 2x Stack and Random s-> // Method with String parameter and no return-type f(s,new Stack()) // Call the recursive function, with a new Stack // Separated recursive method with String and Stack parameters void f(String s,Stack<Integer>S){ int i=0, // Index integer c, // Temp integer used for the current character t,u; // Temp integers used for the peeked/popped top of the stack for(;i++<s;i<s.length();){  // Loop `i` in the range [0, String-length): if((c=s.charAt(i-1))  // Set `c` to the current character ++)) // And increase index `i` by 1 right after <42 // If the character is either '(' or ')', &&S.peek()!=0) // and the top of the stack is not 0: f(s.substring( // Take the substring, either removing everything before and 40/c*i), // including the "(", or keeping the string as is for ")" S); // And do a recursive call with this String if(c==46) // If the character is '.' System.out.println( // Print with trailing newline: S.peek()); // The peeked top of the stack if(c>57) // If the character is ':' or '~': S.add(c>99? // If the character is '~': new Random().nextInt() // Add a random [0,2147483647) integer to the stack : // Else (the character is ':') S.peek()); // Add the peeked top to the stack if(c<44|c==45|c==47) // If the character is '*', '+', '-', or '/': t=S.pop();u=S.pop();// Pop and set the top two values to `t` and `u` S.add(c<43? // If the character is '*': u*t // Add the product of the two values to the stack :c<44? // Else-if the character is '+': u+t // Add the sum of the two values to the stack :c<46? // Else-if the character is '-': u-t // Subtract the top two values, and add it to the stack : // Else (the character is '/'): u/t;}}} // Divide the top two values, and add it to the stack 

Java 8, 420 418 402 373 359 357 341 bytes

import java.util.*;s->f(s,new Stack());void f(String s,Stack<Integer>S){for(int i=0,c,t,u;i++<s.length();){if((c=s.charAt(i-1))<42&&S.peek()!=0)f(s.substring(40/c*i),S);if(c==46)System.out.println(S.peek());if(c>57)S.add(c>99?new Random().nextInt():S.peek());if(c<44|c==45|c==47){t=S.pop();u=S.pop();S.add(c<43?u*t:c<45?u+t:c<46?u-t:u/t);}}} 

-2 bytes thanks to @Grimy.
-16 bytes thanks to @ceilingcat.

Try it online.

import java.util.*; // Required import for 2x Stack and Random s-> // Method with String parameter and no return-type f(s,new Stack()) // Call the recursive function, with a new Stack // Separated recursive method with String and Stack parameters void f(String s,Stack<Integer>S){ int i=0, // Index integer c, // Temp integer used for the current character t,u; // Temp integers used for the peeked/popped top of the stack for(;i++<s.length();){ // Loop `i` in the range [0, String-length): if((c=s.charAt(i-1)) // Set `c` to the current character <42 // If the character is either '(' or ')', &&S.peek()!=0) // and the top of the stack is not 0: f(s.substring( // Take the substring, either removing everything before and 40/c*i), // including the "(", or keeping the string as is for ")" S); // And do a recursive call with this String if(c==46) // If the character is '.' System.out.println( // Print with trailing newline: S.peek()); // The peeked top of the stack if(c>57) // If the character is ':' or '~': S.add(c>99? // If the character is '~': new Random().nextInt() // Add a random [0,2147483647) integer to the stack : // Else (the character is ':') S.peek()); // Add the peeked top to the stack if(c<44|c==45|c==47) // If the character is '*', '+', '-', or '/': t=S.pop();u=S.pop();// Pop and set the top two values to `t` and `u` S.add(c<43? // If the character is '*': u*t // Add the product of the two values to the stack :c<44? // Else-if the character is '+': u+t // Add the sum of the two values to the stack :c<46? // Else-if the character is '-': u-t // Subtract the top two values, and add it to the stack : // Else (the character is '/'): u/t;}}} // Divide the top two values, and add it to the stack 

Java 8, 420 418 402 373 359 357 341 339 bytes

import java.util.*;s->f(s,new Stack());void f(String s,Stack<Integer>S){for(int i=0,c,t,u;i<s.length();){if((c=s.charAt(i++))<42&&S.peek()!=0)f(s.substring(40/c*i),S);if(c==46)System.out.println(S.peek());if(c>57)S.add(c>99?new Random().nextInt():S.peek());if(c<44|c==45|c==47){t=S.pop();u=S.pop();S.add(c<43?u*t:c<45?u+t:c<46?u-t:u/t);}}} 

-2 bytes thanks to @Grimy.
-18 bytes thanks to @ceilingcat.

Try it online.

import java.util.*; // Required import for 2x Stack and Random s-> // Method with String parameter and no return-type f(s,new Stack()) // Call the recursive function, with a new Stack // Separated recursive method with String and Stack parameters void f(String s,Stack<Integer>S){ int i=0, // Index integer c, // Temp integer used for the current character t,u; // Temp integers used for the peeked/popped top of the stack for(;i<s.length();){  // Loop `i` in the range [0, String-length): if((c=s.charAt(i  // Set `c` to the current character ++)) // And increase index `i` by 1 right after <42 // If the character is either '(' or ')', &&S.peek()!=0) // and the top of the stack is not 0: f(s.substring( // Take the substring, either removing everything before and 40/c*i), // including the "(", or keeping the string as is for ")" S); // And do a recursive call with this String if(c==46) // If the character is '.' System.out.println( // Print with trailing newline: S.peek()); // The peeked top of the stack if(c>57) // If the character is ':' or '~': S.add(c>99? // If the character is '~': new Random().nextInt() // Add a random [0,2147483647) integer to the stack : // Else (the character is ':') S.peek()); // Add the peeked top to the stack if(c<44|c==45|c==47) // If the character is '*', '+', '-', or '/': t=S.pop();u=S.pop();// Pop and set the top two values to `t` and `u` S.add(c<43? // If the character is '*': u*t // Add the product of the two values to the stack :c<44? // Else-if the character is '+': u+t // Add the sum of the two values to the stack :c<46? // Else-if the character is '-': u-t // Subtract the top two values, and add it to the stack : // Else (the character is '/'): u/t;}}} // Divide the top two values, and add it to the stack 
Commonmark migration
Source Link

#Java 8, 420 418 402 373 359 357 341 bytes

Java 8, 420 418 402 373 359 357 341 bytes

#Java 8, 420 418 402 373 359 357 341 bytes

Java 8, 420 418 402 373 359 357 341 bytes

deleted 113 characters in body
Source Link
Kevin Cruijssen
  • 136.3k
  • 14
  • 155
  • 394

#Java 8, 420 418 402 373 359 357357 341 bytes

import java.util.*;s->f(s,new Stack())void;void f(String s,Stack<Integer>S){for(int i=0,c,t,u;i++<s.length();){if((c=s.charAt(i-1))<42)if(S<42&&S.peek()!=0)if(c<41)f(s.substring(i),S40/c*i);else f(s,S);if(c==46)System.out.println(S.peek());if(c>57)S.add(c>99?new Random().nextInt():S.peek());if(c<44|c==45|c==47){t=S.pop();u=S.pop();S.add(c<43?u*t:c<45?u+t:c<46?u-t:u/t);}}} 

-2 bytes thanks to @Grimy.
-16 bytes thanks to @ceilingcat.

Try it online.Try it online.

import java.util.*; // Required import for 2x Stack and Random s-> // Method with String parameter and no return-type f(s,new Stack()) // Call the recursive function, with a new Stack // Separated recursive method with String and Stack parameters void f(String s,Stack<Integer>S){ int i=0, // Index integer c, // Temp integer used for the current character t,u; // Temp integers used for the peeked/popped top of the stack for(;i++<s.length();){ // Loop `i` in the range [0, String-length): if((c=s.charAt(i-1)) // Set `c` to the current character <42)  // If the character is either '(' or ')':, if(S &&S.peek()!=0)  //  Ifand the top of the stack is not 0:   if(c<41)  f(s.substring( //  IfTake the current character is '(': f(s.substring(i),//  either Removeremoving everything before and including the "(" in the String S);  40/c*i), // including the And"(", door akeeping recursivethe callstring withas thisis trailingfor part")"   else  // Else (the character is ')') f(s,S);  //  And Dodo a recursive call aswith isthis String if(c==46) // If the character is '.' System.out.println( // Print with trailing newline: S.peek()); // The peeked top of the stack if(c>57) // If the character is ':' or '~': S.add(c>99? // If the character is '~': new Random().nextInt() // Add a random integer from the range [0,2147483647) integer to the stack : // Else (the character is ':') S.peek()); // Add the peeked top to the stack if(c<44|c==45|c==47) // If the character is '*', '+', '-', or '/': t=S.pop();u=S.pop();// Pop and set the top two values to `t` and `u` S.add(c<43? // If the character is '*': u*t // Add the product of the two values to the stack :c<44? // Else-if the character is '+': u+t // Add the sum of the two values to the stack :c<46? // Else-if the character is '-': u-t // Subtract the top two values, and add it to the stack : // Else (the character is '/'): u/t;}}} // Divide the top two values, and add it to the stack 

#Java 8, 420 418 402 373 359 357 bytes

import java.util.*;s->f(s,new Stack())void f(String s,Stack<Integer>S){for(int i=0,c,t,u;i++<s.length();){if((c=s.charAt(i-1))<42)if(S.peek()!=0)if(c<41)f(s.substring(i),S);else f(s,S);if(c==46)System.out.println(S.peek());if(c>57)S.add(c>99?new Random().nextInt():S.peek());if(c<44|c==45|c==47){t=S.pop();u=S.pop();S.add(c<43?u*t:c<45?u+t:c<46?u-t:u/t);}}} 

-2 bytes thanks to @Grimy.

Try it online.

import java.util.*; // Required import for 2x Stack and Random s-> // Method with String parameter and no return-type f(s,new Stack()) // Call the recursive function, with a new Stack // Separated recursive method with String and Stack parameters void f(String s,Stack<Integer>S){ int i=0, // Index integer c, // Temp integer used for the current character t,u; // Temp integers used for the peeked/popped top of the stack for(;i++<s.length();){ // Loop `i` in the range [0, String-length): if((c=s.charAt(i-1)) // Set `c` to the current character <42) // If the character is either '(' or ')': if(S.peek()!=0)  //  If the top of the stack is not 0:   if(c<41)  //  If the current character is '(': f(s.substring(i),//  Remove everything before and including the "(" in the String S);  // And do a recursive call with this trailing part   else  // Else (the character is ')') f(s,S); //  Do a recursive call as is if(c==46) // If the character is '.' System.out.println( // Print with trailing newline: S.peek()); // The peeked top of the stack if(c>57) // If the character is ':' or '~': S.add(c>99? // If the character is '~': new Random().nextInt() // Add a random integer from the range [0,2147483647) to the stack : // Else (the character is ':') S.peek()); // Add the peeked top to the stack if(c<44|c==45|c==47) // If the character is '*', '+', '-', or '/': t=S.pop();u=S.pop();// Pop and set the top two values to `t` and `u` S.add(c<43? // If the character is '*': u*t // Add the product of the two values to the stack :c<44? // Else-if the character is '+': u+t // Add the sum of the two values to the stack :c<46? // Else-if the character is '-': u-t // Subtract the top two values, and add it to the stack : // Else (the character is '/'): u/t;}}} // Divide the top two values, and add it to the stack 

#Java 8, 420 418 402 373 359 357 341 bytes

import java.util.*;s->f(s,new Stack());void f(String s,Stack<Integer>S){for(int i=0,c,t,u;i++<s.length();){if((c=s.charAt(i-1))<42&&S.peek()!=0)f(s.substring(40/c*i),S);if(c==46)System.out.println(S.peek());if(c>57)S.add(c>99?new Random().nextInt():S.peek());if(c<44|c==45|c==47){t=S.pop();u=S.pop();S.add(c<43?u*t:c<45?u+t:c<46?u-t:u/t);}}} 

-2 bytes thanks to @Grimy.
-16 bytes thanks to @ceilingcat.

Try it online.

import java.util.*; // Required import for 2x Stack and Random s-> // Method with String parameter and no return-type f(s,new Stack()) // Call the recursive function, with a new Stack // Separated recursive method with String and Stack parameters void f(String s,Stack<Integer>S){ int i=0, // Index integer c, // Temp integer used for the current character t,u; // Temp integers used for the peeked/popped top of the stack for(;i++<s.length();){ // Loop `i` in the range [0, String-length): if((c=s.charAt(i-1)) // Set `c` to the current character <42  // If the character is either '(' or ')',  &&S.peek()!=0) // and the top of the stack is not 0: f(s.substring( // Take the substring, either removing everything before and 40/c*i), // including the "(", or keeping the string as is for ")" S);  // And do a recursive call with this String if(c==46) // If the character is '.' System.out.println( // Print with trailing newline: S.peek()); // The peeked top of the stack if(c>57) // If the character is ':' or '~': S.add(c>99? // If the character is '~': new Random().nextInt() // Add a random [0,2147483647) integer to the stack : // Else (the character is ':') S.peek()); // Add the peeked top to the stack if(c<44|c==45|c==47) // If the character is '*', '+', '-', or '/': t=S.pop();u=S.pop();// Pop and set the top two values to `t` and `u` S.add(c<43? // If the character is '*': u*t // Add the product of the two values to the stack :c<44? // Else-if the character is '+': u+t // Add the sum of the two values to the stack :c<46? // Else-if the character is '-': u-t // Subtract the top two values, and add it to the stack : // Else (the character is '/'): u/t;}}} // Divide the top two values, and add it to the stack 
added 55 characters in body
Source Link
Kevin Cruijssen
  • 136.3k
  • 14
  • 155
  • 394
Loading
deleted 251 characters in body
Source Link
Kevin Cruijssen
  • 136.3k
  • 14
  • 155
  • 394
Loading
deleted 75 characters in body
Source Link
Kevin Cruijssen
  • 136.3k
  • 14
  • 155
  • 394
Loading
added 3041 characters in body
Source Link
Kevin Cruijssen
  • 136.3k
  • 14
  • 155
  • 394
Loading
Source Link
Kevin Cruijssen
  • 136.3k
  • 14
  • 155
  • 394
Loading