3
\$\begingroup\$

Your goal is to create a program. It must take input indefinitely.

Here is a sample run (the > shows that the line is the output from the program)

2,6
> 0
5,6
> 0
7,5
> 0
2,7
> 1

Since 2 is connected to 6, which in turn is connected to 5 and then 7, 2 and 7 are hence connected.

5,2
> 1

...

Clarifications

Whenever the user writes any two numbers (separated by any delimiter you prefer), the program must output whether they are connected or not. If they are not connected, the program must output a falsy value (0), however if the wires are connected, the program must output a true value (1).

"We are to interpret the pair p-q as meaning “p is connected to q.” We assume the relation “is connected to” to be transitive: If p is connected to q, and q is connected to r, then p is connected to r."

The input must be separated from the output by a newline \n

The input will always be integers in base ten and never floats.

This is , so the program with the shortest bytecount wins!

\$\endgroup\$
23
  • 1
    \$\begingroup\$ It's not very clear how the program is supposed to work. How exactly do we connect wires? \$\endgroup\$
    – DJMcMayhem
    Dec 5, 2016 at 16:10
  • \$\begingroup\$ Its up to you? The user will enter the Input part i just wrote above, and the program should output whether the wires are already connected or they aren't. \$\endgroup\$
    – Silidrone
    Dec 5, 2016 at 16:12
  • 1
    \$\begingroup\$ @KritixiLithos Yes i would really appreciate that. Please edit it so it is clearer. \$\endgroup\$
    – Silidrone
    Dec 5, 2016 at 16:18
  • 1
    \$\begingroup\$ I still see a few problems. 1. There is a self-contradiction in giving > The wires were not connected. Connecting them... as an example of a falsy value. 2. The assumption of transitivity is not sufficient to make the sample run correct. It requires also assuming symmetry. It is not clear whether in addition you expect answers to assume reflexivity. 3. The requirement to separate input from output by a newline seems to assume stdio, but there is no explicit requirement to use stdio. 4. Numbers in base 10 are decimals, so "integers in base ten and never decimals" is self-contradictory. \$\endgroup\$ Dec 5, 2016 at 16:48
  • 2
    \$\begingroup\$ Note that after editing this is likely also to be a borderline dupe of codegolf.stackexchange.com/q/69926/194 and/or codegolf.stackexchange.com/q/8647/194 \$\endgroup\$ Dec 5, 2016 at 16:49

0

Browse other questions tagged or ask your own question.