UW Writing a Function Crossfit that Consumes Two Strings Project
Need help with this assignment?Get an original answer from a qualified tutor — from $10/page.
Get it written →Two words can fit together orthogonally so long as there is a common character shared between them. This is useful for word games like crossword puzzles or Scrabble. For example, "tomato" and "camel" can cross at either the m or the a. We wish to find out all these crossing points
Write a function crossfit that consumes two strings, word1 and word2, and produces a list of pairs of numbers, representing all the places where these two words can cross. Specifically, if the pair (list p q) is in your produced list, it indicates that the character at position p in word1 matches the character at position q in word2. You may assume that the strings are composed entirely of lowercase alphabetic characters. The list of pairs should be produced in increasing order by the first element of the pair, breaking ties by increasing order of the second element of the pair: see the second example
.> (crossfit “tomato” “camel”)
(list (list 2 2) (list 3 1))
> (crossfit “folly” “mulled”)
(list (list 2 2) (list 2 3) (list 3 2) (list 3 3))
> (crossfit “foil” “paper”)
empty
There are several different approaches to solve this question. One approach is to recurse on the rest of one list, and adjust the recursive result to account for the fact that the first letter of that list has been removed. Another approach is to transform each letter in a list to a two-element list involving the letter and its position in the list. A third approach is to keep track of the “current position” in the list in a parameter to a function, and update that parameter in a natural way as the list is being processed. You may find a different approach as well.
You must not use boolean=?, substring or string-ith. Write the code in race beginner level with list abbreviations. DO NOT USE FUNCTIONS LIKE MAP, FILETER, APPLY AND LABDA IN THE CODE. USE SIMPLE RECURSIVE FUNCTIONS AND FOR EACH HELPER FUNCTIONS USED IN THE CODE GIVE A FEW CHEC-EXPECTS AND THE CONTRACT FOR THE CODE.
Get a plagiarism-free answer to this question
Send us your instructions and we’ll match you with the best writer in your subject.
- 100% human-written, zero AI
- Turnitin report included
- Confidential — we never share your data
- Free revisions & refunds
