Shift list elements to left by 3
Shift list elements to left by 3 is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.
- Task
- Shift list elements to left by 3.
shift = [1,2,3,4,5,6,7,8,9]
result = [4, 5, 6, 7, 8, 9, 1, 2, 3]
Ring
<lang ring> see "working..." + nl
shift = [1,2,3,4,5,6,7,8,9] lenshift = len(shift) shiftNew = list(lenshift) nshift = 3 temp = list(nshift)
see "original list:" + nl showArray(shift) see nl + "shift list elements to left by 3:" + nl
for n = 1 to nshift
temp[n] = shift[n]
next
for n = 1 to lenshift - nshift
shiftNew[n] = shift[n+nshift]
next
for n = lenshift-nshift+1 to lenshift
shiftNew[n] = temp[n-lenshift+nshift]
next
showArray(shiftNew)
see nl + "done..." + nl
func showArray(array)
txt = "[" for n = 1 to len(array) txt = txt + array[n] + ", " next txt = left(txt,len(txt)-2) txt = txt + "]" see txt
</lang>
- Output:
working... original list: [1, 2, 3, 4, 5, 6, 7, 8, 9] shift list elements to left by 3: [4, 5, 6, 7, 8, 9, 1, 2, 3] done...