## Decode the diagonal. 

Given a grid of characters. Output a decoded message as a string.

Input

```
  H Z R R Q
  D I F C A E A !
  G H T E L A E 
  L M N H P R F 
  X Z R P E
```
  
Output

`HITHERE!` (diagonally down right `↘` and diagonally up right `↗` if you can't go further).

The message ends when there is no space at the right up or down diagonal.

To make things even clearer: the same example, but in a simplified view

```
  H _ _ _ _
  _ I _ _ _ _ _ !
  _ _ T _ _ _ E 
  _ _ _ H _ R _
  _ _ _ _ E
```

Difficulty: introductory

Starter code:

def get_diagonale_code(grid:
	

Solutions:
def get_diagonale_code(grid):
    grid = [line.split() for line in grid.split("\n")]
    i, j, d, word = 0, 0, 1, ""
    while 0 <= i < len(grid) and j < len(grid[i]):
        if 0 <= j < len(grid[i]):
            word += grid[i][j]
            i, j = i + d, j + 1
        else: i += d
        if i == 0 or i == len(grid) - 1: d = -d
    return word

def get_diagonale_code(grid: str) -> str:
    if not grid:
        return ''
    s=[]    
    for line in grid.split('\n'):
        s.append(line.split(' '))
    if len(s)==1:
        return s[0][0]
    x,y=0,0
    m=-1
    r=''
    while(y<len(s[x])):
        r+=s[x][y]
        if x==0 or x==len(s)-1:
            m*=-1
        x+=m
        y+=1
    return r

from itertools import takewhile,count

def get_diagonale_code(grid):
    grid = grid.replace(' ','').split('\n')
    rail = len(grid)-1
    return grid[0] if not rail else ''.join(takewhile(bool, genRail(grid,rail)))

def genRail(grid,rail):
    for i in count():
        n,x = divmod(i,rail)
        row = rail-x if n&1 else x
        yield '' if i>=len(grid[row]) else grid[row][i]

def get_diagonale_code(grid: str) -> str:
    grid = grid.split('\n')
    ret = ''
    l , i, s = 0, 0 , 1
    while 1:
        try:
            ret += grid[l][i]
        except:
            return ret
        i += 2
        l += s
        if l == len(grid)-1 or l==0:
            s = -s


def get_diagonale_code(s):
    out, m = [], s.splitlines()
    d, i, j = -1, 0, 0
    while i < len(m) and j < len(m[i]):
        out.append(m[i][j])
        j += 2
        if i in (0, len(m) - 1): d = -d
        i += d
    return ''.join(out)

def get_diagonale_code(grid: str) -> str:
    if not grid:
        return ""
    lines = [l.split() for l in grid.split('\n')]
    row, col, word = (0, 0, "")
    while col < len(lines[row]):
        word += lines[row][col]
        if row == 0:
            down = True
        if row+1 == len(lines):
            down = False
        row = row+1 if down else row-1
        col += 1
    return word
        


def get_diagonale_code(grid: str) -> str:
    i, j, res, move, M = 0, 0, [], 1, [line.split() for line in grid.split('\n')]
    while i < len(M) and j < len(M[i]):
        res.append(M[i][j])
        move = 1 if i==0 else -1 if i==len(M)-1 else move
        i, j = i+move, j+1
    return ''.join(res)

def get_diagonale_code(grid):
    grid = [line.split() for line in grid.splitlines()]
    d, word, N = -1, "", len(grid)
    x, y = 0, 0
    while x < N and y < len(grid[x]):
        if x == 0 or x == N - 1:
            d *= -1
        word += grid[x][y]
        x, y = x + d, y + 1
    return word

from itertools import count, cycle, takewhile

def get_diagonale_code(grid: str) -> str:
    rows = grid.splitlines()
    it = zip(cycle(rows + rows[-2:0:-1]), count(0, 2))
    chars = (row[c] if c < len(row) else None for row, c in it)
    return ''.join(takewhile(lambda c: c, chars))

def generator(strings: list):
    while True:
        for q in strings:
            yield q
        for q in strings[-2: 0: -1]:
            yield q
        

def get_diagonale_code(grid: str) -> str:
    strings = [q.replace(' ', '') for q in grid.split('\n')]
    result = []
    for index, row in enumerate(generator(strings)):
        if index < len(row):
            result.append(row[index])
        else:
            return ''.join(result)

def get_diagonale_code(grid: str) -> str:
    ans=[]
    if grid:
      grid = [k.strip().split(" ") for k in grid.split("\n")]
      i=j=0
      dir = True
      while j <len(grid[i]):
        ans.append(grid[i][j])
        if i == len(grid) - 1:dir = False
        if (i == 0): dir = True 
        i = 0 if len(grid) == 1 else i +1 if dir else i - 1
        j+=1
    return "".join(ans)


def get_diagonale_code(s):
    S=[x.split()for x in s.split('\n')]
    i,z,L=0,'',list(range(len(S)))
    while 1:
        try:
            for j in L+L[1:-1][::-1]:z,i=z+S[j][i],i+1
        except:return z

def get_diagonale_code(grid: str) -> str:
    flag=True
    temp=grid.split("\n")
    for i,j in enumerate(temp):
        temp[i]=j.split()
    res=""
    x=0
    y=0
    while True:
        try:
            res+=temp[y][x]
            if y==len(temp)-1:
                flag=False
            elif y==0 and not flag:
                flag=True
            y+=1 if flag else -1
            x+=1
        except:
            return res

def get_diagonale_code(grid: str) -> str:
    matrix = [i.split() for i in grid.split('\n')]
    x, y, flag = 0, 0, 1
    result = ''
    while x < len(matrix) and y < len(matrix[x]) :
        result += matrix[x][y]
        x, y = x + flag, y + 1
        flag = flag if 1 < x + 1 < len(matrix) else -flag
    return result

def get_diagonale_code(grid: str) -> str:
    matrix = [i.split() for i in grid.split('\n')]
    x, y = 0, 0
    flag = True
    result = ''
    while x < len(matrix) and y < len(matrix[x]) :
        result += matrix[x][y]
        y += 1
        x = x + 1 if flag else x - 1
        flag = flag if 1 < x + 1 < len(matrix) else not flag
    return result
        
        



def get_diagonale_code(grid: str) -> str:
    g = (grid.replace(" ","").split("\n"))
    i, j, d, word = 0, 0, 1, ""
    while 0 <= i < len(g) and j < len(g[i]):
        if 0 <= j < len(g[i]):
            word += g[i][j]
            i, j = i + d, j + 1
        else: 
            i += d
        if i == 0 or i == len(g) - 1: 
            d = -d
    return word

def get_diagonale_code(grid: str) -> str:
    grid = grid.replace(' ','').split('\n')
    x,y = 0,0
    s=1
    res=''
    try:
        while True:
            print((x,y,s,grid[x][y]))
            res+=grid[x][y]
            y+=1
            x+= 1 if s==1 else -1
            if not 0<=x<len(grid):
                s*=-1
                x+=s*2
    except:
        return res


def get_diagonale_code(grid: str) -> str:
    grid = grid.split('\n')
    ret = ''
    l , i, s = 0, 0 , 1
    while 1:
        try:
            ret += grid[l][i]
        except:
            return ret
        i += 2
        l += s
        if l == len(grid)-1:
            s = -1
        elif l <= 0:
            s = 1


def get_diagonale_code(grid: str) -> str:
    res, grid = '', [x.split() for x in grid.splitlines()]
    r, c, x, rows = 0, 0, 1, len(grid)
    while -1 < r < rows and c < len(grid[r]):
        res += grid[r][c]
        if r + 1 == rows:
            x = -1
        elif r == 0:
            x = 1
        r += x
        c += 1
    return res

def get_diagonale_code(grid: str) -> str:
    grid = [x.split() for x in grid.splitlines()]
    res, rows, x = '', len(grid), 1
    r = c = 0
    while -1 < r < rows and c < len(grid[r]):
        res += grid[r][c]
        if r + 1 == rows:
            x = -1
        elif r == 0:
            x = 1
        r += x
        c += 1
    return res