Skip to main content
Commonmark migration
Source Link

JavaScript (V8),  178 172  171 bytes

Transpiles to JS. May throw either Z is not defined or x is not defined if the code attempts to do something bad.

s=>eval(s.replace(/./g,c=>`S.push(${c>'}'?'x=Math.random()*1e5|0':c>'9'?'x':c=='.'?');print(x':c<')'?');while(x){(0':c<'*'?')}(0':`1/(x${c}=S.pop(S.pop()))?x:Z`});`,S=[])) 

Try the 1st program online!

Try the 2nd program online!

Try the 3rd program online!

###How?

How?

Each instruction is transpiled to S.push(, followed by a specific pattern, followed by );.

We have to test the division by zero explicitly because JS doesn't give the slightest damn about such a harmless operation. :-p

 char. | JS code -------+-------------------------------------- ~ | S.push( x=Math.random()*1e5|0 ); + | S.push( 1/(x+=S.pop(S.pop()))?x:Z ); - | S.push( 1/(x-=S.pop(S.pop()))?x:Z ); * | S.push( 1/(x*=S.pop(S.pop()))?x:Z ); / | S.push( 1/(x/=S.pop(S.pop()))?x:Z ); : | S.push( x ); . | S.push( );print(x ); ( | S.push( );while(x){(0 ); ) | S.push( )}(0 ); 

JavaScript (V8),  178 172  171 bytes

Transpiles to JS. May throw either Z is not defined or x is not defined if the code attempts to do something bad.

s=>eval(s.replace(/./g,c=>`S.push(${c>'}'?'x=Math.random()*1e5|0':c>'9'?'x':c=='.'?');print(x':c<')'?');while(x){(0':c<'*'?')}(0':`1/(x${c}=S.pop(S.pop()))?x:Z`});`,S=[])) 

Try the 1st program online!

Try the 2nd program online!

Try the 3rd program online!

###How?

Each instruction is transpiled to S.push(, followed by a specific pattern, followed by );.

We have to test the division by zero explicitly because JS doesn't give the slightest damn about such a harmless operation. :-p

 char. | JS code -------+-------------------------------------- ~ | S.push( x=Math.random()*1e5|0 ); + | S.push( 1/(x+=S.pop(S.pop()))?x:Z ); - | S.push( 1/(x-=S.pop(S.pop()))?x:Z ); * | S.push( 1/(x*=S.pop(S.pop()))?x:Z ); / | S.push( 1/(x/=S.pop(S.pop()))?x:Z ); : | S.push( x ); . | S.push( );print(x ); ( | S.push( );while(x){(0 ); ) | S.push( )}(0 ); 

JavaScript (V8),  178 172  171 bytes

Transpiles to JS. May throw either Z is not defined or x is not defined if the code attempts to do something bad.

s=>eval(s.replace(/./g,c=>`S.push(${c>'}'?'x=Math.random()*1e5|0':c>'9'?'x':c=='.'?');print(x':c<')'?');while(x){(0':c<'*'?')}(0':`1/(x${c}=S.pop(S.pop()))?x:Z`});`,S=[])) 

Try the 1st program online!

Try the 2nd program online!

Try the 3rd program online!

How?

Each instruction is transpiled to S.push(, followed by a specific pattern, followed by );.

We have to test the division by zero explicitly because JS doesn't give the slightest damn about such a harmless operation. :-p

 char. | JS code -------+-------------------------------------- ~ | S.push( x=Math.random()*1e5|0 ); + | S.push( 1/(x+=S.pop(S.pop()))?x:Z ); - | S.push( 1/(x-=S.pop(S.pop()))?x:Z ); * | S.push( 1/(x*=S.pop(S.pop()))?x:Z ); / | S.push( 1/(x/=S.pop(S.pop()))?x:Z ); : | S.push( x ); . | S.push( );print(x ); ( | S.push( );while(x){(0 ); ) | S.push( )}(0 ); 
saved 1 byte
Source Link
Arnauld
  • 205.5k
  • 21
  • 187
  • 670

JavaScript (V8),  178 172  172171 bytes

Transpiles to JS. May throw either Z is not defined or x is not defined if the code attempts to do something bad.

s=>eval(s.replace(/./g,c=>`S.push(${c>'}'?'x=Math.random()*1e5|0':c>'9'?'x':c=='.'?');print(x':c<')'?');while(x){(0':c<'*'?');}(0':`1/(x${c}=S.pop(S.pop()))?x:Z`});`,S=[])) 

Try the 1st program online!Try the 1st program online!

Try the 2nd program online!Try the 2nd program online!

Try the 3rd program online!Try the 3rd program online!

###How?

Each instruction is transpiled to S.push(, followed by a specific pattern, followed by );.

We have to test the division by zero explicitly because JS doesn't give the slightest damn about such a harmless operation. :-p

 char. | JS code -------+-------------------------------------- ~ | S.push( x=Math.random()*1e5|0 ); + | S.push( 1/(x+=S.pop(S.pop()))?x:Z ); - | S.push( 1/(x-=S.pop(S.pop()))?x:Z ); * | S.push( 1/(x*=S.pop(S.pop()))?x:Z ); / | S.push( 1/(x/=S.pop(S.pop()))?x:Z ); : | S.push( x ); . | S.push( );print(x ); ( | S.push( );while(x){(0 ); ) | S.push( );}(0 ); 

JavaScript (V8),  178  172 bytes

Transpiles to JS. May throw either Z is not defined or x is not defined if the code attempts to do something bad.

s=>eval(s.replace(/./g,c=>`S.push(${c>'}'?'x=Math.random()*1e5|0':c>'9'?'x':c=='.'?');print(x':c<')'?');while(x){(0':c<'*'?');}(0':`1/(x${c}=S.pop(S.pop()))?x:Z`});`,S=[])) 

Try the 1st program online!

Try the 2nd program online!

Try the 3rd program online!

###How?

Each instruction is transpiled to S.push(, followed by a specific pattern, followed by );.

We have to test the division by zero explicitly because JS doesn't give the slightest damn about such a harmless operation. :-p

 char. | JS code -------+-------------------------------------- ~ | S.push( x=Math.random()*1e5|0 ); + | S.push( 1/(x+=S.pop(S.pop()))?x:Z ); - | S.push( 1/(x-=S.pop(S.pop()))?x:Z ); * | S.push( 1/(x*=S.pop(S.pop()))?x:Z ); / | S.push( 1/(x/=S.pop(S.pop()))?x:Z ); : | S.push( x ); . | S.push( );print(x ); ( | S.push( );while(x){(0 ); ) | S.push( );}(0 ); 

JavaScript (V8),  178 172  171 bytes

Transpiles to JS. May throw either Z is not defined or x is not defined if the code attempts to do something bad.

s=>eval(s.replace(/./g,c=>`S.push(${c>'}'?'x=Math.random()*1e5|0':c>'9'?'x':c=='.'?');print(x':c<')'?');while(x){(0':c<'*'?')}(0':`1/(x${c}=S.pop(S.pop()))?x:Z`});`,S=[])) 

Try the 1st program online!

Try the 2nd program online!

Try the 3rd program online!

###How?

Each instruction is transpiled to S.push(, followed by a specific pattern, followed by );.

We have to test the division by zero explicitly because JS doesn't give the slightest damn about such a harmless operation. :-p

 char. | JS code -------+-------------------------------------- ~ | S.push( x=Math.random()*1e5|0 ); + | S.push( 1/(x+=S.pop(S.pop()))?x:Z ); - | S.push( 1/(x-=S.pop(S.pop()))?x:Z ); * | S.push( 1/(x*=S.pop(S.pop()))?x:Z ); / | S.push( 1/(x/=S.pop(S.pop()))?x:Z ); : | S.push( x ); . | S.push( );print(x ); ( | S.push( );while(x){(0 ); ) | S.push( )}(0 ); 
minor update
Source Link
Arnauld
  • 205.5k
  • 21
  • 187
  • 670

JavaScript (V8),  178  172 bytes

Transpiles to JS. ThrowsMay throw either Z is not defined in case of division by zeroor x is not defined if the code attempts to do something bad.

s=>eval(s.replace(/./g,c=>`S.push(${c>'}'?'x=Math.random()*1e5|0':c>'9'?'x':c=='.'?');print(x':c<')'?');while(x){(0':c<'*'?');}(0':`1/(x${c}=S.pop(S.pop()))?x:Z`});`,S=[])) 

Try the 1st program online!

Try the 2nd program online!

Try the 3rd program online!

###How?

Each instruction is transpiled to S.push(, followed by a specific pattern, followed by );.

We have to test the division by zero explicitly because JS doesn't give the slightest damn about such a harmless operation. :-p

 char. | JS code -------+-------------------------------------- ~ | S.push( x=Math.random()*1e5|0 ); + | S.push( 1/(x+=S.pop(S.pop()))?x:Z ); - | S.push( 1/(x-=S.pop(S.pop()))?x:Z ); * | S.push( 1/(x*=S.pop(S.pop()))?x:Z ); / | S.push( 1/(x/=S.pop(S.pop()))?x:Z ); : | S.push( x ); . | S.push( );print(x ); ( | S.push( );while(x){(0 ); ) | S.push( );}(0 ); 

JavaScript (V8),  178  172 bytes

Transpiles to JS. Throws Z is not defined in case of division by zero.

s=>eval(s.replace(/./g,c=>`S.push(${c>'}'?'x=Math.random()*1e5|0':c>'9'?'x':c=='.'?');print(x':c<')'?');while(x){(0':c<'*'?');}(0':`1/(x${c}=S.pop(S.pop()))?x:Z`});`,S=[])) 

Try the 1st program online!

Try the 2nd program online!

Try the 3rd program online!

###How?

Each instruction is transpiled to S.push(, followed by a specific pattern, followed by );.

 char. | JS code -------+-------------------------------------- ~ | S.push( x=Math.random()*1e5|0 ); + | S.push( 1/(x+=S.pop(S.pop()))?x:Z ); - | S.push( 1/(x-=S.pop(S.pop()))?x:Z ); * | S.push( 1/(x*=S.pop(S.pop()))?x:Z ); / | S.push( 1/(x/=S.pop(S.pop()))?x:Z ); : | S.push( x ); . | S.push( );print(x ); ( | S.push( );while(x){(0 ); ) | S.push( );}(0 ); 

JavaScript (V8),  178  172 bytes

Transpiles to JS. May throw either Z is not defined or x is not defined if the code attempts to do something bad.

s=>eval(s.replace(/./g,c=>`S.push(${c>'}'?'x=Math.random()*1e5|0':c>'9'?'x':c=='.'?');print(x':c<')'?');while(x){(0':c<'*'?');}(0':`1/(x${c}=S.pop(S.pop()))?x:Z`});`,S=[])) 

Try the 1st program online!

Try the 2nd program online!

Try the 3rd program online!

###How?

Each instruction is transpiled to S.push(, followed by a specific pattern, followed by );.

We have to test the division by zero explicitly because JS doesn't give the slightest damn about such a harmless operation. :-p

 char. | JS code -------+-------------------------------------- ~ | S.push( x=Math.random()*1e5|0 ); + | S.push( 1/(x+=S.pop(S.pop()))?x:Z ); - | S.push( 1/(x-=S.pop(S.pop()))?x:Z ); * | S.push( 1/(x*=S.pop(S.pop()))?x:Z ); / | S.push( 1/(x/=S.pop(S.pop()))?x:Z ); : | S.push( x ); . | S.push( );print(x ); ( | S.push( );while(x){(0 ); ) | S.push( );}(0 ); 
fixed the while loop and saved 6 bytes
Source Link
Arnauld
  • 205.5k
  • 21
  • 187
  • 670
Loading
added an explanation
Source Link
Arnauld
  • 205.5k
  • 21
  • 187
  • 670
Loading
Source Link
Arnauld
  • 205.5k
  • 21
  • 187
  • 670
Loading