# The jumping digits to letters transformation

Imagine you have an infinite sequence of the alphabet repeated infinitely many times:

abcdefghijklmnopqrstuvwxyzabcd...


You start at index 0, which corresponds to the letter a, and the should_write boolean flag is False.

The input is a list or string of single-digit numbers. For each number n in the input, you should:

• Print (or add to the return value) the n-th item of the list if the should_write flag is set to True

• If n is 0, swap the should_write flag.

• Otherwise move (jump) the index n places forward.

At the end of the input, stop (and return the result if using a function).

Input

A sequence of digits (list or string).

Output

The text that comes out after applying the above procedure.

Examples

>>> g('99010')
st
>>> g('100')
b
>>> g('2300312')
f
>>> g('390921041912042041010')
mvxyptvab
>>> g('1')
>>> g('1045')
bf
>>> g('33005780')
g
>>> g('100100102')
bcd
>>> g('012')
ab

• Does the input have to be a string of digits, as in your test cases, or can it be a list of numbers? – xnor Oct 13 '15 at 20:23
• Are you sure about your test cases? Several of them seem wrong to me. – Peter Taylor Oct 13 '15 at 20:28
• @xnor a list of digits – Caridorc Oct 13 '15 at 20:32
• @Caridorc In '33005780', how is more than 1 char printed? The should_write flag starts off, is turned on for one digit and turned back off immediately, and then only turned on again at the end. – xnor Oct 13 '15 at 20:39
• @xnor found obvious bug in my reference implementation and facepalmed, will correct testcases asap... – Caridorc Oct 13 '15 at 20:40

## Python 3, 60

i=b=0
for c in input():b and print(chr(97+i%26));b^=c<1;i+=c


Takes a list of numbers and prints the chars on separate lines.

Basically just follows the instructions. The index is i and the should_write flag is b. The expression b and short-circuits to print only when b is true.

# Pip, 20 bytes

Takes a string of digits as command-line argument.

Fda{IyOz@id?i+:dY!y}


This code uses a number of Pip's preinitialized variables. i is initially 0, y is initially "" (falsy) and z contains the lowercase alphabet. a gets the first command-line arg.

Fda{               }  For each digit d in a:
IyOz@i              If y (the flag) is truthy, output letter of z at index i
Pip's cyclic indexing takes care of the infinite effect
d?            If d is truthy (digit is nonzero),
i+:d          then increment i by d;
Y!y       otherwise, yank !y into y (thus swapping the flag)


An alternate way of swapping the flag would be !:y, with !: being a compute-and-assign operator just like +:.

C:\Users\dlosc> pip.py -e Fda{IyOz@id?i+:dY!y} 390921041912042041010
mvxyptvab


# CJam, 28 bytes

0q{~U{1\$'a+o}&_!U^:U;+26%}/;


Test it here.

Nothing really special here. Like xnor, I don't have a string of letters but simply a running total (mod 26) which I add to a when I need to print it. The should_write flag is kept track of in U.

# R, 73 bytes

Once I got it sorted in my head:)

(letters[cumsum(a<-head(scan()),-1)%%26+1])[which(cumprod(-(a<1)*2+1)<0)]


This takes a vector of integers from STDIN and returns a vector of letters.

Ungolfed and explanation

a <- head(scan()),-1)    # get integers from stdin and drop last one
a <- cumsum(a) %% 26 + 1 # do the cumulative sum of the vector to use as a vector of letter indexes
l <- letters[a]          # vector of potential letters
p <- -(a<1)*2+1          # turns 0's into -1 and everything else into 1
p <- cumprod(p)          # the cumlative prod then creates a vector of on and off values
f <- which(p<0)          # index values of the returned characters
l[f]                     # return vector of characters


Tests

> (letters[cumsum(a<-head(scan(),-1))%%26+1])[which(cumprod(-(a<1)*2+1)<0)]
1: 9 9 0 1 0
6:
 "s" "t"
1: 1 0 0
4:
 "b"
1: 2 3 0 0 3 1 2
8:
 "f"
1: 1
2:
character(0)
1: 1 0 4 5
5:
 "b" "f"
1: 0 1 2
4:
 "a" "b"
>


# JavaScript (ES6) 76

(note: the fromCharCode function is so lengthy that for lowercase letters it's better a conversion to base 36)

Test running the snippet below in any EcmaScript 6 compliant browser

g=l=>l.replace(/./g,n=>[f?(p%26+10).toString(36):'',-n?p-=-n:f=!f],p=f=0)

console.log=x=>O.innerHTML+=x+'\n'

;['99010','100','2300312','390921041912042041010','1','1045','33005780','100100102','012']
.forEach(t=>console.log(t+' ['+g(t)+']'))
<pre id=O></pre>