8주차 Discussion #11
chloe-codes1
started this conversation in
General
Replies: 4 comments 1 reply
-
3.1function make_accumulator(initialValue) {
return (value) => (initialValue += value);
} |
Beta Was this translation helpful? Give feedback.
1 reply
-
3.5// x1 <= x2, y1 <= y2 가 성립한다고 가정
function estimate_integral(P, x1, x2, y1, y2, trials) {
function experiment() {
const rx = random_in_range(x1, x2);
const ry = random_in_range(y1, y2);
return P(rx, ry);
}
return (x2 - x1) * (y2 - y1) * monte_carlo(trials, experiment);
}
function monte_carlo(trials, experiment) {
function iter(trials_remaining, trials_passed) {
return trials_remaining === 0
? trials_passed / trials
: experiment()
? iter(trials_remaining - 1, trials_passed + 1)
: iter(trials_remaining - 1, trials_passed);
}
return iter(trials, 0);
}
function random_in_range(low, high) {
const range = high - low;
return low + Math.random() * range;
} const pi = estimate_integral(
(x, y) => x ** 2 + y ** 2 <= 1,
-1,
1,
-1,
1,
10000,
);
console.log(pi); |
Beta Was this translation helpful? Give feedback.
0 replies
-
3.7function make_joint(account, original_password, new_password) {
return (password, m) =>
password !== new_password
? error("Incorrect password")
: account(original_password, m);
}
function make_account(balance, password) {
function withdraw(amount) {
if (balance >= amount) {
balance = balance - amount;
return balance;
} else {
return "Insufficient funds";
}
}
function deposit(amount) {
balance = balance + amount;
return balance;
}
function dispatch(user_password, m) {
return user_password !== password
? error("Incorrect password")
: m === "withdraw"
? withdraw
: m === "deposit"
? deposit
: error(m, "unknown request -- make_account");
}
return dispatch;
}
function error(value, message) {
throw Error(`${value}: ${message}`);
} |
Beta Was this translation helpful? Give feedback.
0 replies
-
몬테카를로를 이용하여 최대공약수가 1일 확률(두 수가 서로소일 확률)
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
📢 책을 읽으면서 궁금한 점들을 자유롭게 적고 대답해 주세요
8주차 진행 방식
진도
: 3.1 - 3.2 읽어오고 정리 & 의견 나누기문제 풀이
: 3.1, 3.5, 3.7, 3.9, 3.10, 3.11 문제 풀고, Github 에 올리기 (총 6문제)Beta Was this translation helpful? Give feedback.
All reactions