Still learning Nim and was trying to solve this problem: [Write a function that 
combines two lists by alternatingly taking elements, e.g. [a,b,c], [1,2,3] → 
[a,1,b,2,c,3].](https://adriann.github.io/programming_problems.html)

I came up with this:
    
    
    let
        numberList = [1, 2, 3]
        letterList = ["a", "b", "c"]
    var counter = 0
    
    proc convertToString[I] (list: array[I, int]): array[I, string] =
        for letter in list:
            result[counter] = $letter
            counter += 1
    
    var convertedList = convertToString(numberList)
    counter = 0
    
    proc alternate[I1, I2: static[int], string](firstList: array[I1, string], 
secoundList: array[I2, string]): array[I1 + I2, string] =
        for letter in firstList:
            result[counter] = letter
            counter += 2
        counter = 1
        for number in secoundList:
            result[counter] = number
            counter += 2
        counter = 0
    
    echo alternate(letterList, convertedList)
    
    
    Run

Is there a better way to solve this problem?

Reply via email to