Difference between revisions of "Card Game Assignment"

From CSE425S Wiki
Jump to navigation Jump to search
Line 19: Line 19:
  
 
==first-name substitutions==
 
==first-name substitutions==
1. This problem involves using first-name substitutions to come up with alternate names. For example,
+
This problem involves using first-name substitutions to come up with alternate names. For example,
Fredrick William Smith could also be Fred William Smith or Freddie William Smith. Only part (d) is
+
Fredrick William Smith could also be Fred William Smith or Freddie William Smith. Only [[similar_names|similar_names]] is
 
specifically about this, but the other problems are helpful.
 
specifically about this, but the other problems are helpful.
 
===all_except_option===
 
===all_except_option===
(a) Write a function all_except_option, which takes a string and a string list. Return NONE if the
+
Write a function all_except_option, which takes a string and a string list. Return NONE if the
 
string is not in the list, else return SOME lst where lst is identical to the argument list except the string
 
string is not in the list, else return SOME lst where lst is identical to the argument list except the string
 
is not in it. You may assume the string is in the list at most once. Use same_string, provided to you,
 
is not in it. You may assume the string is in the list at most once. Use same_string, provided to you,
Line 29: Line 29:
  
 
===get_substitutions1===
 
===get_substitutions1===
(b) Write a function get_substitutions1, which takes a string list list (a list of list of strings, the
+
Write a function get_substitutions1, which takes a string list list (a list of list of strings, the
 
substitutions) and a string s and returns a string list. The result has all the strings that are in
 
substitutions) and a string s and returns a string list. The result has all the strings that are in
 
some list in substitutions that also has s, but s itself should not be in the result. Example:
 
some list in substitutions that also has s, but s itself should not be in the result. Example:
Line 43: Line 43:
  
 
===get_substitutions2===
 
===get_substitutions2===
(c) Write a function get_substitutions2, which is like get_substitutions1 except it uses a tail-recursive
+
Write a function get_substitutions2, which is like get_substitutions1 except it uses a tail-recursive
 
local helper function.
 
local helper function.
  
 
===similar_names===
 
===similar_names===
(d) Write a function similar_names, which takes a string list list of substitutions (as in parts (b) and
+
Write a function similar_names, which takes a string list list of substitutions (as in [[get_substitutions1|get_substitutions1]] and
(c)) and a full name of type {first:string,middle:string,last:string} and returns a list of full
+
[[get_substitutions2|get_substitutions2]]) and a full name of type {first:string,middle:string,last:string} and returns a list of full
 
names (type {first:string,middle:string,last:string} list). The result is all the full names you
 
names (type {first:string,middle:string,last:string} list). The result is all the full names you
 
can produce by substituting for the first name (and only the first name) using substitutions and parts (b)
 
can produce by substituting for the first name (and only the first name) using substitutions and parts (b)
Line 60: Line 60:
 
Do not eliminate duplicates from the answer. Hint: Use a local helper function. Sample solution is
 
Do not eliminate duplicates from the answer. Hint: Use a local helper function. Sample solution is
 
around 10 lines.
 
around 10 lines.
 
  
 
=Pledge, Acknowledgments, Citations=
 
=Pledge, Acknowledgments, Citations=
 
{{Pledge|lab-2-card-game-date}}
 
{{Pledge|lab-2-card-game-date}}

Revision as of 02:17, 29 September 2020

Instructions

UW or Coursera

Hints and Gotchas

Code To Implement

You will write 11 SML functions (not counting local helper functions), 4 related to “name substitutions” and 7 related to a made-up solitaire card game.

Your solutions must use pattern-matching. You may not use the functions null, hd, tl, isSome, or valOf, nor may you use anything containing a # character or features not used in class (such as mutation). Note that list order does not matter unless specifically stated in the problem.


The sample solution, not including challenge problems, is roughly 130 lines, including the provided code.

Do not miss the “Important Caveat” and “Assessment” after the “Type Summary.”

first-name substitutions

This problem involves using first-name substitutions to come up with alternate names. For example, Fredrick William Smith could also be Fred William Smith or Freddie William Smith. Only similar_names is specifically about this, but the other problems are helpful.

all_except_option

Write a function all_except_option, which takes a string and a string list. Return NONE if the string is not in the list, else return SOME lst where lst is identical to the argument list except the string is not in it. You may assume the string is in the list at most once. Use same_string, provided to you, to compare strings. Sample solution is around 8 lines.

get_substitutions1

Write a function get_substitutions1, which takes a string list list (a list of list of strings, the substitutions) and a string s and returns a string list. The result has all the strings that are in some list in substitutions that also has s, but s itself should not be in the result. Example: get_substitutions1([["Fred","Fredrick"],["Elizabeth","Betty"],["Freddie","Fred","F"]], "Fred") (* answer: ["Fredrick","Freddie","F"] *) Assume each list in substitutions has no repeats. The result will have repeats if s and another string are both in more than one list in substitutions. Example: get_substitutions1([["Fred","Fredrick"],["Jeff","Jeffrey"],["Geoff","Jeff","Jeffrey"]], "Jeff") (* answer: ["Jeffrey","Geoff","Jeffrey"] *) Use part (a) and ML’s list-append (@) but no other helper functions. Sample solution is around 6 lines.

get_substitutions2

Write a function get_substitutions2, which is like get_substitutions1 except it uses a tail-recursive local helper function.

similar_names

Write a function similar_names, which takes a string list list of substitutions (as in get_substitutions1 and get_substitutions2) and a full name of type {first:string,middle:string,last:string} and returns a list of full names (type {first:string,middle:string,last:string} list). The result is all the full names you can produce by substituting for the first name (and only the first name) using substitutions and parts (b) or (c). The answer should begin with the original name (then have 0 or more other names). Example: similar_names([["Fred","Fredrick"],["Elizabeth","Betty"],["Freddie","Fred","F"]], {first="Fred", middle="W", last="Smith"}) (* answer: [{first="Fred", last="Smith", middle="W"}, {first="Fredrick", last="Smith", middle="W"}, {first="Freddie", last="Smith", middle="W"}, {first="F", last="Smith", middle="W"}] *) Do not eliminate duplicates from the answer. Hint: Use a local helper function. Sample solution is around 10 lines.

Pledge, Acknowledgments, Citations

file: lab-2-card-game-date-pledge-acknowledgments-citations.txt

More info about the Honor Pledge