예제 #1
0
    def countNumber(self, N):

        array = range(1, N + 1)
        i = 1
        start = 0
        while len(array) > 1:
            t = pow(i, 3)
            index = (start + t) % len(array)
            array.pop(index)
            start = index + 1
            i += 1

        if array[0] == 0:
            return N
        return array[0]
예제 #2
0
def insert(arr, temp):
    if len(arr) == 0 or arr[len(arr) - 1] <= temp:
        arr.append(temp)
        return
    val = arr.pop()
    insert(arr, temp)
    arr.append(val)
예제 #3
0
def checksum(array):
  cb = array.pop()
  checksum = 256 - sum(array) % 256
  if (cb == checksum):
    #print "valid checksum"
    del array[0]
    return True
  else:
    return False  
예제 #4
0
	def test_pop(self):
		""" -- Verifica función pop
		"""
		arr=Array(10)
		arr[0]=10
		arr[1]=20
		arr[2]=30
		arr[3]=40
		res=pop(arr)
		self.assertEqual(res,40)
예제 #5
0
    def addMidiNote(self, array, time, note, velocity=127):
        if(velocity == 0):
            note = 0

        millis = (int) (time*1000)

        while millis >= 256:
            array[-1] = 255
            array.append(array[-2])
            array.append(1)
            millis -= 255

        if millis > 1:
            array[-1] = millis
        else:
            array.pop()
            array.pop()

        array.append(note)
        array.append(100)
예제 #6
0
파일: array11.py 프로젝트: YSreylin/HTML
#write a python to remove a specified items using the index from an array
import array
array = array.array('i',[1,3,4,5,6,7])
print("The original array are:", array)
a = int(input("Enter the place number you want to delete:"))
array.pop(a)
print(array)
#Input an array from user and delete a index.

import array as arr

arr = arr.array('i', [])
n = int(input())

for i in range(n):
    ele = int(input("Enter elements: "))
    arr.append(ele)
for i in arr:
    print(i, end=" ")
ind = int(input("Enter index u want to delete: "))
arr.pop(ind)
for i in arr:
    print(i, end=" ")
예제 #8
0
# cerner_2^5_2020
"""
Given a fixed length array arr of integers, duplicate each occurrence of zero, shifting the remaining elements to the right.
Note that elements beyond the length of the original array are not written.
Do the above modifications to the input array in place, do not return anything from your function.
Example 1:
Input: [1,0,2,3,0,4,5,0]
Output: null
Explanation: After calling your function, the input array is modified to: [1,0,0,2,3,0,0,4]
Example 2:
Input: [1,2,3]
Output: null
Explanation: After calling your function, the input array is modified to: [1,2,3]
Note:
    1 <= arr.length <= 10000
    0 <= arr[i] <= 9
    https://leetcode.com/problems/duplicate-zeros/
"""
import array as arr

arr = [1,0,2,3,0,4,5,0]
#arr = [1,2,3]
#arr = [0,8,2]
i = 0
while i < len(arr):
    if arr[i] == 0
        arr.insert(i,0)
        arr.pop()
        i += 1
        print(arr)
예제 #9
0
	def test_pop_vacio(self):
		""" -- Verifica función pop desde un array vacio
		"""
		arr=Array(10)
		res=pop(arr)
		self.assertEqual(res,None)
예제 #10
0
import array as arr

arr = [1, 2, 3, 4, 5, 6, 7, 8, 9]

arr.pop(6)
print(arr)
a = arr[2]
b = arr[6]
a, b = b, a
arr.insert(2, a)
arr.insert(6, b)
arr.pop(3)
arr.pop(7)
print(arr)
import array

#initializing array with array values
#initializes array with signed integers
arr = array.array('i', [1,2,3,1,5])

#printing original array
print ("The new created array is : ", end ="")
for i in range (0, 5):
    print (arr[i], end =" ")

print ("\r")

#using pop() to remove element at 2nd position
print ("The popped element is : ", end ="")
print (arr.pop(2))

#printing array after popping
print ("The array after popping is : ", end ="")
for i in range (0, 4):
    print (arr[i], end =" ")
    
print("\r")

#using remove() to remove 1st occurence of 1
arr.remove(1)

#printing array after removing
print ("The array after removing is : ", end ="")
for i in range (0, 3):
    print (arr[i], end =" ")