Problem
Defines a one-dimensional array of int, contains 10 elements, assigns values to 1~10, and then moves the elements in the array forward one position,
That is, a[0]=a[1],a[1]=a[2],... The value of the last element is the value of the original first element, and then the array is output.
Resolution (Python)
#!/usr/bin/env python
#coding: Utf-8
def ahead_one ():
a = [I for I in Range (Ten)]
B = A.pop (0)
A.append (b) Return
a
if __name__ = = "__main__":
print Ahead_one ()
Resolution (Racket 5.2.1)
#lang racket
; define function Ahead-one
; Enter as an integer list int-list, assuming its length is N
; output is a list of integers of the same length, and its nth-bit element is the 1th-bit element of Int-list,
; The element whose 1~n-1 bit is the 2~n bit of the Int-list
(define (Ahead-one int-list)
(Append (rest int-list) (list (first int-list)) )
; function calls should output ' (2 3 4 5 6 7 8 9 1)
(Ahead-one (List 1 2 3 4 5 6 + 7 8 9 10)) in normal operation