Hong-Phuc Bui
2025-11-20 9ba573284ccde687b4c190c0f44032eef846410a
Bugfix
4 files modified
3 files added
155 ■■■■ changed files
textbased-programms/arithmetic-op.html 3 ●●●● patch | view | raw | blame | history
textbased-programms/drawing-hands.js 14 ●●●●● patch | view | raw | blame | history
textbased-programms/hello-name.js 5 ●●●●● patch | view | raw | blame | history
textbased-programms/kreisabschnitt/Kreisabschnitt.html 18 ●●●●● patch | view | raw | blame | history
textbased-programms/kreisabschnitt/Kreisabschnitt.js 39 ●●●●● patch | view | raw | blame | history
textbased-programms/kreisabschnitt/kreis.js 29 ●●●●● patch | view | raw | blame | history
textbased-programms/luhn.js 47 ●●●●● patch | view | raw | blame | history
textbased-programms/arithmetic-op.html
@@ -8,7 +8,8 @@
</head>
<body>
<label for="argv">Geben Sie 2 Zahlen getrennt von Leerzeichen ein!</label> <input type="text" id="argv" name="argv" />
<label for="argv">Geben Sie 2 Zahlen getrennt von Leerzeichen ein!</label>
<input type="text" id="argv" name="argv" />
<button name="run" id="run" >Rerun</button>
textbased-programms/drawing-hands.js
@@ -5,16 +5,14 @@
import {terminal} from "./dfhi.js";
const leftHand = () => {
    return rightHand();
}
const rightHand = () => {
    return leftHand();
}
window.main = (...argv) => {
    terminal.printl(leftHand() + " draws first!");
};
const leftHand = () => {
    return rightHand();
}
const rightHand = () => {
    return leftHand();
}
textbased-programms/hello-name.js
@@ -7,6 +7,7 @@
window.main = (...argv) => {
    let name = argv[0];
    terminal.print(`Hallo, ${name}!`)
    for(let e of argv) {
        terminal.printl(e);
    }
};
textbased-programms/kreisabschnitt/Kreisabschnitt.html
New file
@@ -0,0 +1,18 @@
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Kreisabschnitt</title>
</head>
<body>
Fs = <input id="Fs" value="100.1214"></input><br/>
s = <input id="s" value="49.245363"><br/>
<button id="run">Calculate</button><br/>
<p>Ergebnis:</p>
r: <span id="radius"></span><br/>
alpha: <span id="alpha"></span><br/>
<script src="Kreisabschnitt.js" type="module"></script>
</body>
</html>
textbased-programms/kreisabschnitt/Kreisabschnitt.js
New file
@@ -0,0 +1,39 @@
import {calculateRadius} from "./kreis.js";
const runBnt = document.getElementById("run");
runBnt.addEventListener("click", () => {
    try {
        const fsInput = document.querySelector("#Fs");
        const sInput = document.querySelector("#s");
        const [fs, s] = convertInput(fsInput, sInput);
        console.log({fs, s});
        const [radius,alpha] = calculateRadius(fs, s);
        console.log({radius, alpha});
        const radiusSpan = document.getElementById("radius");
        radiusSpan.innerText = `${radius}`;
        const alphaSpan = document.getElementById("alpha");
        alphaSpan.innerText = `${alpha}`;
    }catch (e) {
        showError(e);
    }
});
const convertInput = (fsInput, sInput) => {
    const fs = fsInput.value;
    const nFs = Number(fs);
    if(isNaN(nFs)) {
        //TODO: set styling von fsInput to error
        throw new Error("Fläche-eingabe ist keine Zahl")
    }
    const s = sInput.value;
    const nS = Number(s);
    if(isNaN(s)) {
        //TODO: set styling von sInput to error
        throw new Error("Sehnenlänge-eingabe ist keine Zahl");
    }
    return[nFs, nS];
}
const showError = (error) => {
    console.error(error);
}
textbased-programms/kreisabschnitt/kreis.js
New file
@@ -0,0 +1,29 @@
export const calculateRadius = (fs, s) => {
    const alpha = approximateAlpha(fs, s);
    const radius = s/(2*Math.sin(alpha/2));
    return [radius, alpha];
}
const approximateAlpha = (fs, s) => {
    console.log({fs, s});
    const Y = 8*fs/(s**2);
    let left = 0;
    let right = Math.PI;
    // f(alpha) = (alpha - sin(alpha)) / (sin^2(alpha/2))
    const EPSILON = 0.001;
    let alpha = 0 ;
    let y = 0;
    let diff = 2*EPSILON;
    do{
        alpha = (left + right)/2;
        y = (alpha - Math.sin(alpha)) / ( Math.sin(alpha/2)**2 ) ;
        diff = y - Y;
        if(diff < 0) {
            left = alpha;
        }else{
            right = alpha;
        }
    } while( Math.abs(diff) >= EPSILON);
    return alpha;
}
textbased-programms/luhn.js
@@ -5,25 +5,32 @@
import {terminal} from "./dfhi.js";
window.main = (...argv) => {
    let sumEvent = 0n;
    let sumOdd = 0n;
    let credit = argv[0];
const checkLuhnNumber = (n) => {
    let sumEvent = 0n;
    let sumOdd = 0n;
    while(n > 0) {
        sumOdd += (n % 10n);  // modulo division base 10 to get the last digit
        n = n/10n;            // integer division base 10 to shift credit number one digit to right
        let rest = n % 10n;   // get the second-last digit
        let p = rest*2n;
        sumEvent += (p > 9n) ? (p - 9n) : p;
        n = n/10n;
    }
    return (sumEvent + sumOdd) % 10n;
}
    let n = BigInt(credit.replace(/[-_\s+]/g, ''));
    while(n > 0) {
        sumOdd += (n % 10n);  // modulo division base 10 to get the last digit
        n = n/10n;            // integer division base 10 to shift credit number one digit to right
        let rest = n % 10n;   // get the second-last digit
        let p = rest*2n;
        sumEvent += (p > 9n) ? (p - 9n) : p;
        n = n/10n;
    }
    console.log({sumOdd, sumEvent});
    const sum =(sumEvent + sumOdd) % 10n;
    if (sum === 0n) {
        terminal.printl(`${credit} may be a valid credit number`);
    } else {
        terminal.printl(`${credit} is not a valid credit number`);
    }
window.main = (...argv) => {
    try {
        let credit = argv[0];
        let n = BigInt(credit.replace(/[-_\s+]/g, ''));
        const sum = checkLuhnNumber(n);
        if (sum === 0n) {
            terminal.printl(`${credit} may be a valid credit number`);
        } else {
            terminal.printl(`${credit} is not a valid credit number`);
        }
    }catch (e) {
        terminal.printl("Die eingegebene Zeichenkette ist keine Credit Nummer");
        terminal.printl("Erlaubten Zeichen sind Ziffer, Leerzeichen und Bindenstrich");
    }
};