50 lines
1.7 KiB
HTML
50 lines
1.7 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="de">
|
|
<head>
|
|
<meta charset="UTF-8" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
<title>Optionale Übung 6: Berechnung von Kombinationen mit Rekursion</title>
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.8/dist/css/bootstrap.min.css" rel="stylesheet" />
|
|
</head>
|
|
<body>
|
|
<main>
|
|
<div class="container py-5">
|
|
<div class="alert alert-warning">
|
|
<h2>Optionale Übung 6: Berechnung von Kombinationen mit Rekursion</h2>
|
|
<p>
|
|
Implementiere eine rekursive Funktion in JavaScript, die die Anzahl der Kombinationen berechnet, in denen
|
|
man <code>k</code> Elemente aus einer Menge von <code>n</code> Elementen auswählen kann (also den
|
|
Binomialkoeffizienten).
|
|
</p>
|
|
<h4>Hinweise</h4>
|
|
|
|
<ul>
|
|
<li>
|
|
Die Formel für Kombinationen lautet:<br /><img
|
|
src="https://trainers.atp.wpicert.org/system/wpi_curriculum/file/images/files/000/016/028/302-59/79ca8a079d2c6c737780cd08584c343e.png?1755753490"
|
|
class="img-thumbnail"
|
|
alt="" />
|
|
</li>
|
|
<li>
|
|
Definiere geeignete Basisfälle, zum Beispiel wenn <code>k</code> gleich <code>0</code> oder
|
|
<code>n</code> ist.
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
</main>
|
|
<script>
|
|
'use strict';
|
|
|
|
const combinations = (n, k) => {};
|
|
|
|
// Test Cases
|
|
console.log(combinations(5, 2)); // => 10
|
|
console.log(combinations(6, 3)); // => 20
|
|
console.log(combinations(4, 0)); // => 1
|
|
console.log(combinations(4, 4)); // => 1
|
|
console.log(combinations(5, 6)); // => 0
|
|
</script>
|
|
</body>
|
|
</html>
|