I absolutely hate the digit 1. So, I need your help to convert numbers to their "proper forms".

Numbers in proper form never have two 1s in a row. 101 is okay, but 110 is hideous.

To convert, simply skip all the improper numbers and count normally. For instance...

1 -> 1
2 -> 2
...
10 -> 10
11 -> 12
12 -> 13
...
108 -> 109
109 -> 120
110 -> 121
111 -> 122


and so on.

Your program should take an integer and output it in proper form. This is , so shortest code in bytes wins.

• Is there an upper bound on input? – lirtosiast Oct 23 '15 at 18:48
• I don't get the 109 -> 120 conversion... – kirbyfan64sos Oct 23 '15 at 19:52
• @kirbyfan64sos Since 108 maps to 109, 109 would map to the next number, which is 110. But that one has two 1s in a row, so it goes to the next number until it reaches one that does not. Which is 120, since all of 110-119 are excluded. – Reto Koradi Oct 23 '15 at 19:59
• @Corey Ogburn It's not about binairy. See it as how a list of numbers would be when you count up to the given number with the no-11 rule for each number in the list – LukStorms Oct 23 '15 at 20:26
• @leymannx The number on the left represents the number in the series. So the first value in the series is 1, the second value in the series is 2, yadda yadda(lobster bisque), the tenth value in the series is 10, and the eleventh value in the series is 12, because we skipped 11 as talex finds it an abomination unto the lord. This idea continues on, hence why the 108th value in the series is 109, and the 110th value in the series is 120, as we skip everything from 110 to 119. Hope I clarified well enough. – ahall Oct 24 '15 at 23:35

Burlesque, 10 bytes

{11~[n!}FO

Older versions:

ro{11~[n!}f[

ro{Sh"11"~=n!}f[

• done. It's been around since 2012, there's also an article on RosettaCode and the esowiki as well. – mroman Oct 23 '15 at 21:00

Perl 5, 34 Bytes

Looping a counter and changing the occasional double-one.

map{$i++;$i=~s/11/12/}1..pop;say$i  Test $ perl -M5.012 -e 'map{$i++;$i=~s/11/12/}1..pop;say$i' 111$ 122


Bash + GNU utils, 36

seq $1$1|grep -v 11|sed -n "$1{p;q}"  • Surely 1$1 suffices, rather than $1$1? – Neil Oct 24 '15 at 10:39

Pyth, 13 11 bytes

e.f!}hTZQ


Saved 2 bytes thanks to @FryAmTheEggman.

Live demo and test cases.

13-byte version

e.f!}"11"+ZkQ

• Context: Pyth, Pyth, and Pyth. – Peter Mortensen Oct 25 '15 at 16:21
• @PeterMortensen The third one is unrelated to the Pyth used here - it's from 8 years before this Pyth was created, actually. Pyth is just a popular name for Python inspired languages. – isaacg Oct 26 '15 at 9:18

JavaScript, 53 bytes

n=>[...Array(n*2).keys()].filter(a=>!/11/.test(a))[n]


Alternate (using comprehensions, same length):

n=>[for(i of Array(n*2).keys())if(!/11/.test(i))i][n]


Python 2, 50

lambda n:[i for i in range(n*2)if'11'not ini][n]


An anonymous function that lists the numbers not containing 11 in order, and takes the nth one. The off-by-one error of zero-indexing cancels with the inclusion of 0 in the list.

In theory, this will fail for sufficiently high numbers where f(n)>2*n, but this shouldn't happen until n is at least 10**50.

51 bytes:

n=input();i=0
while n:i+=1;n-='11'not ini
print i


Counts up numbers i until the quota of n numbers without 11 is met.

A function is the same length because of the off-by-one corrections needed.

f=lambda n,i=0:n+1and f(n-('11'not ini),i+1)or~-i


Python 3 74

Still need a bit of golfing.

n=int(input())
c=0
for x in ' '*n:
c+=1
while'11'in str(c):c+=1
print(c)


It's pretty brute force right now.

Perl 5, 47 bytes

@_[$_]=++$i!~/11/?$i:redo for 1..<>;print$_[-1]


JavaScript (ES6) 41

As an anonymous function

n=>eval('for(i=0;/11/.test(++i)||n--;)i')


Note: the very simplest way would be 44:

n=>{for(i=0;/11/.test(i)||n--;i++);return i}


Test running the snippet below.

f=n=>eval('for(i=0;/11/.test(++i)||n--;)i')

alert(f(+prompt('Enter number')))

([x|x<-[0..],notElem('1','1')$zip=<<tail$show x]!!)


Usage example: ([x|x<-[0..],notElem('1','1')$zip=<<tail$show x]!!) 110 -> 121.

How it works:

[x|x<-[0..]                                   ]    -- take all x starting with 0
,                                       -- where
('1','1')                       -- the pair of two chars '1'
notElem                                -- is not part of
zip=<<tail            -- the list of pairs of neighbor elements of
show x     -- the string representation of x
!!  -- take nth element, where n is the parameter


MUMPS, 37 bytes

t(i) f j=1:1 s:j'[11 k=k+1 q:k=i
q j


Pretty straightforward. The only "interesting" thing here is the construct j'[11 - '[ is the "does not contain" operator, so that "abc"'["ab" is false and "abc"'["cd" is true. Despite both operands of j'[11 being numbers, MUMPS remains unperturbed. It will happily autocoerce both operands to strings and move on with its life. Hooray!

(Incidentally, if you're okay with the program never terminating, we can shorten this to 35 bytes: t2(i) f j=1:1 s:j'[11 k=k+1 w:k=i j)

while(preg_match('/11/',$i)){$i++;}print$i;  Ruby, 24 bytes Misinterpreted the task, will rework later! $><<gets.gsub('11','12')

• Doesn't work on inputs that don't contain 11. For example, 12 should give 13, not 12. – DLosc Oct 23 '15 at 20:56
• @DLosc Oh gosh I've misinterpreted the task! I'll rework it later! – Peter Lenkefi Oct 23 '15 at 21:06