- Executors
-
Learn
Python Learning Hub Runnable examples, NumPy, pandas, and more C & C++ Learning Hub Pointers, memory, STL, and modern C++ C# Learning HubC# basics, OOP, LINQ, async, and .NET exercises Python Algorithms Search, sorting, recursion, and visualizers O(n) C & C++ Algorithms Compare algorithms implemented in C and C++
- Challenges
XOR (exclusive or) is the classic problem a single neuron cannot solve, but a network with one hidden layer can. Train a network with 2 inputs, 2 hidden neurons and 1 output, all sigmoid (σ(z) = 1 / (1 + e^(-z))), using the loss L = (y - target)².
The training data, always used in this order in every epoch:
| input | target |
|---|---|
| [0, 0] | 0 |
| [0, 1] | 1 |
| [1, 0] | 1 |
| [1, 1] | 0 |
For each example:
- Forward: a_j = σ(x₁ × hidden_weights[j][0] + x₂ × hidden_weights[j][1] + hidden_biases[j]), y = σ(a₁ × output_weights[0] + a₂ × output_weights[1] + output_bias)
- delta_out = 2 × (y - target) × y × (1 - y), and delta_j = delta_out × output_weights[j] × a_j × (1 - a_j), using the weights before this example's update
- Update every parameter with learning rate lr: output_weights[j] -= lr × delta_out × a_j, output_bias -= lr × delta_out, hidden_weights[j][i] -= lr × delta_j × x_i, hidden_biases[j] -= lr × delta_j
Implement train_xor(hidden_weights, hidden_biases, output_weights, output_bias, learning_rate, epochs).
Output
After training, return the network's predictions y for the inputs [0, 0], [0, 1], [1, 0] and [1, 1], in that order.
Constraints
0 ≤ epochs ≤ 5,000
0 < learning_rate ≤ 5
-2 ≤ each starting weight and bias ≤ 2
Examples
Example 1
Input:
epochs = 0
output_bias = 0.0
hidden_biases = [0.0, 0.3]
learning_rate = 1.5
hidden_weights = [
[0.2, 0.8],
[0.9, -0.7]
]
output_weights = [-0.6, 0.4]
Expected output:
[0.482451, 0.436972, 0.494378, 0.452729]
Explanation
With 0 epochs nothing is trained, so the result is just the forward pass with the starting weights: about [0.482, 0.437, 0.494, 0.453]. The untrained network gives every input nearly the same answer.
Example 2
Input:
epochs = 2000
output_bias = 0.0
hidden_biases = [0.0, 0.3]
learning_rate = 1.5
hidden_weights = [
[0.2, 0.8],
[0.9, -0.7]
]
output_weights = [-0.6, 0.4]
Expected output:
[0.015727, 0.982119, 0.985515, 0.013682]
Explanation
After 2,000 epochs the predictions are about [0.016, 0.982, 0.986, 0.014]: low for [0, 0] and [1, 1], high for [0, 1] and [1, 0]. The network has learned XOR.
References
-
Example 1 Not runInput:
epochs = 0 output_bias = 0.0 hidden_biases = [0.0, 0.3] learning_rate = 1.5 hidden_weights = [ [0.2, 0.8], [0.9, -0.7] ] output_weights = [-0.6, 0.4]Expected output:[0.482451, 0.436972, 0.494378, 0.452729]Your output -
Example 2 Not runInput:
epochs = 2000 output_bias = 0.0 hidden_biases = [0.0, 0.3] learning_rate = 1.5 hidden_weights = [ [0.2, 0.8], [0.9, -0.7] ] output_weights = [-0.6, 0.4]Expected output:[0.015727, 0.982119, 0.985515, 0.013682]Your output
4 hidden tests also run when you submit.
Online C# Compiler & Debugger
Write, compile, run, and debug C# code online. Set breakpoints, step into or over code, and inspect variables and nested objects in a full IDE with multiple files, saved workspaces, sharing, and live collaboration—no setup required.
🚀 350,747 total executions (1 this month)
Practice C# with coding challenges
Solve hands-on problems right in this editor: run the sample tests, submit, and get an AI code review.
🔷 About This C# / .NET Online Executor
The CodeUtility C# Executor lets you write and run real C# code directly in your browser - no installation, Visual Studio setup, or .NET SDK required. It’s powered by a secure sandbox that supports the .NET runtime and modern C# language versions, including C# 9 and later.
This tool uses dotnet-script under the hood to compile and execute your code with true .NET behavior, allowing you to experiment with both basic and advanced C# features like LINQ, async/await, pattern matching, and generics.
You can test simple scripts, functions, and logic flows, or explore concepts like classes, structs, inheritance, and interfaces - all in a clean, distraction-free coding environment.
Whether you’re learning C#, testing algorithms, or experimenting with .NET features, the CodeUtility C# Executor gives you a fast, secure, and reliable way to run C# code instantly from any browser.
More than a code runner
Use a multi-file editor, an isolated execution terminal, runtime-specific libraries, persistent workspaces, sharing, and real-time collaboration from the same executor.
How to use this executor?
Choose a runtime, open or create a file, write your code, and select Run. Output appears in the terminal, while signed-in users can keep files in a workspace, install libraries, and collaborate through shares.
- Select a version and edit the current file or open another workspace file.
- Run the code, provide input in the terminal when requested, and review saved run history.
- Use libraries, workspace tools, sharing, and chat when your task needs more than one snippet.
💡 C# Basics & Examples You Can Try Above
1. Declaring Variables and Constants
C# uses strongly-typed variable declarations. Use const for compile-time constants and readonly for runtime constants.
int age = 30;
double pi = 3.14159;
char grade = 'A';
string name = "Alice";
bool isActive = true;
// Constants
const int MaxUsers = 100;
const string Company = "CodeUtility";
2. Conditionals (if / switch)
Use if, else if, and switch for control flow.
int x = 2;
if (x == 1)
{
Console.WriteLine("One");
}
else if (x == 2)
{
Console.WriteLine("Two");
}
else
{
Console.WriteLine("Other");
}
switch (x)
{
case 1:
Console.WriteLine("One");
break;
case 2:
Console.WriteLine("Two");
break;
default:
Console.WriteLine("Other");
break;
}
3. Loops
C# supports for, while, and foreach loops.
for (int i = 0; i < 3; i++)
{
Console.WriteLine(i);
}
int n = 3;
while (n > 0)
{
Console.WriteLine(n);
n--;
}
4. Arrays
Arrays store fixed-size collections of elements of the same type.
int[] numbers = { 10, 20, 30 };
Console.WriteLine(numbers[1]);
5. List Manipulation
Use List<T> for dynamic collections.
List<int> nums = new List<int> { 1, 2, 3 };
nums.Add(4);
nums.Remove(2);
foreach (int n in nums)
{
Console.Write(n + " ");
}
6. Console Input/Output
Use Console.WriteLine and Console.ReadLine for basic I/O.
Console.Write("Enter your name: ");
string name = Console.ReadLine();
Console.WriteLine($"Hello, {name}!");
7. Functions
Define methods using a return type, name, and parameters.
int Add(int a, int b)
{
return a + b;
}
Console.WriteLine(Add(3, 4));
8. Dictionaries
Dictionary<TKey, TValue> stores key-value pairs.
Dictionary<string, int> ages = new Dictionary<string, int>();
ages["Alice"] = 30;
Console.WriteLine(ages["Alice"]);
9. Exception Handling
Handle runtime errors using try, catch, and finally.
try
{
throw new Exception("Something went wrong");
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
10. File I/O
Use File and StreamReader/StreamWriter for file operations.
File.WriteAllText("file.txt", "Hello File");
string text = File.ReadAllText("file.txt");
Console.WriteLine(text);
11. String Manipulation
C# strings support methods like Length, Substring, Contains.
string message = "Hello World";
Console.WriteLine(message.Length);
Console.WriteLine(message.Substring(0, 5));
Console.WriteLine(message.Contains("World"));
12. Classes & Objects
C# supports object-oriented programming through classes and objects.
class Person
{
public string Name;
public Person(string name) => Name = name;
public void Greet() => Console.WriteLine($"Hi, I'm {Name}");
}
Person p = new Person("Alice");
p.Greet();