Everybody knows that if you mix up letters in a word except the first and the last letter, you still will be able to read the word. Example: "Cmpuoter", "Adniord", "Wniodws"
But can you write code that will turn every word like this? I first tried this with c#, but then I realized how much it's difficult for such simple thing. Can you do it?
Just build a new string with randomized indexes from 1 to len-2 od the original word House 01234 Hsoue 03124
Nathan Gutierrez
holy shit what the fuck man, first of all, get the hell out of windows. second, C#? Really? you should really be able to do this in C in 5 minutes or less or you are a retard.
Zachary Johnson
>2+2 yeah bro me too
Oliver Jackson
well, you would need a large database of words for starters, then clever ways to optimize searches so you don't naively check every single word against the full database
note also that a large part of that ability in people comes from context in a sentence, and that's not easily replicated on a computer
Landon Fisher
We’re not doing your homework for you pajeet
Ayden Phillips
that's pretty easy to do with machine learning.
Brandon Ramirez
>muh-chine learning
Gabriel Walker
>how much it's difficult for such simple thing
Jaxson Thomas
Retard alert
Luis Campbell
>make a function that randomly picks two letters from a word, and if they're not the first or last characters, switches them around >repeat function multiple times >done I don't want to do your homework for you but it's really simple, especially in a language like C# where you have built in String functionality. Honestly, at this point, just give up on programming, or honestly anything remotely related to computers. Trust me bro. You won't find it fun, you won't find the environment fun, and it's a bubble that's gonna pop soon.
Nathaniel Anderson
I have no idea how (in)efficient this is or if there are any edge cases but it seems to work. Had to find a shuffle algorithm because surprisingly JS doesn't have one built-in
function shuffle(array) { var currentIndex = array.length, temporaryValue, randomIndex;
// While there remain elements to shuffle... while (0 !== currentIndex) {
// And swap it with the current element. temporaryValue = array[currentIndex]; array[currentIndex] = array[randomIndex]; array[randomIndex] = temporaryValue; }
return array; }
const words = "words that make sense when shuffled";
const mixedUpWords = words.split(' ').map(word => { const len = word.length; let split = word.split(''); const inner = split.slice(1, len - 1); for (let i = 1; i < len - 1; i++) { const innerLen = inner.length; const rand = Math.floor(Math.random() * ((innerLen - 2) - 1 + 1)) + 1; split[i] = inner[rand]; inner.splice(rand, 1); }
return split.join(''); });
console.log(mixedUpWords.join(' '));
Leo Allen
Write a custom class and overload the array access operator. You can find a way to generate a unique hash for the letters that are between the first and the last in the word irrespective of their order. This is just a fancy hashmap
Robert Bailey
Actually something seems wrong with this. Running it a few times I get wrdos taht mkae snsee wehn sulffehd wrdos taht mkae snsee wehn sfuflehd wrdos taht mkae snsee wehn slffuehd wrdos taht mkae snsee wehn sffluehd wrdos taht mkae snsee wehn sfuflehd wrdos taht mkae snsee wehn sulffehd wrdos taht mkae snsee wehn sulffehd wrdos taht mkae snsee wehn sffluehd wrdos taht mkae snsee wehn sffulehd wrdos taht mkae snsee wehn slfufehd wrdos taht mkae snsee wehn suflfehd only 'shuffled' ever changes which is a bit odd. Dunno why that is.
Samuel Price
this should do the job #include #include #include
using namespace std; int main(){ string line; while(getline(cin,line)){ auto wordstart=begin(line); bool inword=0; for(auto p=begin(line);p!=end(line);p++){ if(inword){ if(!isalpha(*p)){ //word ended if(p>wordstart+1) random_shuffle(wordstart+1,p-1); inword=0; } } else{ if(isalpha(*p)){ //word started inword=1; wordstart=p; } } } if(inword && end(line)>wordstart+1){ random_shuffle(wordstart+1,end(line)-1); } cout
Connor Howard
>I don't want to do your homework for you but it's really simple, especially in a language like C# where you have built in String functionality. >Honestly, at this point, just give up on programming, or honestly anything remotely related to computers. Trust me bro. You won't find it fun, you won't find the environment fun, and it's a bubble that's gonna pop soon. what a cunt telling people to quit while learning, lol doomer bitch
Ethan Cooper
>if they're not the first or last characters code monkey
William Jackson
({. , ({~ >:@?~@(-&2)@#) , {:)&.> ;: 'Programming is easy'
Prmraiomgngisesay
Joseph Wood
Here's a good start to structuring your solution.
class StringSegmentationProvider { public: virtual std::vector PerformStringSegmentationOnInputStringAndYieldResultAsVector(string inputString); }
class StringSegmentationProviderFactory () { public: virtual StringSegmentationProvider ProvideStringSegmentationProvider(); }
class WordPermutationProvider { public: virtual string PermuteWord(string inputWord); }
class WordPermutationProviderFactory { public: virtual WordPermutationProvider MakeWordPermutationProvider(); }
class StringRecombinator { public: virtual string RecombineVectorOfStringElementsYieldString(std::vector inputVectorOfStrings); }
class StringRecombinatorFactory () { public: virtual StringRecombinator CreateStringRecombinator(); }
Dylan Ortiz
Heres my shitty attempt, any tips appreciated: import random words = ['windows', 'android', 'computer']
>copying the fisher Yates algorithm and claiming it as your own without even modifying it to skip the 0 and last index of the array and making it a function on String.prototype