[challenge] Code in another language challenge!

@jibblyj: Yes, that’s right! But you should only add even numbers, forget about the odd ones.
And yes, that can be in JS haha
@grisful: Oh, really? So maybe you should code to check if the person’s name starts with a vowel in C++, how about that?
My fellow C++ programmer :smiley:

1 Like

I’ll never be able to more than read it, Gabriel, but how would you port this,

Ruby FizzBuzz to C++?

def fizzbuzz(limit)
  (1..limit).each do |i|
    puts case 0
      when i % 15
        "FizzBuzz"
      when i % 3
        "Fizz"
      when i % 5
        "Buzz"
      else
        "#{i.to_s}"
    end
  end
end
fizzbuzz(20)
Edit: > I'll never be able to more than read it

I take that back. Zeke’s post below opens a door.

1 Like

@g4be Tada!

It took me a lot longer than it would’ve in Python or JavaScript, because I’ve never done anything with C++, but it works! :slight_smile:

3 Likes

Thanks for the example of <details><summary>...</summary><pre>code</pre></details>. Really nice touch.

Hm… who do i give the challenge? If it is too complex, let me know. I think Ceaser cipher is a nice challenge, the language? C

Who want to take that challenge and has one for me?

@mtf:
In C++ we have three types of looping instructions:
1 - for:

for (initialValues; condition; increment or decrement){ #Your code here! }

2 - while::

while(condition){ #Your code here! }

3 - do - while:

do{ #Your code here! }while(condition)
And the conditional statements are more “basic”, comparing with the other:
1 - if:

if(condition){ #Your code here!}
2 - else:

#In C++ you can't have an else after a for loop, like we have in Python, only an **if** else { #Your code here! }

The other things such as the module operator and the comparision are the same in Ruby :slightly_smiling:

@zystvan: That looks really nice, congrats!

@stetim94: In C? Hmm, okay! I’ll give it a try! I understood the idea of it and will try to do!
And for you, how about compute Pascal’s Triangle in C++?
You’ll need to print it! But if this is too complex, let me know and I’ll change!

1 Like

I’ll give this a shot, prefer something more basic-ish. pretty bad at python and ruby. never touched c/c++

@benjnev: There’s no need to be afraid, trust me.

Make a code where a user will try to guess the word, where you can decide what this word will be, and give the user three chances to do it.
Try to code it in Python.

If that’s too complex, let me know and I’ll change!

I will give it a shot, but i can only print hello world in c++, so lets see how far i can get. Okay, that is going to be tricky, but a fun challenge

Haha, I’m glad you liked it :smiley:
If it turns out to be complicated in C++, try in Python or Ruby.
I know you can program in those languages as well.

Ruby has a been while, but yes, python and ruby this challenge is fun, but i want to try c++, additional challenge, i will learn something about c++, is this an okay c++ tutorial?

I have no idea where to even start, I know it uses raw_input somewhere but not a clue, was disappointed I couldn’t even get it to work in js… :frowning:

@benjnev: Oh, that’s okay! So make a program in Python where you’ll get two numbers from the user, add them and print the result of it to you!

@stetim94: That’s a good one! Let me know what you think about it.
About your challenge: it’s being really fun! Been writing a few things on the paper to later use it.
Will post it soon!

Thank you, for letting me know that is a good resource. I am very curious how your solution is going to look, i am not really far with your challenge, but i really enjoy your challenge, i will let you know as soon as i have an answer :slight_smile:

1 Like

I had to cheat a bit, because I couldnt get %s (num1, num2, answer) to work, so I swapped it out for {0} {1} {2} even though I’ve never seen that before or the use of .format

Here it is anyway

What’s some good places to learn python, and the benefits of it?

Your code is correct and I have to say I’ve never seen this kind of print statement, that’s interesting.
You were actually supposed to add the numbers, which I thought would be integers/floats, but that works.

Good places to learn Python? Well, there are many!
Codecademy is a really good place.

I’d recommend for other friends who would like to learn Python, for free, here!
Of course there are websites, tutorials and stuff but here is a good place and the best thing of all is that whenever you have doubts about something on the language, you can post on the forums and someone will show up and give you some help :slightly_smiling:

And the benefits of it? There are quite many.
Here’s a list of some of them:

  1. Easy Syntax
  2. Readability
  3. High-Level Language
  4. Object oriented programming
  5. It’s Free
  6. Cross-platform
  7. Widely Supported
  8. It’s Safe
  9. Batteries Included
  10. Extensible

There’s a good explanation here!

Q: Okay but where do we use it?
A: Where is Python used?

Q: Are the areas that use such language good ?
A: Yes, they are! Cryptography is one of them :slightly_smiling:

Know that any language by itself isn’t “strong enough” but when you combine with another one, you’ll see how great it will become!
My personal experience was Python with SQL and WOW, it was amazing! Hard, at the beginning, but got used to it.

The key about learning something, in our case programming language, is to never give up. Whenever you wrote something and you got the incorrect output, instead of thinking how bad, stupid or dumb you are, think on how smart you are to find a way that isn’t correct so you won’t do it again, how about that? :slightly_smiling:

2 Likes

@zystvan: I was busy with my internship and other courses I’m attending so I took way more time to do this code than I expected haha
But here is it:

#include <iostream>
#include <string>

void caesarsCypher(char * pt, int quantShift);

int main(void){
    char myArray[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', 'Y', 'Z'};
    int positionsToShift = 0;
    std::cout<<"Inform the quantity of shifts:";
    std::cin>> positionsToShift;
    std::cout<<"Shifts:" << positionsToShift;
    std::cout<<std::endl;
    std::cout << "Entry: ";
    for(int i = 0; i < 26; i ++){
        std::cout<< myArray[i];
    }
    caesarsCypher(myArray, positionsToShift);
}

void caesarsCypher(char *pt, int quantShift){
    char auxArray[26] = {'0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0'};
    int value = 0;
    for(int i = 0; i < 26; i ++){
        switch (pt[i]) {
        case 'A':
            value = 0;
            break;
        case 'B':
            value = 1;
            break;
        case 'C':
            value = 2;
            break;
        case 'D':
            value = 3;
            break;
        case 'E':
            value = 4;
            break;
        case 'F':
            value = 5;
            break;
        case 'G':
            value = 6;
            break;
        case 'H':
            value = 7;
            break;
        case 'I':
            value = 8;
            break;
        case 'J':
            value = 9;
            break;
        case 'K':
            value = 10;
            break;
        case 'L':
            value = 11;
            break;
        case 'M':
            value = 12;
            break;
        case 'N':
            value = 13;
            break;
        case 'O':
            value = 14;
            break;
        case 'P':
            value = 15;
            break;
        case 'Q':
            value = 16;
            break;
        case 'R':
            value = 17;
            break;
        case 'S':
            value = 18;
            break;
        case 'T':
            value = 19;
            break;
        case 'U':
            value = 20;
            break;
        case 'V':
            value = 21;
            break;
        case 'W':
            value = 22;
            break;
        case 'X':
            value = 23;
            break;
        case 'Y':
            value = 24;
            break;
        case 'Z':
            value = 25;
            break;
        default:
            break;
        }
        int aux = (value + quantShift) % 26;
        auxArray[aux] = pt[i];
    }
    std::cout<<std::endl;
    std::cout<<"Output: ";
    std::cout<<std::endl;
    for(int j = 0; j < 26; j ++){
        std::cout << auxArray[j];
    }

}

Not sure who’s next though.

1 Like

@g4be Nice!
I think it was @stetim94 who wanted you to do the Cesar Cypher, though :slight_smile:

1 Like

@zystvan: Oh, really? Well he can do it in Python or Ruby, no problem at all haha
It was really fun!

1 Like

Off topic…

Shifts:2
Entry: ABCDEFGHIJKLMNOPQRSTUVWXYZ
Output: 
UVWXYZABCDEFGHIJKLMNOPQRST   
/usr/lib/gcc/x86_64-openwrt-linux-uclibc/4.8.3/crt1.o: In function `_start':
(.text+0x12): undefined reference to `main'
collect2: error: ld returned 1 exit status

exit status 1
1 Like