1+

From Esolang
Jump to navigation Jump to search

1+, initially conceived by Jeremy Tan (User:Parcly Taxel) in 2012 (but with the final specification and interpreter written in 2014), is an esoteric programming language where 1 is the only literal. It is mostly inspired by FALSE, Piet and Wang's B-machine.

Commands and syntax

1+ operates only on an initially empty stack of non-negative integers (negative integers cannot be represented, and indeed ensure that the jumps work; see below). Twelve of the language's thirteen commands do something to the stack:

  • 1 pushes the number 1 onto the stack. This is the only literal; all other numbers are constructed with operators like INTERCAL does. Unlike INTERCAL, however, this restriction is derived from the concept of integer complexity, the minimum number of 1's needed to make a number n with only additions and multiplications.
  • + pops the top two numbers and pushes their sum.
  • * is the same as + but pushes the product instead.
  • " duplicates the top number.
  • / rotates the stack upward, sending the top number to the bottom.
  • \ rotates the stack downward, sending the bottom number to the top.
  • ^ swaps the top two numbers.
  • < pops the top two numbers and pushes 0 if the top number is less than the second-top number, 1 otherwise. This is the only conditional in 1+.
  • . and , read input as a number or Unicode character respectively and push that on.
  • : and ; are corresponding commands for output, popping the top value and printing it as a number or Unicode character respectively.
  • # is the only control structure in 1+: it pops the top value n and sends program flow to immediately after the nth # in the current line of execution (where numbering starts from 0).

Subroutines are defined as (name|symbols) and are called as (name); they can call other subroutines or themselves (thereby implementing recursion) and the point where they are defined causes their execution too. They are separate lines of execution, so the numbering of #'s in them starts from 0. They are positioned within the overall program such that they never depend on a subroutine that is defined later on.

Comments are placed in square brackets ([ ]).

Undocumented instruction

There's one undocumented instruction in the original interpreter, d, that prints the whole stack in an obscured format.

Examples

Hello world program

11+"""1+"****"; [H]
111++""**1+(D|/"\"/^\)1++; [e]
(D)11+""**++"";; [ll]
111+++"; [o]
/"11+"""***+; [,]
"11+"*+; [ ]
"111++"/*\+; [W]
\"; [o]
111+++; [r]
(D)11+""**++; [l]
+; [d]
11+""""****1+; [!]
111++"*1+; [\n]


Infinite Loop

1##1#

Cat Program (EOF returns 0)

1##,";1+1<1+#

Fibonacci sequence

111##":"\+1#

Factorial

.111##^"/*\1+\<1+#

Truth-Machine

.1##":"1+1<1+#

Infinite Looping Counter

11##":1+1#

Nested Loop Example

11##111+#":1+"\"/<1+1<11++#"<*1+1#

The above code outputs A002260 using a nested loop.

Quine

Here's a quine in 1+ from the Code Golf Stack Exchange user dzaima, with some basic concepts and snippets from User:TwilightSparkle, Code Golf Stack Exchange user wizzwizz4, User:A, and Code Golf Stack Exchange user user202729.

11+1+1+1+1+1+11+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+11+1+1+1+1+1+1+1+1+1+1+1+1+1+1+11+1+1+1+1+1+1+1+1+1+1+1+1+1+1+11+1+1+1+1+1+1+1+1+11+1+1+1+1+1+1+1+1+1+1+1+1+1+1+11+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+11+1+1+1+1+1+1+11+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+11+1+1+1+1+1+11+1+1+1+1+1+1+1+1+1+1+1+1+1+1+11+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+11+1+1+1+1+1+1+1+1+1+1+1+1+1+1+11+1+1+1+1+1+1+1+1+1+1+1+1+1+1+11+1+1+1+1+1+1+1+1+11+1+1+1+1+1+1+1+1+1+1+1+1+1+1+11+1+1+1+1+1+1+1+1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+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+11+11+1+1+1+1+1+1+11+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+11+1+1+1+1+1+11+1+1+1+11+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+11+1+1+1+1+1+11+1+1+1+1+1+1+11+11+1+1+1+1+1+1+1+1+1+1+1+1+1+1+11+1+1+1+1+1+1+1+1+1+1+1+1+1+1+11+1+1+1+1+1+1+1+1+111+1+1+1+1+1+1+1+111+1+1+1+1+1+1+1+111+1+1+1+1+1+1+1+1+11+1+1+1+1+1+1+1+1+11+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+11+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+111+1+1+1+1+1+1+1+1+1+1+1+1+1+1+11+1+1+1+1+1+1+1+1+11+1+1+1+1+1+1+1+1+1+1+1+1+1+1+11+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+11+11+1+1+1+1+1+1+(|11+1<)\(1|11+1+"+1+"*;)($|1+11#(1)11+1+"+"1+*1+;1#1+"//"\^\<11+*#()*+\)(%|()#(1)($)"1+1<#)\(&|()#11+"*"*"++;\"1+1<#) 

Here's a much shorter quine by Code Golf Stack Exchange user Jo King, where he uses his own design.

 (|11+"*"+"1+\1+/)("|1/()11+^)(2|\""++1+/()""+^)++<+/(#|\##"\+;1#()\^\1#)+<+()()(")(2)(2)()()(")()(2)(")(2)()(")()(")()()()(2)(")()()()(2)()()(2)()(")()()()()(2)(2)(")()()()(2)()()(2)()(")(2)()(")(2)(")()(")()()()(2)(")(2)(2)()(")()(2)(")()()()(2)()()(2)()(")(")()(")()(")()()()(2)()()(2)()(")(2)()(2)()(2)(")()(")(2)(")()()(2)()(")()(2)(")(2)(2)()()(")()(2)(")()(2)(")(2)()(")()()()()(2)(2)(")()(2)(")(")(")(2)()(")(2)(")()()(2)()(")()(2)(")()()()(2)(")()(2)(")()(2)(")(")(")()()()(2)()()(2)()(")(2)()(2)()(2)(")()()()(2)()(")(2)(")(2)()(")()()()()(2)(2)(")()(2)(")()()()(2)(")()()()(2)(")(2)()(")(2)(")()()(2)()(")()()()(2)(")(2)()(2)()(2)(")(")(2)(")(2)()(")()()(2)()(")()(2)(")()()()(2)(")()()()(2)()()(2)()(")()(2)(")()()()(2)(")(")()(2)(")(")(2)()()(")(")()(2)(")()()()(2)(")()()()(2)(")(2)()(2)()(2)(")(2)(")(2)()()(2)(")(")(#)@

Turing-Completeness

1+ is Turing-Complete as any Boolf*** program can be translated into 1+ program.

First, we need to push a single 2, which represents the seperator between the memory cells on the left of the pointer and the memory cells on the right of the pointer, and then a single 0, which is the "initial" memory cell.

Then, we will be able to translate the @,.<> operations:

Boolf***        1+
---------------------------
@               1+1<
,               .1^<
.               ":
<               /
>               \

In order to guarantee an infinite tape, the tape-extending instruction is also neccecary for 1+. This pushes a 0 onto the stack.

Boolf***        1+
---------------------------
x(extended)     11+1<

[] will be a lot more trickier, as they involves flow control. You'll have to figure out which bracket matches which bracket first. Let's say the left bracket is the Lth bracket and the right bracket is the Rth bracket. Then that pair of brackets will be translated as follows:

Boolf***        1+
---------------------------
[              "1+1<[Push R-L]*[Push L]+#
]              "1+1<[Push R-L]*[Push L]+#

It's obvious to see it's possible to push every positive number and 0, thus 1+ is Turing-Complete.

Constants

Generator for this shortest way table.

Here's the shortest known way to push a specific number (I'm too lazy to complete the table, find constants out yourself!). (See this revision to see an alternative list of constants.)

 Number    Code
 ----------------------------------------------
  0 11+1<
  1 1
  2 11+
  3 111++
  4 11+"*
  5 111+"*+
  6 11+""*+
  7 111+""*++
  8 11+""**
  9 11"++"*
 10 11+"""**+
 11 11+"1+"*+
 12 11+"""*+*
 13 11"+"""*+*+
 14 11+""""*+*+
 15 11"++"""*++
 16 11+"*"*
 17 11"+"*"*+
 18 11+""*"*+
 19 11"+""*"*++
 20 11+"*""*+
 21 11"+"*""*++
 22 11+""*""*++
 23 11"+""*""*+++
 24 11+""""*+**
 25 11"+"*+"*
 26 11""+"*+"*+
 27 11"++""**
 28 11""++""**+
 29 11+"1+""**+
 30 11"++"""**+
 31 11""++"""**++
 32 11+""*"**
 33 11"+""*"**+
 34 11+"""*"**+
 35 11"+"""*"**++
 36 11+""*+"*
 37 11"+""*+"*+
 38 11+"""*+"*+
 39 11"++""+"*+
 40 11+""*""*+*
 41 11"+""*""*+*+
 42 11+""*+""*+
 43 11"+""*+""*++
 44 11+"""*""*++*
 45 11"++""""*++*
 46 11+""""*""*++*+
 47 11+"1+""""*++*+
 48 11+"*"*""++
 49 11"+""*++"*
 50 11"+"*+"*"+
 51 11""+"*+""+*+
 52 11+"*""*""+++
 53 11"+"*""""++*++
 54 11"++""**"+
 55 11""++"""+**+
 56 11"+""*++""*+
 57 11"++"""**"++
 58 11+""*"1+"*+*
 59 11"+""1+""**+*+
 60 11+"*""*+""++
 61 11"+"*""*+""+++
 62 11+""*""*+""+++
 63 11"++""""+*+*
 64 11+""**"*
 65 11"+"*""**+
 66 11+""*""**+
 67 11"+""*""**++
 68 11+"*"""**+
 69 11"+"*"""**++
 70 11+""*"""**++
 71 11"+""*"""**+++
 72 11+""**""*+
 73 11"+"""*+"**+
 74 11+"""**""*++
 75 11"+"*+"""++*
 76 11+""""*+"*+*
 77 11"+""""*+"*+*+
 78 11+""*+""*"++
 79 11"+""*+"""+*++
 80 11+"*"""*+*
 81 11"++"*"*
 82 11""++"*"*+
 83 11+"1+"*"*+
 84 11"++""*"*+
 85 11""++""*"*++
 86 11+"1+""*"*++
 87 11"++"""*"*++
 88 11+""""*""*++**
 89 11+""**"1+"*+
 90 11"++"*""*+
 91 11""++"*""*++
 92 11+"1+"*""*++
 93 11"++""*""*++
 94 11""++""*""*+++
 95 11+"1+""*""*+++
 96 11+""*"**""++
 97 11"+""*"""++**+
 98 11"+""*++""+*
 99 11"++"*"""*++
100 11+"""**+"*
101 11"+"""**+"*+
102 11+""""**+"*+
103 11"++""*1+"*+
104 11+"*""1+"**+
105 11"+"*+""+"*+
106 11""+"*+""+"*++
107 11+""*1+""+"*++
108 11"++""+"**
109 11""++""+"**+
110 11+"""**+""*+
111 11"++"""+"**+
112 11+"*"""""*+++*
113 11+"1+"""+"**++
114 11"++""""+"**++
115 11"+"*+""+""*++
116 11+"*""1+"*+*
117 11"++"""+"*+*
118 11""++"""+"*+*+
119 11+"1+"""+"*+*+
120 11+"*"1+""*+*
121 11+"1+"*+"*
122 11"+"1+"*+"*+
123 11+""1+"*+"*+
124 11+"*""1+""*+*+
125 11"+"*+""**
126 11""+"*+""**+
127 11+""*1+""**+
128 11+""*""***
129 11"+""*""***+
130 11+"""*""***+
131 11"+"""*""***++
132 11+"""*""**+*
133 11"+"""*""**+*+
134 11+"""""**"*+*+
135 11"++"""""*++**
136 11+""*"""**+*
137 11"+""*"""**+*+
138 11+"""*"""**+*+
139 11"+"""*"""**+*++
140 11+"""*"""**++*
141 11"+"""*"""**++*+
142 11+""""*"""**++*+
143 11+"1+"*+"""*++
144 11+"""*+*"*
145 11"+"""*+*"*+
146 11+""""*+*"*+
147 11"++"""*+"*+
148 11+"*"""++"*+
149 11"+"*"""++"*++
150 11"+"*+"""*+*
151 11""+"*+"""*+*+
152 11+"""""*+"*+**
153 11"++""+""+"*++
154 11+"*"1+"""*+*+
155 11"+"*+""""*+*+
156 11+"""*+*""*+
157 11"+"""*+*""*++
158 11+""""*+*""*++
159 11"++"""*+""*++
160 11+""*"""*+**
161 11"+""*"""*+**+
162 11"++"*"*"+
163 11""++"*""+*+
164 11""++"*"*+"+
165 11"++""*""+*+
166 11+""1+"*"*+*
167 11"+""1+"*"*+*+
168 11"++""*"*+"+
169 11"+"""*+*+"*
170 11""+"""*+*+"*+
171 11"++"*"""+*+
172 11""++"*""*"+++
173 11+"1+"*""*"+++
174 11"++""*"""+*++
175 11"+"*+""""*++*
176 11+"*""""*+"++*
177 11"+"*""""*+"++*+
178 11+"""**"1+"*+*
179 11"+"""**"1+"*+*+
180 11"++"*""*+"+
181 11""++"*""*+"++
182 11"+"""*+*+""*+
183 11"++""*""*+"++
184 11+""1+"*""*++*
185 11"+"*+""1+"**+
186 11"++""*""*++"+
187 11""++""*""*++"++
188 11""++""*""*+++"+
189 11"++""""*"++**
190 11""++"""""+*+**+
191 11+"1+""""*"++**+
192 11+""**"*""++
193 11"+"*""""++**+
194 11+""*""""++**+
195 11"+"*""**+""++
196 11+""""*+*+"*
197 11"+""""*+*+"*+
198 11+"""""*+*+"*+
199 11"++""1++"+"*+
200 11+""""**+"**
201 11"+""""**+"**+
202 11+"""""**+"**+
203 11"+""*++""+"*+
204 11+"""""**+"*+*
205 11"+"*+""+""+*+
206 11"++""*1+"*+"+
207 11"+"*"""**++""++
208 11+"*"""""++*+*
209 11"++"*"1+""+*+
210 11+"""**+""*"++
211 11"+"""**+"""+*++
212 11+""""**+"""+*++
213 11"++""1+"""**++*
214 11+"""*1+""+"*++*
215 11"+"*+""+"""+*++
216 11+""*+""**
217 11"+""*+""**+
218 11+"""*+""**+
219 11"++""+""**+
220 11+""""**+""*+*
221 11"+"*+"1+""**+
222 11+""*+"""**+
223 11"+""*+"""**++
224 11+"""*+"""**++
225 11"++"""*++"*
226 11""++"""*++"*+
227 11+""*1+""++"*+
228 11+""*+""""**++
229 11+"*"1+""++"*+
230 11"+"*+"""++"*+
231 11""+"*+"""++"*++
232 11+""*""1+"*+**
233 11"+""*""1+"*+**+
234 11"++"""+"*+"+*
235 11""++""+"""+*+*+
236 11""++"""+"*+*+"+
237 11"++"""+"""+*+*+
238 11+""1+"""+"*+*+*
239 11+""""*+*+"1+"*+
240 11+"*"""*+""++*
241 11"+"*"""*+""++*+
242 11+""1+"*+"**
243 11"++""*"**
244 11""++""*"**+
245 11+"1+""*"**+
246 11"++"""*"**+
247 11""++"""*"**++
248 11+"1+"""*"**++
249 11"++""""*"**++
250 11"+"*+""*"+*
251 11""+"*+""**"++
252 11"++"""*"*+*
253 11""++"""*"*+*+
254 11+"""*+"""*+*+
255 11"++""""*"*+*+
256 11+"*"*"*
 257 11+"+"*"*1+
 258 11+""+"*"*+
 260 11+"+""*"*+
 272 11+"+"*"1+*
 289 111+"+"*+"*
 324 111++"*"+"*
 400 11+"+"1+*"*
 512 11+"+"*"*"+
 625 11+"1++"*"*
 729 111++""**"*
 1024 11+"+"*"+"*
 1296 11+"1+*"*"*
 4096 11+"+"+"*"*
 6561 111++"*"*"*
 65536 11+"+"*"*"*

See Also

Online Interpreters

Code must be written in the 'Input' box.

External resources