Wrod Jbmlue

Aoccdrnig to a rscheearch at Cmabrigde Uinervtisy, it deosn’t mttaer in waht oredr the ltteers in a wrod are, the olny iprmoetnt tihng is taht the frist and lsat ltteer be at the rghit pclae. The rset can be a toatl mses and you can sitll raed it wouthit porbelm. Tihs is bcuseae the huamn mnid deos not raed ervey lteter by istlef, but the wrod as a wlohe.

Tihs is iertiesnntg if you h'venat seen it bfoere.
Try writing source code this way and see how readable it is.
You should definitely define all your keywords like that

1
2
3
4
#define srtnig  string
#define cahr    char
#define igetenr int
#define vtoecr  vector 


confuse the heck out of anyone perusing your code.
I hvae seen taht bfroee, but it olny wkors if you raed it fsat, whiutot cnairg too mcuh aoubt the wrods
1
2
3
4
typedef std::string sitnrg;
typedef char        cetaarhcr;
typedef int         igeetnr;
typedef double      dbolue;
Last edited on
You should definitely define all your keywords like that

Indeed. And you should define every possible variant so that flaot, falot, faolt, foalt, folat and float can all be used in the same code. It shouldn't be a problem to write a program to generate headers with such definitions. Or even better a preprocessor that would take all these words and convert them to a format in which they are all the same.
I see a bright future ahead of us..
Just because I can:
EDIT, Fixed small errors.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include <ctime>
#include <vector>
#include <string>
#include <fstream>
#include <iostream>
#include <iterator>

#include <boost/random/uniform_int.hpp>
#include <boost/random/mersenne_twister.hpp>
#include <boost/random/variate_generator.hpp>

// Global Gen Var
boost::mt19937 gen;

// Prototype
int rand (int, int);
void get_words (std::vector<std::string> &);
void jumble (std::vector<std::string> &);
  void jumble (std::string &);
  void swap (char &, char &);
void print (const std::vector<std::string> &);


int main ()
{
  gen.seed( (unsigned)std::time(0) );

  std::vector<std::string> sentence;
  get_words(sentence);
  jumble(sentence);
  print(sentence);
}

int rand(int min, int max)
{
  boost::uniform_int<> dist(min, max);
  boost::variate_generator< boost::mt19937&, boost::uniform_int<> > rnd(gen, dist);
  return rnd();
}

void get_words (std::vector<std::string> &words)
{
  std::ifstream fin("jumble.txt");
  if (!fin)
  {
    std::cerr << "Cannot find file \'jumble.txt\'. Please check directory.";
    //throw std::invalid_argument;
  }

  std::string temp;
  while ( fin >> temp )
  {
    words.push_back(temp);
  }

  fin.close();
  return;
}

void jumble (std::vector<std::string> &words)
{
  for (std::vector<std::string>::iterator it = words.begin();
        it != words.end(); ++it)
  {
    if (it->length() > 2)
      jumble(*it);
  }

  return;
}

void jumble (std::string &str)
{
  for (size_t i = 0; i < str.length()-1; ++i)
  {
    size_t k = rand(1, str.length()-2), j = rand(1, str.length()-2);
    if ( k != j )
      swap(str[k], str[j]);
  }

  return;
}

void swap(char &a, char &b)
{
  char temp = a;
  a = b;
  b = temp;

  return;
}

void print (const std::vector<std::string> &words)
{
  std::ostream_iterator<std::string> out_it (std::cout, " ");
  std::copy ( words.begin(), words.end(), out_it );

  return;
}
Last edited on
Now we just need a program to jumble its own source code. :-)
I see a bright future ahead of us..


Oh fine, be pessimistic ;)

Perhaps he should just make his own jumbled IDE? Call it jIDE? Maybe he should swap around his ascii codes, you know make it reeeeaaaly confusing? Or even better he should just parse only the first and last letter of every keyword so you can literally type anything as long as the first and last letters were the same? Do you see your world darkening by the poorly worded suggestion?
Or even better a preprocessor that would take all these words and convert them to a format in which they are all the same.
if(s.size()>1) std::sort( s.begin()+1, s.end()-1 );
I love where this thread is going :P
Topic archived. No new replies allowed.