Skip to main content
deleted 215 characters in body
Source Link
Martin Ender
  • 198.2k
  • 67
  • 455
  • 999

CJam, 1717 16 bytes

{`"_~"+q~{W%}&`"_~"+Wq~g#%}_~ 

Test it here.Test it here.

A fairly straight-forward modification of the standard quine. This also worksOther solutions for the same byte count17 bytes:

{`"_~"+q~{W%}&}_~ {`"_~"+q~!2*(%}_~ 

If I can assume that the input is only 0 or 1 (as a stand-in for a boolean, which there is no dedicated type for in CJam), I get 15 by omitting the g:

{`"_~"+Wq~#%}_~ 

Explanation

{`"_~"+ e# Standard generalised quine framework. Leaves the source code on the stack.  q~  e# Read and evaluate input. {W%}& e#W If it's truthy, reverse the string. }_~ 

And the other one:

{`"_~"+ e# Standard generalised quine framework. Leaves the source code onPush thea stack-1.  q~ e# Read and evaluate input. !g e# Logical NOTsignum, turning 0truthy values into 1, and everything else into(leaving 0 unchanged). 2*(# e# Double, decrement,e# givingPower. 1-1^0 for== falsy1, input-1^1 and== -1 for truthy input. % e# Select every Nth element: a no-op for 1 and reverses the string for -1. }_~ 

CJam, 17 bytes

{`"_~"+q~{W%}&}_~ 

Test it here.

A fairly straight-forward modification of the standard quine. This also works for the same byte count:

{`"_~"+q~!2*(%}_~ 

Explanation

{`"_~"+ e# Standard generalised quine framework. Leaves the source code on the stack.  q~  e# Read and evaluate input. {W%}& e# If it's truthy, reverse the string. }_~ 

And the other one:

{`"_~"+ e# Standard generalised quine framework. Leaves the source code on the stack.  q~ e# Read and evaluate input. ! e# Logical NOT, turning 0 into 1, and everything else into 0. 2*( e# Double, decrement, giving 1 for falsy input and -1 for truthy input. % e# Select every Nth element: a no-op for 1 and reverses the string for -1. }_~ 

CJam, 17 16 bytes

{`"_~"+Wq~g#%}_~ 

Test it here.

A fairly straight-forward modification of the standard quine. Other solutions for 17 bytes:

{`"_~"+q~{W%}&}_~ {`"_~"+q~!2*(%}_~ 

If I can assume that the input is only 0 or 1 (as a stand-in for a boolean, which there is no dedicated type for in CJam), I get 15 by omitting the g:

{`"_~"+Wq~#%}_~ 

Explanation

{`"_~"+ e# Standard generalised quine framework. Leaves the source code on the stack. W e# Push a -1. q~ e# Read and evaluate input. g e# signum, turning truthy values into 1 (leaving 0 unchanged). # e# Power. -1^0 == 1, -1^1 == -1. % e# Select every Nth element: a no-op for 1 and reverses the string for -1. }_~ 
added 219 characters in body
Source Link
Martin Ender
  • 198.2k
  • 67
  • 455
  • 999

CJam, 17 bytes

CJam, 17 bytes

{`"_~"+q~{W%}&}_~ 

Test it here.

A fairly straight-forward modification of the standard quine. This also works for the same byte count:

{`"_~"+q~!2*(%}_~ 

Explanation

{`"_~"+ e# Standard generalised quine framework. Leaves the source code on the stack. q~ e# Read and evaluate input. {W%}& e# If it's truthy, reverse the string. }_~ 

And the other one:

{`"_~"+ e# Standard generalised quine framework. Leaves the source code on the stack. q~ e# Read and evaluate input. ! e# Logical NOT, turning 0 into 1, and everything else into 0. 2*( e# Double, decrement, giving 1 for falsy input and -1 for truthy input. % e# Select every Nth element: a no-op for 1 and reverses the string for -1. }_~ 

CJam, 17 bytes

{`"_~"+q~{W%}&}_~ 

Test it here.

A fairly straight-forward modification of the standard quine. This also works for the same byte count:

{`"_~"+q~!2*(%}_~ 

CJam, 17 bytes

{`"_~"+q~{W%}&}_~ 

Test it here.

A fairly straight-forward modification of the standard quine. This also works for the same byte count:

{`"_~"+q~!2*(%}_~ 

Explanation

{`"_~"+ e# Standard generalised quine framework. Leaves the source code on the stack. q~ e# Read and evaluate input. {W%}& e# If it's truthy, reverse the string. }_~ 

And the other one:

{`"_~"+ e# Standard generalised quine framework. Leaves the source code on the stack. q~ e# Read and evaluate input. ! e# Logical NOT, turning 0 into 1, and everything else into 0. 2*( e# Double, decrement, giving 1 for falsy input and -1 for truthy input. % e# Select every Nth element: a no-op for 1 and reverses the string for -1. }_~ 
Source Link
Martin Ender
  • 198.2k
  • 67
  • 455
  • 999

CJam, 17 bytes

{`"_~"+q~{W%}&}_~ 

Test it here.

A fairly straight-forward modification of the standard quine. This also works for the same byte count:

{`"_~"+q~!2*(%}_~