This is a challenge developed for the C# discord server.
Want to Participate? Join the C# discord:
You are writing a software that allows users to design electrical circuits. You need to add a feature
that will count the number of loose wire ends in the current design. The wire layout data is currently
stored in a string
with the characters
, ║
, ╠
, ╩
, ╦
, ═
, ╬
, ╣
, ╚
, ╝
, ╔
, ╗
, and \n
.
The \n
character represents the end of the current horizontal dimension, the ' '
character represents a
coordinate with no wires, and the rest ║ ╠ ╩ ╦ ═ ╬ ╣ ╚ ╝ ╔ ╗
represent various wire configurations.
string input =
"╔══╗\n" +
"║╚╝║\n" +
"║╔╗║\n" +
"╚══╝";
// contains 4 disconnected wire ends
string input =
"║╔╗║\n" +
"║║║║\n" +
"║║║║\n" +
"╚╝╚╝";
// contains 2 disconnected wire ends
string input =
" ╔╗\n" +
"╔╝╚═╗\n" +
"╚╗ ╚═╗\n" +
" ╚════╝";
// contains 0 disconnected wire ends
public int CountWireEnds(string s)
{
string chars = "║╠╩╦═╬╣╚╝╔╗ \n";
// -----------------------
// complete challenge here
// -----------------------
}
Unit tests are included here: WireEndsTests.cs
After you successfully complete the challenge, consider challenging yourself further...
- golf: minimize the source code for the solution as much as possible while keeping it fully functional
- optimization: optimize your solution as much as possible using Benchmark.NET
If you have any feedback on this challenge, please open an issue on this repository, mention this challenge, and ping the contributor(s) of this challenge.
This was an original challege. :)
Discord meta data. Do not edit. This is used for GitHub => Discord linking.
Name | Wire Ends Challenge |
Description | You are writing a software that allows users to design electrical circuits. You need to add a feature that will count the number of loose wire ends in the current design. The wire layout data is currently stored in a `string` with the characters ` `, `║`, `╠`, `╩`, `╦`, `═`, `╬`, `╣`, `╚`, `╝`, `╔`, `╗`, and `\n`. The `\n` character represents the end of the current horizontal dimension, the `' '` character represents a coordinate with no wires, and the rest `║ ╠ ╩ ╦ ═ ╬ ╣ ╚ ╝ ╔ ╗` represent various wire configurations. |
Sample |
string input =
"╔══╗\n" +
"║╚╝║\n" +
"║╔╗║\n" +
"╚══╝";
// contains 4 disconnected wire ends string input =
"║╔╗║\n" +
"║║║║\n" +
"║║║║\n" +
"╚╝╚╝";
// contains 2 disconnected wire ends |
Contributed by | 438382611929366537 |
Self link | https://github.com/discord-csharp/challenges/tree/main/src/Wire%20Ends |