[Community Puzzle] Logic gates

you got a ‘mdr’ from me for that :smiley:

4 Likes

Hello, I’m new here and I struggle to get the first answer, how am I supposed to change the strings inside the signals ?

I’m using this in the m loop but it doesn’t change the signal form :

if input_signal_1 == “A” and input_signal__2 ==“B”:
print(output_name, input_signal)

I’m willing to learn by myself and don’t find any good tips on google. thank you guys :blush:

What does your current code do? Can you describe it, like step by step? The code you have provided does not perform any string manipulation.

You can google “python strings tutorial” to get resources on how to manipulate strings.

1 Like

Well, my code is kind of empty, I’m still figuring out how to use those strings … Should I use an array list to classify each character ?

Thank you for the tip, I’ll check tutorials right now. :slight_smile:

It seems to me that arrays are seldom talked about in Python (except under libraries e.g. numpy). In my solution to this puzzle, I use a dictionary and lists.

need help, I’m still learning Python, don’t know what I need to do even for the first task :frowning:

Try other puzzles first. And if even other puzzles prove to be too difficult for you, you should consider learning more before coming back to CodinGame to practise.

I’ve done other puzzle on other language, I’m just new with Python.

and now I have other problem, after learning the code, I have trouble on storing data from the signal form input, when I use “append” it storing every char, not the whole signal form, how to store the whole signal?

What do you mean? If your code is able to store every character then the result should be the whole string / whole signal form? Any examples to illustrate your question?

I want to store the signal like this
__’

yesterday my code storing the signal like this
’, '’, ‘_’, ‘-’ , ‘-’, ‘-’, etc

and today my code working like it meant to be…

is there any other way I can store my signal?

If you split the input string once only, the signal string will not be further split into characters. For example, in the first test case, one of the input strings is:
A __---___---___---___---___
If you read that using this line of code:
signal_name, signal = input().split()
Then the results are:
signal_name stores the string of A
signal stores the string of __---___---___---___---___

Hi! While I do understand how to solve this challenge, I am not quite familiar with the input, output system. Im new to codingame, so any help would be appreciated.
Im in C btw, so can someone provide an example?

The default code reads all the inputs of a test case. For example, you can see this line in the default code:
scanf("%d", &n);
and it reads the first input “number of input signals” and stores it in the variable “n”.

Near the end of the default code you can see this line:
printf("output name and signal\n");
You will have to replace the contents of printf with your answer, and after testing/submitting your completed code, CodinGame will evaluate it against the expected answer.

Between the input code and the output code you should add your own code for processing the inputs to obtain the outputs.

Some more details may be found here: https://www.codingame.com/playgrounds/40701/help-center/inout-puzzles

To complete what 5DN1L said, you can imagine your program running in the console.
The datas in input are given by the user who run your program, so you read it with a scanf, and the data you have to give in output has to be shown in the console, so your print it with a prinf.

Very fun. I thought it was supposed to be XNOR instead of NXOR and that stumped me for a while because I didn’t check to see how it was actually spelled… lol

Let’s say you decide to store your input signals in the form of bools (true/false).
Make an array of arrays, or lists: List[] inputSignals = new List[n];
Each time you go through the for loop set the the inputSignals[i] to be that list of bools.

Very interesting, I have solved the puzzle (in C) implementing the logic gates like this:

        if (a[i] == '-' && b[i] == '-') {
            wf[i] = '-';
        }
        else {
            wf[i] = '_';
        }

But as soon as I try to make the code shorter by using a ternary operator, e.g.

        wf[i] = (a[i] == '-' && b[i] == '-') ? '-' : '_';

the code still works with all test cases, but the “Buffer (AND)” validator fails. :sweat_smile: Does anyone have any idea what could be happening here? Changing the code for AND or OR breaks this validator, the others don’t.

EDIT: I also tried out a custom test case with what I would expect a Buffer (AND) to be, namely

1
1
IN0
-_--__---___----____-_--__---___
OUT AND IN0 IN0

and it works without complaints. Super weird.

This was interesting, and made me pay more attention to bitwise operators and operations - thank you @B0n5a1 for making this available to us! :+1:

After almost a week, I figured out how to write the code so the first testcase pass…
However, in the second testcase… I’m getting a IndexOutOfRangeException
checking and rechecking the code, I still have no clue why I’m getting the error…
(I made a outs[m,4] to store the values of the second loop and that runs fine.
But when I get to the final loop, the error appears even I put the values manually…

Try adding some debug prints to check (a) the length/size of the string/list/array/container and (b) which index you’re checking. The index is probably smaller than the lower bound or greater than the upper bound of the string/list/array/container.