Increment

From Esolang
Jump to navigation Jump to search

Commands

Character What it does
Any character except the ones listed below Increment the accumulator by the character's ASCII value.
& Print the accumulator, and end the program.
[ Turn off the user's computer.

Examples

Discover the answer to life, the universe, and everything

*&

Shut down the user's computer

[

Partial Implementation

Lua Implementation

function Increment(str)
	local acc = 0
	for char in str:gmatch(".") do
		if char == "&" then
			print(acc)
			return
		elseif char == "[" then
			--Works in Microsoft Windows
			os.execute("shutdown -s -f")
			return
		else
			acc = acc + string.byte(char)
		end
	end
end

For UNIX-like operating systems:

function Increment(str)
	local acc = 0
	for char in str:gmatch(".") do
		if char == "&" then
			print(acc)
			return
		elseif char == "[" then
			--Works in UNIX-like operating systems 
			os.execute("poweroff")
			return
		else
			acc = acc + string.byte(char)
		end
	end
end

Python Implementation

import os
code=input()
x=0
for i in code:
    if '&[' not in i:
        x+=ord(i)
    if i=='&':
        print(x)
    if i=='[':
        os.system('shutdown -p -f')