commit 5473a6aedaf9f23511b43102bcbb0ba6002141f2
parent 90b880488472c95fd392db609d799f9d035909cb
Author: NunoSempere <nuno.sempere@protonmail.com>
Date: Thu, 2 Nov 2023 23:40:05 +0000
add bc version without comments or extraneous newlines.
Diffstat:
2 files changed, 59 insertions(+), 0 deletions(-)
diff --git a/bc/comments_stripped/estimate.bc b/bc/comments_stripped/estimate.bc
@@ -0,0 +1,27 @@
+p_a = 0.8
+p_b = 0.5
+p_c = p_a * p_b
+weights[0] = 1 - p_c
+weights[1] = p_c / 2
+weights[2] = p_c / 4
+weights[3] = p_c / 4
+define mixture(){
+ p = sample_unit_uniform()
+ if(p <= weights[0]){
+ return 0
+ }
+ if(p <= (weights[0] + weights[1])){
+ return 1
+ }
+ if(p<= (weights[0] + weights[1] + weights[2])){
+ return sample_to(1, 3)
+ }
+ return sample_to(2, 10)
+}
+n_samples = 1000000
+sum=0
+for(i=0; i < n_samples; i++){
+ sum += mixture()
+}
+sum/n_samples
+halt
diff --git a/bc/comments_stripped/squiggle.bc b/bc/comments_stripped/squiggle.bc
@@ -0,0 +1,32 @@
+scale = 16
+pi = 4 * atan(1)
+normal90confidence=1.64485362695
+define sample_unit_uniform(){
+ return rand()/maxrand()
+}
+define sample_unit_normal(){
+ u1=sample_unit_uniform()
+ u2=sample_unit_uniform()
+ z = sqrt(-2 * l(u1)) * sin(2 * pi * u2)
+ return z
+}
+define sample_uniform(min, max){
+ return (min + sample_unit_uniform()*(max-min))
+}
+define sample_normal(mean, sigma){
+ return (mean + sigma * sample_unit_normal())
+}
+define sample_lognormal(logmean, logstd){
+ return e(sample_normal(logmean, logstd))
+}
+define sample_normal_from_90_confidence_interval(low, high){
+ mean = (high + low) / 2
+ std = (high - low) / (2 * normal90confidence)
+ return sample_normal(mean, std)
+}
+define sample_to(low, high){
+ loglow = l(low)
+ loghigh = l(high)
+ return e(sample_normal_from_90_confidence_interval(loglow, loghigh))
+}
+