Everybody knows that if you mix up letters in a word except the first and the last letter...

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?

Attached: 1.png (519x483, 6K)

Other urls found in this thread:

ellie-app.com/4CMXp97SVLNa1
code.jsoftware.com/wiki/Guides/GettingStarted
twitter.com/SFWRedditVideos

Just build a new string with randomized indexes from 1 to len-2 od the original word
House 01234
Hsoue 03124

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.

>2+2
yeah bro me too

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

We’re not doing your homework for you pajeet

that's pretty easy to do with machine learning.

>muh-chine learning

>how much it's difficult for such simple thing

Retard alert

>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.

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) {

// Pick a remaining element...
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex -= 1;

// 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(' '));

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

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.

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

>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

>if they're not the first or last characters
code monkey

({. , ({~ >:@?~@(-&2)@#) , {:)&.> ;: 'Programming is easy'

Prmraiomgngisesay

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();
}

Heres my shitty attempt, any tips appreciated:
import random
words = ['windows', 'android', 'computer']

def scramble(word):
middle = list(word[1:][:-1])
random.shuffle(middle)
middle = ''.join(middle)

return "{}{}{}".format(word[0], middle, word[-1])

for word in words:
print(scramble(word))

4chin ate my unicode :(

Attached: 2019-02-02-151728_1920x1080_scrot.png (400x84, 4K)

list(word[1:][:-1])

you can slice both ends at once
list(word[1:-1])

or [*word[1:1]]

if you want your code shorter, but more cryptic.
also scramble doesn't work as expected for single letter words.

Solved it in Elm:
ellie-app.com/4CMXp97SVLNa1

shuffle : Seed -> String -> String
shuffle seed input =
let
words =
String.split " " input

( newSeed, shuffledWords ) =
List.foldr
(\word ( s, acc ) ->
let
( w, s2 ) =
shuffleWord s word
in
( s2, w :: acc )
)
( seed, [] )
words
in
String.join " " shuffledWords


shuffleWord : Seed -> String -> ( String, Seed )
shuffleWord seed word =
let
( a, b, c ) =
splitMiddle word

( middle, s ) =
Random.step (Random.shuffle (String.toList b)) seed
in
( a ++ String.fromList middle ++ c, seed )


splitMiddle : String -> (String, String, String)
splitMiddle s =
( String.left 1 s, String.slice 1 -1 s, String.right 1 s )

wot language?

J
code.jsoftware.com/wiki/Guides/GettingStarted

Is this the new "do my homework" general?

Topkek

>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