This repository was archived by the owner on Aug 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcodingBat1.py
More file actions
75 lines (63 loc) · 1.41 KB
/
codingBat1.py
File metadata and controls
75 lines (63 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Program Name: codingBat_2.py
# Anthony Waldsmith
# 07/23/16
# Python Version 3.4
# Description: A collection of Functions 2
# Optional import for versions of python <= 2
from __future__ import print_function
def main():
# Main Method
print()
big_diff([10, 3, 5 , 6])
#### FUNCTIONS ####
# Count utility function
def count(needle, haystack):
counter = 0
for i in range(len(haystack)):
# Scan along the haystack for needle
if (haystack[i:i + len(needle)] == needle):
# Increment by 1 if found
counter += 1
return counter
def smallest(nums):
smallest = 9999
for i in nums:
if (i < smallest):
smallest = i
return smallest
def largest(nums):
largest = -9999
for i in nums:
if (i > largest):
largest = i
return largest
def sortList(array):
size = len(array)
for i in range(size):
for j in range(size-i-1):
if (array[j] > array[j+1]):
var = array[j]
array[j] = array[j+1]
array[j+1] = var
return array
def centered_average(nums):
amount = len(nums)
# Not using min() , max(), sort(), sorted(), or reduce()
# Sorting and trimming
array = sortList(nums)
array = array[1:-1]
total = 0
for i in array:
total += i
total = (total / amount)
return total
def big_diff(nums):
minimum = smallest(nums)
maximum = largest(nums)
#print ("Min: %i" %(minimum))
#print ("Max: %i" %(maximum))
return (maximum - minimum)
# Call main
main()