From Esolang
Jump to: navigation, search

Heh, cool. I once made something like this, but quickly scapped it. Now I just have to write an Unary interpreter or something. XD Hmm. Apparently hello world is 0x2924924962924922924924914914000F94A15124925224A14A00924924924928624A36DB71B6DB6E150C 0's.

YET ANOTHER edit here. I just made a brainfuck-to-unary converter in Thue. Please notify me of any bugs blah blah etc. EDIT: You guessed it, unary-to-brainfuck converter in Thue. --BodyTag 18:25, 11 Sep 2005 (GMT)

Great, now how to run it without running out of memory :) --Aardwolf 20:46, 11 Sep 2005 (GMT)
Well there's the obvious approach. Make shorter programs. :P --BodyTag 21:01, 11 Sep 2005 (GMT)

One character language

Hey, this finally gave me the idea how to create a language that uses only one character! Yihaaaaa! I've been so stupid for not seeing it before.. --User:Keymaker

But this language has two symbols: 0 and EOF. The fact that it uses one character is merely a technical detail. --Graue 21:27, 11 Sep 2005 (GMT)
Oh please.. :) Would it be necessary to count in the EOF for some reason when making one character language? --User:Keymaker
Surely EOF is meta-data, and not part of the program data itself? --Safalra 13:51, 20 Oct 2005 (GMT)
Absolutely not; how else can an implementation make any sense of how to run the program, other than by looking for the EOF symbol? --Graue 14:26, 20 Oct 2005 (GMT)
Yeah, EOF is part of the program data, but this would count not only for Unary but also for all other languages. Then BF has not 8 but 9 symbols, since when the end of BF code is reached, it is interpreted as finish program. This is then also something to be considered in the BF minimization page. --Aardwolf 14:36, 20 Oct 2005 (GMT)
Iota and Unlambda don't require EOF. --Ihope127 15:20, 20 Oct 2005 (GMT)
Use meta-data, as I said. In Javascript, use, in Java use String.length(). EOF is just a way of representing the end of a file as a character, for languages that don't provide any other way of finding the length/end of a file (or don't have an exception system, so want a call to a next() method to always return), or for programmers who know that a while(c>-1) loop runs faster than a while(!eof()) loop. --Safalra 14:56, 20 Oct 2005 (GMT)
OK, then how do you propose storing that metadata with one symbol? --Graue 15:00, 20 Oct 2005 (GMT)
It's meta-data, so it doesn't get stored as part of the program - it's an implementation detail and can be stored in any way. The program code is an abstraction - if I compress a Unary program, the compressed file may use a variety of symbols, but the Unary program it represents still contains just one symbol. Saying that EOF is part of the language is like saying a 2D language needs a end-of-row symbol as well - of course we could instead use an end-of-column symbol, or specify that the program is padded so that it's width and height are prime numbers, with its width being greater than its height. The point I'm making is that these implementation details are all meta-data, and not part of the program. --Safalra 16:38, 20 Oct 2005 (GMT)
Definitely agree with that. --User:Keymaker
EOF isn't a printable symbol in this programming language, yet in some way it seems to be semantically significant, therefore it must exist in some form. If a Unary program were to be printed on paper, the EOF would be the end of the paper, or the space where the next 0 would be, if there was a next 0 in the first place. Therefore IMO, Unary has 2 symbols. Many of you don't want to thus change the definition of Brainfuck as being a language consisting of 9 symbols, but this is probably just humans being resistant to change. We've defined it as 8 symbols for so long, why change it now..? :) Also, I just wondered.. we could construct a language implementing the same semantics, but with an infinite amount of symbols. Just let the Unary program be represented instead by a positive integer whose value is the number of zeroes. --Anonymous
If you think EOF is another symbol and that makes Brainfuck to have nine symbols, you can still use ] as the end of program symbol instead. In this case, you then do have only eight symbols. --Zzo38 21:30, 31 May 2010 (UTC)

Joke Language

Should Unary be considered a joke language, since in a way it's unique. --Aardwolf 15:00, 22 Oct 2005 (GMT)

Attempt at Python converter

I've tried to make a Brainfuck to Unary converter in Python(currently at [1] However, I'm having two problems with it. The first is that I don't know how to convert numbers from binary to unary in Python. The second is that I can't get the programs to show up right in the Unary to Brainfuck converter if I convert the number by hand.

Does anyone have a clue on how to fix this? 16:14, 1 April 2008 (UTC)

For binary to unary, start with a number at zero, then repeatedly double it if the first digit of the binary is a 0, and double it and add 1 if the first digit of the binary is a 1, going through all the digits of the binary number in order; that will give you the length of the unary output you need to produce. (You'll need to use an unbounded integer to do this, otherwise the number will overflow.)

How can a Unary Number System possibly exist?

Read above. Essentially, Unary being base 1 must include all the Whole Numbers up to but not including 1. Thus, we have a range of {0}. Now, using this system, we create an arbitrary number, say 000000 which would be (what we think) the equivalent of 6d or 00000110b. However, if we evaluate our unary number, we come to a problem: 000000 = 0*1^5 + 0*1^4 + 0*1^3 + 0*1^2 + 0*1^1 + 0*1^0 = 0 This is of course a problem, because we cannot use only 0's as we will never have a value other than 0 (being the multiplicative dead) and if we use a 1 then this turns into binary by virtue of the existence of two symbols and the fact that it includes all the whole numbers up to but not including two.

So, from the above, is Unary merely a fancy term for "tally using 0's", otherwise I cannot see a way it can possibly function. -- Hiato 11:24, 4 April 2008 (UTC)

Unary generally refers to a number system where the number of digits represents the size of the number; there is usually only one digit, but that digit is usually 1 (thus an example number would be 111111 = 1*1^5 + 1*1^4 + 1*1^3 + 1*1^2 + 1*1^1 + 1*1^0 = 6). This doesn't exactly follow the pattern used by the other number systems, though. (The base really determines the base of the exponent, rather than the digits used; think about base -2, for instance, which uses 2 digits but has -2 as the base for exponents when calculating digits.) --ais523 09:20, 5 April 2008 (UTC)

In this program we use zeros but they say unary is uaually 1's. One way to do it, is you can use any characters you want in the program, the interpreter will ignore the actual contents of the file and read only the size of the file. This will break if the file has a newline or EOF mark at the end, but the programs that do that can be fixed. In this way, you can also make sparse files in a NTFS file system that are larger than the drive can contain, and it will still work. Of course, even the file size field might not store a large enough number, but the other conversion programs are no better. --Zzo38 14:22, 5 April 2008 (UTC)

Oh, I see - thanks. So essentially Unary is just a fancy tally (as 1^n = 1, n e Q) as opposed to a "true" base n number system. Is this to say that what I put forth would be some kind of Nullary (Base 0 number system?) -- Hiato 20:27, 13 April 2008 (UTC)
Yes, pretty much. I don't blame you for being confused; the standard terminology is inconsistent and confusing. --ais523 20:32, 14 April 2008 (UTC)

Inefficient conversion to number

Instead of adding a 1 before each number when converting to binary, you could let 8 instead of 0 represent '<'.

So you get:

Brainfuck Binary
> 8 (1000)
< 1 (001)
+ 2 (010)
- 3 (011)
. 4 (100)
, 5 (101)
[ 6 (110)
] 7 (111)

Then convert the sequence of numbers as if they were written in base 8 (big endian). In other word: calculate the sum of a*8^n for each number a, where n is the position in the bf-code code counting from the right.

If the above was confusing, here is an example:

If you want to convert +>,< into Unary2 you first convert each character into a number according to above: +>,< -> {2,8,5,1} then add it together to get the number of digits: 2*8^3 + 8*8^2 + 5*8 + 1 = 1577. So +>,< in Unary2 is 1577 zeroes.

With this approach every sequence of zeros has a corresponding brainfuck code, which is not achived with normal Unary.

--Anka 20:24, 3 January 2009 (UTC)

Surely you can't use the digit 8 in base 8? Phantom Hoover 15:01, 5 January 2010 (UTC)
Yes, you cna't use the digit 8 in base 8. Instead, you could change around the order to make 0 mean the ] instruction and put the least significant numbers the first command, and the most significant numbers the last command. So, the zero will always be the last command and can be used as termination, too, in case of not inside of a loop the ] can be used to mark end of a program. And now, if you needed to add on input to the program you could do it in the same way --Zzo38 01:00, 9 January 2010 (UTC)
None of this changes the fact that using digit 8 actually works though. --Ørjan 10:39, 9 January 2010 (UTC)
It does, but it's not using base 8. Phantom Hoover 21:06, 12 January 2010 (UTC)
Well there is balanced ternary, so this might be "hyperimbalanced" octal. Actually Wikipedia calls it bijective base-k numeration. --Ørjan 23:47, 12 January 2010 (UTC)

The way this should be done is as follows:

1) Convert to octal digits ie: '<>+-.,[]' to '01234567'
2) Prefix the whole string with an octal '1' to protect any leading zeros.
3) Convert to decimal.



For hello world.

Your way gives:


Notice the original is a little longer than the decimal:


The examples on the main page use the octal method; the javascript "converter" is wrong.

--(this comment by 2001:470:1F09:10D6:59EC:8D1F:E4AD:59EF at 19:28, 4 August 2013‎ UTC; please sign your comments with ~~~~)

1 symbol

I've never really been happy with that, and not just because of the EOF. I suppose it comes down to the definition of "symbol" — by this definition of "symbol" more or less all languages have exactly two symbols: 1 and 0. Phantom Hoover 13:32, 20 March 2010 (UTC)

99 bottles of beer

The 99-bottles-of-beer program


is represented in Unary as a string of


zeroes. Wow. Jleedev 18:05, 31 May 2010 (UTC)

In fact unless I'm mistaken the length of that number should be approximately log 8/log 10 ~ 0.903 of the length of the brainfuck program. --Ørjan 08:19, 1 June 2010 (UTC)

Converter in sed/dc

I made converters for Unary<->Brainfuck using only dc and sed (and wc at the beginning to get the file size). If you're using Windows, you just need sed and dc.sed.

Convert Unary to Brainfuck:

wc -c filename | sed -e "s/ .*/ 8opq/" | dc | sed -e "s/0/>/g;s/1/</g;s/2/+/g;s/3/-/g;s/4/./g;s/5/,/g;s/6/[/g;s/7/]/g"

Convert Brainfuck back to Unary:

sed -e ":a;s/[^-][><+.,]//g;s/>/0/g;s/</1/g;s/+/2/g;s/-/3/g;s/\./4/g;s/,/5/g;s/\[/6/g;s/]/7/g;$!{N;s/\n//;ba};s/^/8i/;s/$/ [0P1-d0!=a]dsaxq/" filename | dc

The second one will print a LOT of zeroes! Just change the [0P1-d0!=a]dsaxq to pq to print a decimal number instead.

Another way using "lookup tables" which actually turned out to be longer (and probably slower):

wc -c filename | sed -e "s/ .*/ 8opq/" | dc | sed -e "s/$/0>1<2+3-4.5,6[7]/;:a;s/\([0-7]\)\(.*\(.\)\1.\)/\3\2/;ta;s/.\{16\}$//"
sed -e ":a;s/[^-][><+.,]//g;s/$/0>1<2+3-4.5,6[7]/;:b;s/\([-][><+.,]\)\(.*\1\(.\)\)/\3\2/;tb;s/.\{16\}$//;$!{N;s/\n//;ba};s/^/8i/;s/$/[0P1-d0!=a]dsaxq/" filename | dc

Ian 06:27, 3 March 2011 (UTC)


Quine in Unary anyone? Is it possible?

I don't think so. --(this comment by at 01:04, 19 January 2012 UTC; please sign your comments with ~~~~)

It certainly exists mathematically by general principles, and I think we could construct the corresponding Brainfuck program, but the actual Unary program probably won't fit in our universe. --Ørjan 03:07, 19 January 2012 (UTC)
It would be interesting to know at least one such number. In itself this isn't the most difficult task: create a program which is a brainfuck quine, but which instead of printing its code as brainfuck symbols creates in its internal memory the binary number needed in Unary. This part is easy. After that, the program should convert it to unary using a method such as this Markov algorithm (found it from Wikipedia but I think it works):
'1' -> '0|'
'0' -> 
And print the resulting long list in '0' characters. Actually this is moderately easy too, only tedious as string-matching tends to be in this language. However -- to get to know this number we don't need to print it. The program must have in its code the functionality for converting the binary string into unary and printing it as '0's, even if it never needs to be executed for one to get the result: one might insert a character like '#' in the brainfuck code just before the converting part starts -- and why not end the program too, as further execution isn't necessary -- and modify the brainfuck interpreter to dump the memory when a '#' is encountered. That memory dump would reveal the number in binary, which could be taken from there and converted to decimal (for a better and more logical presentation) with a simple Python program (for example). I might do this but not today. --Keymaker 12:33, 19 January 2012 (UTC)
One of the more difficult quines around here. And also one of the more interesting ones:) Markov algorithm implementation would be quite tricky. 22:17, 19 January 2012 (UTC)

A quine in Unary

This is a quine in Unary, prepared the way I sketched above. The binary number before it is converted to unary has 11401 digits. If anyone visits an alternate universe and has a chance to run this program, tell me if it works. The number below, presented in unary format of '0' characters in a row, is a quine in Unary (divided into rows of 100 digits for better legibility):


Below is the brainfuck program (likewise divided into lines of 100 characters). If you translate it to Unary it should become the number above (in unary of course).

And it does! I just tried -- that is, converting the Unary program's binary phase to decimal, converting it to unary would be impossible... But of course if the number matches in decimal it matches in unary as well. --Keymaker 00:59, 21 January 2012 (UTC)

The "%" in between is meta-data for the brainfuck interpreter (the "#" of the plan somewhere above). Once the brainfuck interpreter reaches that point it can print all the memory and quit. The code after "%" is for the Markov algorithm and printing the resulting unary number in '0's. Suffices to say, it's pointless to try running this program till it completes. :) --Keymaker 00:41, 21 January 2012 (UTC)