From f58fdeff5091edac9bea84b946002c5a83f81ec5 Mon Sep 17 00:00:00 2001 From: Torchtopher Date: Tue, 6 Feb 2024 10:34:29 -0500 Subject: [PATCH 1/2] problem9 --- .gitignore | 0 INSTALL.md | 1 + README.md | 14 +++++++++++++- gitignore | 0 old.txt | 0 problem1.py | 29 +++++++++++++++++++++++++++++ problem2.js | 31 +++++++++++++++++++++++++++++++ styles.css | 19 +++++++++++++++++++ website.html | 17 +++++++++++++++++ 9 files changed, 110 insertions(+), 1 deletion(-) create mode 100644 .gitignore create mode 100644 INSTALL.md create mode 100644 gitignore create mode 100644 old.txt create mode 100644 problem1.py create mode 100644 problem2.js create mode 100644 styles.css create mode 100644 website.html diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/INSTALL.md b/INSTALL.md new file mode 100644 index 0000000..c5ffe3f --- /dev/null +++ b/INSTALL.md @@ -0,0 +1 @@ +### Installation Instructions:pgi \ No newline at end of file diff --git a/README.md b/README.md index 4fed924..a98ac70 100644 --- a/README.md +++ b/README.md @@ -1 +1,13 @@ -# Git Lab 1 +# Christopher Holley +## **RESOURCES** +- https://www.markdownguide.org/hacks/ +- Github Copilot +- https://stackoverflow.com/questions/14907067/how-do-i-restart-a-program-based-on-user-input +- https://www.geeksforgeeks.org/how-to-read-command-line-arguments-in-node-js/# +- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map +- https://stackoverflow.com/questions/20864893/replace-all-non-alphanumeric-characters-new-lines-and-multiple-white-space-wit +- https://www.w3schools.com/html/html_form_input_types.asp +- https://www.w3schools.com/html/html_css.asp +- https://brand.ncssm.edu/fonts-and-colors +- https://stackoverflow.com/questions/15843391/div-height-set-as-percentage-of-screen +- https://dequeuniversity.com/rules/axe/4.4/color-contrast diff --git a/gitignore b/gitignore new file mode 100644 index 0000000..e69de29 diff --git a/old.txt b/old.txt new file mode 100644 index 0000000..e69de29 diff --git a/problem1.py b/problem1.py new file mode 100644 index 0000000..d0583a4 --- /dev/null +++ b/problem1.py @@ -0,0 +1,29 @@ +import sys + +def main(args): + currency = [("dollar", "dollars", 100), ("quarter", "quarters", 25), ("dime", "dimes", 10), ("nickel", "nickels" , 5), ("penny", "pennies", 1)] + if len(args) != 1: + print("Exactly one argument is required: usage `python problem1.py \$X.YZ`") + + exit(-1) + money = args[0] + assert money[0] == '$', "\nThe input should start with a dollar sign. Make sure to escape this if on linux." + dollars = money[1:] # remove $ + dollars, cents = dollars.split('.') + assert len(cents) == 2, "\nThe cent amount should be two digits" + assert dollars.isdigit(), "\nThe dollar amount should be a number" + assert 0 <= int(dollars) <= 100, "\nThe dollar amount should be between 0 and 100" + assert 0 <= int(cents) <= 99, "\nThe cent amount should be between 0 and 99" + total = int(dollars) * 100 + int(cents) + + current = 0 + for name, plural_name, value in currency: + if total >= value: + count = total // value # find most whole number of currency that fits + total -= count * value # remove the amount of currency from the total + name = plural_name if count > 1 else name + print(f"{count} {name}") + current += count + +if __name__ == "__main__": + main(sys.argv[1:]) \ No newline at end of file diff --git a/problem2.js b/problem2.js new file mode 100644 index 0000000..3a263f3 --- /dev/null +++ b/problem2.js @@ -0,0 +1,31 @@ +var arguments = process.argv; +if (arguments.length < 3) { + console.log('ERROR: You must provide at least one string'); + return; +} +arguments = arguments.slice(2); +const word_map = new Map(); + +arguments.forEach((word) => { + // so I am considering what to do in the case where you have '“' or '”' in the word + // in your examples, 'Panda”' matched with panda despite the quotes + // this seems to go against 'A word is indicated by a sequence of characters separated by whitespace.' + // as ” is a character and not whitespace so it should be part of the word + + // I will follow the test cases and assume that the quotes are not part of the word + word = word.toLowerCase(); + word = word.replace(/[^a-zA-Z]/g, ''); + + if (word_map.has(word)) { + word_map.set(word, word_map.get(word) + 1); + } else { + word_map.set(word, 1); + } +}); + +word_map.forEach((value, key) => { + if (value > 1) { + console.log(key); + } +}); +//console.log(word_map); \ No newline at end of file diff --git a/styles.css b/styles.css new file mode 100644 index 0000000..9338e3a --- /dev/null +++ b/styles.css @@ -0,0 +1,19 @@ +body { + background: #346094; +} + +div.form +{ + text-align: center; + color: #b2b1b1; +} + + +input { + background-color: #8a8a8d; + color: #000; + font-size: xxx-large; + font-style: bold; + width: 80vh; + height: 23.33vh; +} diff --git a/website.html b/website.html new file mode 100644 index 0000000..11ec7c7 --- /dev/null +++ b/website.html @@ -0,0 +1,17 @@ + + + + + + https://webaim.org/resources/contrastchecker/ This is large text (i hope) + + +
+
+
+
+
+
+
+ + \ No newline at end of file From a9b88b73d5a599fce982dbf242ed08345b284dab Mon Sep 17 00:00:00 2001 From: Torchtopher Date: Tue, 13 Feb 2024 19:19:53 -0500 Subject: [PATCH 2/2] update with fixes --- INSTALL.md | 2 +- README.md | 2 ++ problem1.py | 21 ++++++++++++++++----- problem2.js | 49 +++++++++++++++++++++++++++++-------------------- styles.css | 2 +- website.html | 4 ++-- 6 files changed, 51 insertions(+), 29 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index c5ffe3f..a1ba71c 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -1 +1 @@ -### Installation Instructions:pgi \ No newline at end of file +### Installation Instructions: \ No newline at end of file diff --git a/README.md b/README.md index a98ac70..e01bc64 100644 --- a/README.md +++ b/README.md @@ -11,3 +11,5 @@ - https://brand.ncssm.edu/fonts-and-colors - https://stackoverflow.com/questions/15843391/div-height-set-as-percentage-of-screen - https://dequeuniversity.com/rules/axe/4.4/color-contrast +- https://www.w3schools.com/jsref/jsref_split.asp +- https://stackoverflow.com/questions/1374126/how-to-extend-an-existing-javascript-array-with-another-array-without-creating diff --git a/problem1.py b/problem1.py index d0583a4..5360fbb 100644 --- a/problem1.py +++ b/problem1.py @@ -1,12 +1,23 @@ import sys -def main(args): +def main(money_str): + """ + Prints out the minimum number of coins to make a dollar amount, i.e $4.42 + + Args: + money_str: A string of the form $X.YZ where X <= 100, and Y and Z are both integers 0 <= x <= 9 + + Returns: + None, has side effect of printing + + Raises: + AssertationError if input is not valid, may also exit + """ currency = [("dollar", "dollars", 100), ("quarter", "quarters", 25), ("dime", "dimes", 10), ("nickel", "nickels" , 5), ("penny", "pennies", 1)] - if len(args) != 1: + if len(money_str) != 1: print("Exactly one argument is required: usage `python problem1.py \$X.YZ`") - exit(-1) - money = args[0] + money = money_str[0] assert money[0] == '$', "\nThe input should start with a dollar sign. Make sure to escape this if on linux." dollars = money[1:] # remove $ dollars, cents = dollars.split('.') @@ -26,4 +37,4 @@ def main(args): current += count if __name__ == "__main__": - main(sys.argv[1:]) \ No newline at end of file + main(sys.argv[1:][0]) \ No newline at end of file diff --git a/problem2.js b/problem2.js index 3a263f3..c208804 100644 --- a/problem2.js +++ b/problem2.js @@ -1,31 +1,40 @@ -var arguments = process.argv; +let arguments = process.argv; if (arguments.length < 3) { console.log('ERROR: You must provide at least one string'); return; } arguments = arguments.slice(2); -const word_map = new Map(); +split_arguments = [] +for (let arg of arguments) { + // woah the "spead" operator is really neat + // split returns an array and ... (functionally) appends each element to split_arguments without another for loop + // probably equal to concat? this avoids a copy which totally doesn't matter here + split_arguments.push(...arg.split(" ")); +} -arguments.forEach((word) => { - // so I am considering what to do in the case where you have '“' or '”' in the word - // in your examples, 'Panda”' matched with panda despite the quotes - // this seems to go against 'A word is indicated by a sequence of characters separated by whitespace.' - // as ” is a character and not whitespace so it should be part of the word +// console.log(split_arguments); +// has key of lowercase word, value of [original case, number of occurances] +const word_map = new Map(); - // I will follow the test cases and assume that the quotes are not part of the word - word = word.toLowerCase(); - word = word.replace(/[^a-zA-Z]/g, ''); +for (let word of split_arguments) { + // console.log(word); + word_lower = word.toLowerCase(); - if (word_map.has(word)) { - word_map.set(word, word_map.get(word) + 1); - } else { - word_map.set(word, 1); + // only want to update occurances, not original case of word after we find a new word + if (!word_map.has(word_lower)) { + word_map.set(word_lower, [word, 1]); + } + else { + updated_count = word_map.get(word_lower); + updated_count[1] += 1 + word_map.set(word_lower, updated_count) } -}); +} +//console.log(word_map); -word_map.forEach((value, key) => { - if (value > 1) { - console.log(key); +for (let kv of word_map.entries()) { + occurances = kv[1]; + if (occurances[1] > 1) { + console.log(occurances[0]); } -}); -//console.log(word_map); \ No newline at end of file +} \ No newline at end of file diff --git a/styles.css b/styles.css index 9338e3a..4314469 100644 --- a/styles.css +++ b/styles.css @@ -14,6 +14,6 @@ input { color: #000; font-size: xxx-large; font-style: bold; - width: 80vh; + width: 80vw; height: 23.33vh; } diff --git a/website.html b/website.html index 11ec7c7..9863b35 100644 --- a/website.html +++ b/website.html @@ -3,14 +3,14 @@ - https://webaim.org/resources/contrastchecker/ This is large text (i hope) +


-
+