aboutsummaryrefslogtreecommitdiffstats
path: root/OLD/csci1913/Python/lab3_strap012.py
diff options
context:
space:
mode:
authorRossTheRoss <mstrapp@protonmail.com>2020-01-30 16:55:04 -0600
committerRossTheRoss <mstrapp@protonmail.com>2020-01-30 16:55:04 -0600
commit175721a63b426355274fa9e8063f762020ab8362 (patch)
treecf2c1b33233d660c9f50de5e659b9343bb264984 /OLD/csci1913/Python/lab3_strap012.py
parentMake Python thing in Python (diff)
downloadhomework-175721a63b426355274fa9e8063f762020ab8362.tar
homework-175721a63b426355274fa9e8063f762020ab8362.tar.gz
homework-175721a63b426355274fa9e8063f762020ab8362.tar.bz2
homework-175721a63b426355274fa9e8063f762020ab8362.tar.lz
homework-175721a63b426355274fa9e8063f762020ab8362.tar.xz
homework-175721a63b426355274fa9e8063f762020ab8362.tar.zst
homework-175721a63b426355274fa9e8063f762020ab8362.zip
R E A R R A N G E
Diffstat (limited to 'OLD/csci1913/Python/lab3_strap012.py')
-rw-r--r--OLD/csci1913/Python/lab3_strap012.py63
1 files changed, 63 insertions, 0 deletions
diff --git a/OLD/csci1913/Python/lab3_strap012.py b/OLD/csci1913/Python/lab3_strap012.py
new file mode 100644
index 0000000..f9df918
--- /dev/null
+++ b/OLD/csci1913/Python/lab3_strap012.py
@@ -0,0 +1,63 @@
+#"New" functions
+def Reduce(F,S):
+ if len(S)==0:
+ return -255
+ else:
+ return F(Reduce(F,S[:-1]),S[-1])
+def returnGreater(a,b):
+ if a > b:
+ return a
+ else:
+ return b
+
+#Implementation from Lab
+def Sort(T):
+ if len(T)==0:
+ return ()
+ else:
+ return (Sort(Remove(T,Maximum(T))))+(Maximum(T),)
+def Maximum(T):
+ return Reduce(returnGreater,T)
+def Remove(T,E):
+ if len(T)==0:
+ return ()
+ elif T[0] is E:
+ return T[1:]
+ else:
+ return (T[0],)+Remove(T[1:],E)
+
+
+#
+# TESTS. Tests for CSci 1913 Lab 3.
+#
+# James Moen
+# 11 Feb 19
+#
+# Each test is worth 2 points, for 40 points total. Comments show what must be
+# printed to receive credit. Note that your function SORT must work for tuples
+# with negative elements.
+#
+
+print(Maximum((1,))) # 1 2 pt.
+print(Maximum((-2, -1))) # -1 2 pt.
+print(Maximum((1, 1))) # 1 2 pt.
+print(Maximum((1, 2, 3))) # 3 2 pt.
+
+print(Remove((), 1)) # () 2 pt.
+print(Remove((1,), 1)) # () 2 pt.
+print(Remove((0, 1), 0)) # (1,) 2 pt.
+print(Remove((0, 1, 2, 1, 3), 1)) # (0, 2, 1, 3) 2 pt.
+print(Remove((0, 1, 2, 1, 3), 2)) # (0, 1, 1, 3) 2 pt.
+print(Remove((1, 2, 3), 3)) # (1, 2) 2 pt.
+
+print(Sort(())) # () 2 pt.
+print(Sort((0,))) # (0,) 2 pt.
+print(Sort((0, -1))) # (-1, 0) 2 pt.
+print(Sort((1, 0))) # (0, 1) 2 pt.
+print(Sort((0, 0, 1))) # (0, 0, 1) 2 pt.
+print(Sort((0, -1, 0))) # (-1, 0, 0) 2 pt.
+print(Sort((0, 0, 1))) # (0, 0, 1) 2 pt.
+
+print(Sort((9, 8, 7, 6, 5, 4, 3, 2, 1))) # (1, 2, 3, 4, 5, 6, 7, 8, 9) 2 pt.
+print(Sort((1, 2, 3, 4, 5, 6, 7, 8, 9))) # (1, 2, 3, 4, 5, 6, 7, 8, 9) 2 pt.
+print(Sort((1, 2, 1, 4, 2, 5, 4, 5, 3))) # (1, 1, 2, 2, 3, 4, 4, 5, 5) 2 pt.