我试图在由 _ 和其他字母组成的字符串中生成输入字符的所有可能位置,其中输入字符只能替换 _ 表示的位置。
我到目前为止所做的代码在这里:
possibleNewWords currentString letterInput listOfPossibleStrings currentColumn iterations
| iterations == length currentString = removeDuplicates listOfPossibleStrings
| (currentColumn == length currentString) && (currentString!!iterations == '_') = possibleNewWords iteredString letterInput listOfPossibleStrings 0 (iterations+1)
| (currentColumn == length currentString) && (currentString!!iterations /= '_') = possibleNewWords currentString letterInput listOfPossibleStrings 0 (iterations+1)
| currentString!!currentColumn == '_' = possibleNewWords currentString letterInput (possibleStringNormal:listOfPossibleStrings) (currentColumn+1) iterations
| currentString!!currentColumn /= '_' = possibleNewWords currentString letterInput listOfPossibleStrings (currentColumn+1) iterations
where
possibleStringNormal = replaceInString currentColumn letterInput …Run Code Online (Sandbox Code Playgroud) 十个小时以来,我一直在尝试对这个字符串列表进行排序。这十个小时主要用于充实解决方法,但命运是残酷的,经过所有这些努力,我的解决方法仍然需要我对字符串列表进行排序而不考虑大小写。
我希望此函数执行的操作的示例:
Input: ["In", "Thats", "pLAIN"]
Output: ["In", "pLAIN", "Thats"]
Run Code Online (Sandbox Code Playgroud)
基本上我想对字符串进行排序,就好像它们都是小写一样,但保持输入的大小写
到目前为止我的代码:
--This function inserts the strings with capitals in them into the list of lower case only strings
--alphabetically
insertCapitals :: [String] -> [String] -> [String]
insertCapitals capitalList lowerList
--Base case
|capitalList == [] && lowerList == [] = []
--If the capital list is empty then append the rest of the lowerList
|capitalList == [] = (lowerListHead:insertCapitals capitalList tailedLowerList)
--If the lowerList is empty append the rest of …Run Code Online (Sandbox Code Playgroud)