palindrome

How to pass an input string from user to a MIPS program

a 夏天 提交于 2021-02-05 11:14:06
问题 I'm trying to solve a problem to write assembly language program to detect if a phrase or characters entered by the user is a palindrome. I've gotten this far, and I believe everything should work, but I'm wondering how I can implement this so that it takes an actual word to test. When I run in MARS, there's simply no input option. .data string_space: .space 1024 is_palin_msg: .asciiz "The string is a palindrome.\n" not_palin_msg: .asciiz "The string is not a palindrome.\n" .text main: la $a0

read a local file in javascript and output certain lines from it

孤人 提交于 2021-01-27 18:49:57
问题 I am tasked with a little coding challenge that I can't seem to work out. Its meant to be done in javascript, a language I have touched in years... Basically the task is to read a local file , which has sentences on each line. Some of the sentences are palindromes- and the goal is to output only the sentences that are palindromes. I have tried playing around in JSFiddle with the following code. But, my functionality isn't working. HTML: <input type="file" name="file" id="file"> Javascript:

Counting Palindromes using recursion

三世轮回 提交于 2021-01-05 12:47:26
问题 I currently have a code which counts the palindromes in a given string and it was working fine till I tested it with "appal" the function returned 0 when it should return 2 (appa and pp) I would really appreciate it if someone can edit my current code so that it meets that requirement, thank you! Here's my code: function countPalindromes(string, count) { if (string.length <= 1) { return count; } let [ firstLetter ] = string; let lastLetter = string[string.length - 1]; if (firstLetter ===

How to count all the palindromes in a string using recursion?

寵の児 提交于 2020-12-11 06:01:23
问题 I have a recursive function that checks if a string is a palindrome, but my assignment asks me to count the number of palindromes in a string (for example kayak has 2). I'm really confused about how I can implement a recursive function that counts the number of palindromes. Here's my current code: function isPalindrome(string) { if (string.length <= 1) { return true; } let [ firstLetter ] = string; let lastLetter = string[string.length - 1]; if (firstLetter === lastLetter) { let

How to count all the palindromes in a string using recursion?

筅森魡賤 提交于 2020-12-11 06:01:22
问题 I have a recursive function that checks if a string is a palindrome, but my assignment asks me to count the number of palindromes in a string (for example kayak has 2). I'm really confused about how I can implement a recursive function that counts the number of palindromes. Here's my current code: function isPalindrome(string) { if (string.length <= 1) { return true; } let [ firstLetter ] = string; let lastLetter = string[string.length - 1]; if (firstLetter === lastLetter) { let

Recursive palindrome check with JavaScript

喜你入骨 提交于 2020-08-27 21:33:25
问题 I am trying to find out whether a string is a palindrome by recursion using javascript. But I can't figure out what I am missing in the code. var firstCharacter = function(str) { return str.slice(0, 1); }; var lastCharacter = function(str) { return str.slice(-1); }; var middleCharacters = function(str) { return str.slice(1, -1); }; var isPalindrome = function(str) { if(str.length < 2) { return true; } else { if(firstCharacter(str) == lastCharacter(str)) { isPalindrome(middleCharacters(str));

Recursive method for palindrome checkup

99封情书 提交于 2020-02-24 10:17:25
问题 Is it even possible to define a recursive method for palindrome checkup with the following argument list? int testPalindromeRecursive(char* str, int len) { ... } Note: no external sub-functions or global variables have to be used I think this is impossible, because you have to remember the last (front) index position somehow. 回答1: Yes, it is completely possible - as several people have mentioned. Base Cases: If len <= 1, return True If str[0] != str[len-1] return False Else: recurse with (str

Recursive method for palindrome checkup

牧云@^-^@ 提交于 2020-02-24 10:15:55
问题 Is it even possible to define a recursive method for palindrome checkup with the following argument list? int testPalindromeRecursive(char* str, int len) { ... } Note: no external sub-functions or global variables have to be used I think this is impossible, because you have to remember the last (front) index position somehow. 回答1: Yes, it is completely possible - as several people have mentioned. Base Cases: If len <= 1, return True If str[0] != str[len-1] return False Else: recurse with (str

Recursive method for palindrome checkup

我是研究僧i 提交于 2020-02-24 10:15:26
问题 Is it even possible to define a recursive method for palindrome checkup with the following argument list? int testPalindromeRecursive(char* str, int len) { ... } Note: no external sub-functions or global variables have to be used I think this is impossible, because you have to remember the last (front) index position somehow. 回答1: Yes, it is completely possible - as several people have mentioned. Base Cases: If len <= 1, return True If str[0] != str[len-1] return False Else: recurse with (str