anagram

Anagram / partial anagram detection algorithm finds incorrect answers

坚强是说给别人听的谎言 提交于 2019-12-12 10:22:18
问题 I've written the following method to find out whether a long word contains a shorter word, and the order in which I pass the letters appears to effect the outcome. I've noticed that if I feed it absconds and bassy it correctly reports NO , but if I alphabetize the letters and give it abcdnoss and abssy , it gives YES . I'm not too sure why this is – can anyone spot the issue? - (BOOL) does: (NSString* ) longWord contain: (NSString *) shortWord { while([longWord length] > 0 && [shortWord

Perfect/ideal hash to isolate anagrams

故事扮演 提交于 2019-12-11 19:19:09
问题 In an effort to accelerate fast-out behaviour on testing strings for anagrams, I came up with a prime-based hashing scheme -- although it looks like I wasn't the first. The basic idea is to map letters to prime numbers, and to compute the product of these primes. Any rearrangement of the letters will have the same product, and if the result can be arbitrarily large then no combination of other letters can produce the same result. I had initially envisioned this as just a hash. Eventually the

Large anagram search not reading to end of set Python

让人想犯罪 __ 提交于 2019-12-11 18:04:24
问题 I've got a piece of code here that checks anagrams of a long list of words. I'm trying to find out how to search through every word in my long word list to find other anagrams that can match this word. Some words should have more than one anagram in my word list, yet I'm unable to find a solution to join the anagrams found in my list. set(['biennials', 'fawn', 'unsupportable', 'jinrikishas', 'nunnery', 'deferment', 'surlinesss', 'sonja', 'bioko', 'devon'] ect... Since I've been using sets,

mysql: Anagram query to pull every possible word with any letters

旧城冷巷雨未停 提交于 2019-12-11 16:43:59
问题 I am in the middle of building my anagram query which is almost working great. Here is my sql The letters I am using are "settin?" The difference is the wildcard which I will allow the user to add a "?" into the field. SELECT `word`, 0+ABS(`e`-1)+ABS(`i`-1)+ABS(`n`-1)+ABS(`s`-1)+ABS(`t`-2) AS difference FROM `TWL06` WHERE LENGTH(`word`) <= 7 HAVING difference <= 1 My Table Structure is as word | a | b | c | d | e | f | g | h | i | j | k | l | m | n | o | p | q | r | s | t | u | v | w | x | y

How to count values in dictionary and print the key and value associated with the max amount

空扰寡人 提交于 2019-12-11 08:47:01
问题 I have created an anagram program that takes all words from a file and prints the letters followed by all of the words from the file that can be created using those letters. This is an example of what it prints out: cinos ['cions', 'coins', 'icons', 'scion', 'sonic'] Now that I have created an anagram program that has a dictionary with the random letters as keys and the anagrams as values, I want to find the group of letters(keys) that has the largest amount of anagrams(values) and print just

How can I get all the anagrams of a string

雨燕双飞 提交于 2019-12-11 05:25:42
问题 Im trying to find all the possible anagrams of a string and store them in an array using only recursion. Im stuck and this is all i have. int main() { const int MAX = 10; string a = "ABCD"; string arr[10]; permute(arr, a, 0, a.size(), 0); return 0; } void permute(string arr[], string wrd, int firstLetter, int lastLetter, int it) { if (firstLetter == lastLetter) *arr = wrd; else { swap(wrd[firstLetter], wrd[it]); permute(arr, wrd, firstLetter + 1, lastLetter, it++); } } The order doesnt matter

Find anagrams of a given word in a file

删除回忆录丶 提交于 2019-12-11 05:04:05
问题 Alright so for class we have this problem where we need to be able to input a word and from a given text file (wordlist.txt) a list will be made using any anagrams of that word found in the file. My code so far looks like this: def find_anagrams1(string): """Takes a string and returns a list of anagrams for that string from the wordlist.txt file. string -> list""" anagrams = [] file = open("wordlist.txt") next = file.readline() while next != "": isit = is_anagram(string, next) if isit is True

Looping in ArrayLists with a Method

耗尽温柔 提交于 2019-12-11 04:07:16
问题 With much assistance I have developed a method that makes anagrams and then adds them into an ArrayList . public void f(String s, String anagram, ArrayList<String> array) { if(s.length() == 0) { array.add(anagram); return; } for(int i = 0 ; i < s.length() ; i++) { char l = s.charAt(i); anagram = anagram + l; s = s.substring(0, i) + s.substring(i+l, s.length()); f(s,anagram,array); } } The problem is when I attempt to use this function to make ArrayList s in a loop that adds String s from one

Find if N strings are anagrams of each other

a 夏天 提交于 2019-12-11 03:38:42
问题 Basically I have a problem with 2 subquestions. First question is: Given 2 strings, determine if they are anagrams. Second is a bit harder. You have N strings and have to determine if those are anagrams of each other. I've solved the first one and I'll write the code below, but for the second one I have no idea. I was thinking it's possible to somehow do it by reading N strings from an array of strings, and then to use a for sequence to read each of them and compare them but I have no idea

Frama-C anagram function behavior verification

六月ゝ 毕业季﹏ 提交于 2019-12-11 03:32:08
问题 I wrote a C function that checks if two given strings (C-style) are anagrams or not. I try to verify it with Frama-C but it cannot validate the final behaviors of the function (other specifications are valid). The first one goes to timeout (even with very high timeout values in WP) and the second is unknown. Here is the code: #include <string.h> //@ ghost char alphabet[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x'