# "Backwards reader" program



## GSquadron (Apr 20, 2012)

Hi!
I created a stupid program and found it interesting.
So i thought to share!
It reads what you write and displays it on the screen backwards
For example:
tech
hcet
Have a look for yourself: 
http://www.mediafire.com/?67lkmi8rdaf7d72


----------



## Aquinus (Apr 20, 2012)

Aleksander Dishnica said:


> Hi!
> I created a stupid program and found it interesting.
> So i thought to share!
> It reads what you write and displays it on the screen backwards
> ...



Neat, but that is a toy. Ruby can do this in one line.


```
$ irb
>> "Some literal string".reverse!
=> "gnirts laretil emoS"
```


----------



## GSquadron (Apr 20, 2012)

lol nice 
How many bytes will that be? Just for curiosity


----------



## de.das.dude (Apr 20, 2012)

didnt you just use an array and reverse it


----------



## GSquadron (Apr 20, 2012)

No, i was practicing the for loop!


----------



## Kreij (Apr 20, 2012)

Alek got it right! It's not the simplicity of the concept it's the practice and making a program work, even a simple one, that gives you experience as a coder.
Good job, Alek and thanks for sharing.

Here's your next practice program (it's a classic from almost every programming class) ...
Write a little program that detects if an input string is a palindrome (reads the same forward and backward). It must detect capitalization and punctuation and handle it.

Example :
Input string : "Hello"
Output : "Hello" is not a palindrome"
Input string : "Hello olleH"
Output : "Hello olleH" is a palindrome.

You have ten minutes. GO !! lol

Part #2 : Make general adjustments for phrases.
Input : "do geese see god"
Ouput: "do geese see god" is a palindrome.


----------



## GSquadron (Apr 20, 2012)

Here is the code

```
for (int i = word.size() - 1; i >= 0; i--)
{
for (int j = 0; j >= word.size() - 1; j++)
{
    if(word.size(j) == word.size(i))
     cout << "palindrome";
    else
     cout << "not a palindrome";
}
}
```
And no more with the FOR CYCLE!!!


----------



## Kreij (Apr 20, 2012)

You didn't do part #2. No extra credit points for you !!


----------



## GSquadron (Apr 20, 2012)

what a joke... i was waiting for million dollar compensation....


----------



## Kreij (Apr 20, 2012)

Sounds good to me. I'm a little strapped for cash at the moment so I'll send 1 cent a day to your paypal account for the next 273,790.926 years. 

What's your next little practice project? Something with pointers perhaps?


----------



## GSquadron (Apr 20, 2012)

lol, oh well i am reading a book right now so even if i know the for, if, else and other things i must
read them. So the next project is already made 
Anyway it is not fun to share stupid projects, but this one made me laugh reading backwards!
It was like a game.
I am interested in solving the part 2 if you can help me of your question, cuz i dont know how to
do it.
[or even a program who reads backwards only if there are syllables]


----------



## Kreij (Apr 20, 2012)

The easiest way is to simply remove all the spaces from the string and then run the palidrome test loop.
Also, if the string is written backward, the same capitalization would apply to make it a correct phrase ("Do geese see God"), so you simply force the string into all lower (or upper) case characters before doing the test loop.


----------



## Aquinus (Apr 20, 2012)

Ruby impl.

```
some_string = "Do geese see God".upcase.gsub(/ /, "")
if some_string.eql?(some_string.reverse)
    p "is palindrome"
else
    p "is not palindrome"
end
```


----------



## librin.so.1 (Apr 20, 2012)

I did not find You mentioning what language You were using for this program. Since _on one other thread_ You mentioned trying to learn C++, I will assume that.

#1 can we get the source of that "backwards reader"? I would like to test it out, yet, am too lazy to run an .exe right now.

#2 I don't really get how Your palindrome detector works. Telling what data type "word" is and which size() You are using, would probably help a lot. (there is a whole lot of different implementationts of size() in C++, And, I don't remember a single one that would take any arguments. Hmmm...). (I suppose You would be using string for that word variable. Yet, I should not assume that.)


----------



## GSquadron (Apr 20, 2012)

#1 No

#2 string word;

@Aquinus
How bytes does your ruby program need?
Maybe 3 megs?


----------



## librin.so.1 (Apr 20, 2012)

That was very !(informative).    *sigh*   /______/

At least, care to explain how Your palindrome detector works?


----------



## de.das.dude (Apr 20, 2012)

i have a whole bunch of programs i made while learning C++.

throw a pm if you want them.

source codes are there.


----------



## Kreij (Apr 20, 2012)

Vinska said:


> That was very !(informative).    *sigh*   /______/
> 
> At least, care to explain how Your palindrome detector works?



He just tossed out code to appease me I think. 
It can't possibly work with the code he posted unless nested for loops work completely differntly on his machine.


----------



## GSquadron (Apr 20, 2012)

@kreij
I just gave an idea, just like your reply on my question was. I don't really know how to do it.
@Vinska
I didn't give anything cuz you said too lazy to run the .exe
And not lazy for the source code 
lol


----------



## librin.so.1 (Apr 20, 2012)

Kreij said:


> He just tossed out code to appease me I think.


That's what I thought at first. Yet since in any of Your following posts You did not note anything being wrong with that code, I got confused. =|



Kreij said:


> It can't possibly work with the code he posted unless nested for loops work completely differntly on his machine.



No kiddin'!
...along with: "and if he is also using some custom implementation of size()"


----------



## GSquadron (Apr 20, 2012)

The code is this one:

```
It was a 1-day trial anyway :)
```

But to tell you the truth, the real source code, is to learn like a PIG.
I mean, learn a lot and don't forget that everybody will use whatever they
can, distracting you from learning. The worst enemy is yourself.
It is not you who is learning, it is your mind. You just 'manipulate' your mind.
That is the real source code. At least, it works for me!


----------



## Kreij (Apr 20, 2012)

Umm ... Alek? The above code shouldn't even compile.
You get an input string.
Then run a for loop which contains a nested for loop with no execution block (so even if it did compile the for loops do nothing).
Then print out a pair of newlines before calling main again.

We aren't trying to distract you, we're trying to help you.
Just remember that if you are ever coding for a living, there are going to be all kinds of distractions to drive you nuts.


----------



## GSquadron (Apr 20, 2012)

Copy-Paste in again, i changed a line of code....
Also, want to point out that where i live, C++ is already dead.
So i code for nothing. At least, for now!


----------



## Kreij (Apr 20, 2012)

Alek said:
			
		

> Also, want to point out that where i live, C++ is already dead.



By that I assume you mean that companies in your area are not looking to hire C++ programmers.
What kind of coders are the companies in your area looking for?


----------



## de.das.dude (Apr 20, 2012)

Alek, to me the best way to learn was to think like the compiler. that way i can skip on algos and do the programs directly from though, then modify.

i know some ppl who learn it like hell. they lose the creativity :9


----------



## Kreij (Apr 20, 2012)

Here ya go , Alek. Palindrome code for a word or perfect palidrome phrase ...

```
string inputString;
bool IsPalindrome = true;

// Get input string however

for (int i = 0; i < intputString.Length(); i++)
{
    if (inputString[i] != inputString[(inputString.Length() - 1) - i]) 
    {
        IsPalindrome == false;
        break;
    }
}

if (!IsPalindrome)
{
   // output the it's not a palindrome
}
else // output that it is a palindrome
```





			
				d.d.d said:
			
		

> Alek, to me the best way to learn was to think like the compiler.


This is why coders have problems with relationships. The women keep feeding our "compilers" with ambiguous references and we keep getting unhandled exceptions.


----------



## GSquadron (Apr 20, 2012)

Thanks!
Oh well, in my country, you can find .net developers by microsoft. (fake one)
So C++ is for no job at all. Those who learnt programming languages, went outside
of the town to find a job. Maybe after 20 years, the situation will change.

EDIT: Still, coping and pasting your code on my compiler doesn't work!
Made mods, still doesn't....


----------



## Kreij (Apr 20, 2012)

I know what you mean. Here in my little community there are zero jobs for any kind of programmers as it's a rural area.
I would have to move to a city to get a coding job ... and I don't want to do that. I love the peace and solitude of the country life.
So I just keep learning and use what I learn to help others instead of to make money.
Probably why I'm broke.


----------

