diff options
| author | Alexander Pickering <alex@cogarr.net> | 2020-01-01 22:37:37 -0500 |
|---|---|---|
| committer | Alexander Pickering <alex@cogarr.net> | 2020-01-01 22:37:37 -0500 |
| commit | 9fae5d516012e2c0802105e67c79e2587a22b9dc (patch) | |
| tree | 1c782ad2cd08bd1ecc4f0b42bd042778b4f34c2e /hw5 | |
| download | infsci2620-9fae5d516012e2c0802105e67c79e2587a22b9dc.tar.gz infsci2620-9fae5d516012e2c0802105e67c79e2587a22b9dc.tar.bz2 infsci2620-9fae5d516012e2c0802105e67c79e2587a22b9dc.zip | |
Diffstat (limited to 'hw5')
| -rw-r--r-- | hw5/2620.HW05.Python.docx | bin | 0 -> 62269 bytes | |||
| -rw-r--r-- | hw5/hw5.lua | 39 | ||||
| -rw-r--r-- | hw5/hw5.moon | 38 | ||||
| -rw-r--r-- | hw5/hw5.zip | bin | 0 -> 62526 bytes | |||
| -rw-r--r-- | hw5/res/1.PNG | bin | 0 -> 59094 bytes |
5 files changed, 77 insertions, 0 deletions
diff --git a/hw5/2620.HW05.Python.docx b/hw5/2620.HW05.Python.docx Binary files differnew file mode 100644 index 0000000..01c5710 --- /dev/null +++ b/hw5/2620.HW05.Python.docx diff --git a/hw5/hw5.lua b/hw5/hw5.lua new file mode 100644 index 0000000..b1fa6f3 --- /dev/null +++ b/hw5/hw5.lua @@ -0,0 +1,39 @@ +local accept_input = io.read +local split_string +split_string = function(s) + local _accum_0 = { } + local _len_0 = 1 + for x in string.gmatch(s, "(%S+)") do + _accum_0[_len_0] = x + _len_0 = _len_0 + 1 + end + return _accum_0 +end +local capitalize_word +capitalize_word = function(word) + return string.gsub(word, "^(.)", string.upper) +end +local uppercase_words +uppercase_words = function(array) + local _accum_0 = { } + local _len_0 = 1 + for _index_0 = 1, #array do + local word = array[_index_0] + _accum_0[_len_0] = capitalize_word(word) + _len_0 = _len_0 + 1 + end + return _accum_0 +end +local print_words +print_words = function(array) + for _index_0 = 1, #array do + local word = array[_index_0] + print(word) + end +end +local sort_words = table.sort +local sentence = accept_input() +local words = split_string(sentence) +words = uppercase_words(words) +sort_words(words) +return print_words(words) diff --git a/hw5/hw5.moon b/hw5/hw5.moon new file mode 100644 index 0000000..142625c --- /dev/null +++ b/hw5/hw5.moon @@ -0,0 +1,38 @@ +--Homework 5, Alexander Pickering (amp215@pitt.edu) +-- +-- Moonscript! +-- $ apt-get install lua5.3 lua5.3-dev luarocks +-- $ luarocks install moonscript +-- +-- You can then run this file with +-- $ moon hw5.moon + +accept_input = io.read + +--seperate things that are one or more non-space characters +--https://www.lua.org/manual/5.3/manual.html#6.4.1 +split_string = (s) -> [x for x in string.gmatch(s,"(%S+)")] + +--apply string.upper() to the first character in a word +capitalize_word = (word) -> string.gsub(word,"^(.)",string.upper) + +--uppercase words in an array +uppercase_words = (array) -> + [capitalize_word(word) for word in *array] + +--print all the words in an array +print_words = (array) -> + for word in *array do + print(word) + +--Built in sorting! +sort_words = table.sort + +--If a function has no arguments, it can be called using the ! operator, instead of empty parentheses. The ! invocation is the preferred way to call functions with no arguments. +sentence = accept_input! + +words = split_string(sentence) +words = uppercase_words(words) +sort_words(words) + +print_words(words) diff --git a/hw5/hw5.zip b/hw5/hw5.zip Binary files differnew file mode 100644 index 0000000..7626d51 --- /dev/null +++ b/hw5/hw5.zip diff --git a/hw5/res/1.PNG b/hw5/res/1.PNG Binary files differnew file mode 100644 index 0000000..2a04d48 --- /dev/null +++ b/hw5/res/1.PNG |
