!@$%^&*()+/Algorithms

From Esolang
Jump to navigation Jump to search

This is horrible and I'm very sorry.

This page provides common code snippets for easy !@#$%^&*()_+ programming, inspired by Brainfuck algorithms.

x can be replaced with any literal.

Push 0

xx_+

(Actually, an ASCII 0 character is shorter but is impossible to display on the wiki.)

Comment

xx_+(Your comment goes here)+

Pop

!_++

Decrement

_^_

Multiplication

$!%$_^_(%!%+%_^_)+!_++

Only works if the stack only constitutes the multipliers. //_+(TODO: Replace this with a snippet without the restriction.)+

Divide by constant

xx_+$(_^^^^...^^^_$^$)+

Divides by n when there is n ^ in ^^^^...^^^.

Warning: If the number is not divisible by n, the code will loop infinitely. //_+(TODO: Replace this with a snippet without the restriction.)+

Stack length

!!_+!%$(%^$)%#

Only works when there are no zeroes on the stack.

Read all characters into memory

*^(  _+*^)%(_^_%)+

Works if EOF is -1.

Stores the entirety of the input as individual ASCII values onto the stack

Input a decimal number

0
_+(
+0_+$!+!!+!+++
_*)

This snippet reads a number that ends with a newline. (To end with a space or other characters, replace all newlines in the snippet.) It needs a 0 on the stack top to work properly, and it leaves an extra 0 on the top of the stack.

Parity

  _+$(_^_$_^$)+

Turns the top of the stack to 0 if even, and 1 if odd.