Skip to main content
added 1 character in body
Source Link
Sp3000
  • 61.9k
  • 13
  • 115
  • 287
~:                     Read input char a and dup
  ~                    Read input char b (-1 on EOF)
   :0`!                Push 1 if b ><= 0, 0 otherwise
       #@_             Halt if b <= 0 (i.e. EOF)
          -            Subtract to check whether a != b
           >#,_$       Output a if so
~:                     Read input char a and dup
  ~                    Read input char b (-1 on EOF)
   :0`!                Push 1 if b > 0, 0 otherwise
       #@_             Halt if b <= 0 (i.e. EOF)
          -            Subtract to check whether a != b
           >#,_$       Output a if so
~:                     Read input char a and dup
  ~                    Read input char b (-1 on EOF)
   :0`!                Push 1 if b <= 0, 0 otherwise
       #@_             Halt if b <= 0 (i.e. EOF)
          -            Subtract to check whether a != b
           >#,_$       Output a if so
Post Undeleted by Sp3000
Post Deleted by Sp3000
added 494 characters in body
Source Link
Sp3000
  • 61.9k
  • 13
  • 115
  • 287

Befunge 93, 1916 bytes

~:~:0`!#@_-!!*>:#>#,__$
~:                     Read input char a and dup
  ~                    Read input char b (-1 on EOF)
   :0`!                Push 1 if b > 0, 0 otherwise
       #@_             Halt if b <= 0 (i.e. EOF)
          -!!          Check  Subtract to check whether a != b
           >#,_$    *   Output a if so

The last part makes use of the fact that popping from an empty Befunge-93 stack yields 0.

If a != b, we perform

>         Multiply a by the result         Move rightward
#              >        Bridge:# skip next
_                      Horizontal if - go right if 0, else left. But a != b, so we go left
,                      Output a
#                      Bridge: skip next
-                      Subtract (0 - 0 = 0)
_                      If: ago >right since 0 is popped
>#                     Go right and skip next
_                      If: go right since 0 is popped
$                      Pop top of stack, outputstack a.is now empty

The last part makes use of the fact that popping from an empty Befunge-93 stack yields 0Otherwise, which means that if a is positive we go left at _ and execute , == b for output the first time, but on the second pass we go right at _ since 0 if popped from the stack.perform:

>                      Move rightward
#                      Bridge: skip next
_                      If: go right since a == b (i.e. a-b is 0)
$                      Pop top of stack and discard, keeping stack empty

Befunge 93, 19 bytes

~:~:0`!#@_-!!*>:#,_
~:                     Read input char and dup
  ~                    Read input char (-1 on EOF)
   :0`!                Push 1 if b > 0, 0 otherwise
       #@_             Halt if b <= 0 (i.e. EOF)
          -!!          Check whether a != b
             *         Multiply a by the result
              >:#,_    If a > 0, output a.

The last part makes use of the fact that popping from an empty Befunge-93 stack yields 0, which means that if a is positive we go left at _ and execute , for output the first time, but on the second pass we go right at _ since 0 if popped from the stack.

Befunge 93, 16 bytes

~:~:0`!#@_->#,_$
~:                     Read input char a and dup
  ~                    Read input char b (-1 on EOF)
   :0`!                Push 1 if b > 0, 0 otherwise
       #@_             Halt if b <= 0 (i.e. EOF)
          -            Subtract to check whether a != b
           >#,_$       Output a if so

The last part makes use of the fact that popping from an empty Befunge-93 stack yields 0.

If a != b, we perform

>                      Move rightward
#                      Bridge: skip next
_                      Horizontal if - go right if 0, else left. But a != b, so we go left
,                      Output a
#                      Bridge: skip next
-                      Subtract (0 - 0 = 0)
_                      If: go right since 0 is popped
>#                     Go right and skip next
_                      If: go right since 0 is popped
$                      Pop top of stack, stack is now empty

Otherwise, if a == b, we perform:

>                      Move rightward
#                      Bridge: skip next
_                      If: go right since a == b (i.e. a-b is 0)
$                      Pop top of stack and discard, keeping stack empty
Source Link
Sp3000
  • 61.9k
  • 13
  • 115
  • 287

Befunge 93, 19 bytes

~:~:0`!#@_-!!*>:#,_

A one-liner for compactness. Tested using this online interpreter.

~:                     Read input char and dup
  ~                    Read input char (-1 on EOF)
   :0`!                Push 1 if b > 0, 0 otherwise
       #@_             Halt if b <= 0 (i.e. EOF)
          -!!          Check whether a != b
             *         Multiply a by the result
              >:#,_    If a > 0, output a.

The last part makes use of the fact that popping from an empty Befunge-93 stack yields 0, which means that if a is positive we go left at _ and execute , for output the first time, but on the second pass we go right at _ since 0 if popped from the stack.