mirror of
https://github.com/Zenithsiz/ist-pe-proj.git
synced 2026-02-03 05:57:12 +00:00
Fixed 5.
This commit is contained in:
parent
7e758860bd
commit
9c27df5b32
1
5/answer.txt
Normal file
1
5/answer.txt
Normal file
@ -0,0 +1 @@
|
||||
0.1321
|
||||
38
5/script.R
38
5/script.R
@ -1,7 +1,7 @@
|
||||
#!/bin/env Rscript
|
||||
|
||||
# Set the seed for the RNG
|
||||
set.seed(1966)
|
||||
# set.seed(1966)
|
||||
|
||||
|
||||
p <- 0.4
|
||||
@ -23,22 +23,32 @@ dist_fn <- function(x) {
|
||||
}
|
||||
|
||||
# TODO: This doesn't seem right...
|
||||
values_length <- 1090
|
||||
values <- vector()
|
||||
cur_idx <- 0
|
||||
while (length(values) < 1090) {
|
||||
while (length(values) < values_length) {
|
||||
u <- runif(1, min = 0, max = 1)
|
||||
|
||||
min <- dist_fn(cur_idx - 1)
|
||||
max <- dist_fn(cur_idx)
|
||||
x <- 0
|
||||
while (TRUE) {
|
||||
min <- dist_fn(x - 1)
|
||||
max <- dist_fn(x)
|
||||
|
||||
message("Trying ", u, " (", min, "..", max, ")")
|
||||
if (u > min && u <= max) {
|
||||
message("Successful ", u)
|
||||
values <- append(values, TRUE)
|
||||
} else {
|
||||
values <- append(values, FALSE)
|
||||
if (u > min && u <= max) {
|
||||
values <- append(values, x)
|
||||
break
|
||||
}
|
||||
|
||||
x <<- x + 1
|
||||
}
|
||||
cur_idx <- cur_idx + 1
|
||||
}
|
||||
print(cur_idx)
|
||||
print(values)
|
||||
|
||||
true_mean <- (1 - p) / p
|
||||
values_mean <- mean(values)
|
||||
values_sd <- sd(values)
|
||||
|
||||
|
||||
values_count <- sum(sapply(values, function(value) {
|
||||
value >= true_mean + values_sd && value >= values_mean
|
||||
}))
|
||||
print(values_count)
|
||||
print(values_count / values_length)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user