aboutsummaryrefslogtreecommitdiff
path: root/Semestr 3/anm/numerki
diff options
context:
space:
mode:
authorFranciszek Malinka <franciszek.malinka@gmail.com>2021-10-05 21:49:54 +0200
committerFranciszek Malinka <franciszek.malinka@gmail.com>2021-10-05 21:49:54 +0200
commitc5fcf7179a83ef65c86c6a4a390029149e518649 (patch)
treed29ffc5b86a0d257453cedcf87d91a13d8bf3b0d /Semestr 3/anm/numerki
parentf8a88b6a4aba1f66d04711a9330eaba49a50c463 (diff)
Duzy commit ze smieciami
Diffstat (limited to 'Semestr 3/anm/numerki')
-rw-r--r--Semestr 3/anm/numerki/lista1/test.jl118
-rw-r--r--Semestr 3/anm/numerki/lista1/test.jl.txt16
-rw-r--r--Semestr 3/anm/numerki/lista2/rozw.ml33
3 files changed, 0 insertions, 167 deletions
diff --git a/Semestr 3/anm/numerki/lista1/test.jl b/Semestr 3/anm/numerki/lista1/test.jl
deleted file mode 100644
index 235800a..0000000
--- a/Semestr 3/anm/numerki/lista1/test.jl
+++ /dev/null
@@ -1,118 +0,0 @@
-using Random
-
-function prettyfloat64(f)
- ss = bitstring(f)
- s = ss[1]
- c = ss[2:12]
- m = ss[13:end]
- return string(s, " ", c, " ", m)
-end
-
-function string_to_float64(st)
- s = st[1]
- c = st[2:12]
- m = st[13:end]
-
- if s == '0'
- s = 1.0
- else
- s = -1.0
- end
-
- c = parse(Int, string("0b", c))
- c = 2.0^(c - 1023)
- m = Float64(parse(Int64, string("0b", m))) / Float64(2^52) + 1.0
- return s * c * m
-end
-
-rng = MersenneTwister(123)
-
-function rand_f64_bitstring()
- return randstring(rng, ['0', '1'], 64)
-end
-
-function test_string_to_float()
- for i in 1:100000
- # st = rand_f64_bitstring()
- st = rand(rng)
- res = string_to_float64(bitstring(st))
- println(string(st, " -> ", prettyfloat64(st), " -> ", res))
- if bitstring(res) == bitstring(st)
- println("OK")
- else
- println("ZJEBALO SIE")
- break
- end
- end
-end
-
-function find_felerny_x()
- while true
- x = rand(rng) + 1.0
- res = x * (1.0 / x)
- if res != 1.0
- println(string("Znalazlem! ", x))
- return x
- end
- end
-end
-
-function find_felerne_iksy(iterations)
- bad_xs = 0
- for i in 1:iterations
- x = rand(rng) + 1.0
- res = x * (1.0 / x)
- if res != 1.0
- bad_xs += 1
- end
- end
- println("Znalazlem ", bad_xs, " felernych iksow, czyli ", bad_xs / iterations * 100.0, "% wszystkich losowanych wartosci.")
-end
-
-# find_felerne_iksy(10000000)
-
-
-function rel_error(x, rx)
- x = Float64(x)
- rx = Float64(rx)
- relative = abs((x - rx) / x)
- return relative
-end
-
-function test_poly(t, poly, x=4.71, exact=-14.636489)
- println("Testing poly \"", poly, "\" with float type ", t, ".")
- res = poly(x, t)
- println(poly, "(", x, ") = ", res)
- println("Relative error (exact: ", exact, "): ", rel_error(exact, res))
-end
-
-function w(x, t)
- x = t(x)
- return x^3 - (t(6)) * (x^2) + (t(3)) * x - t(0.149)
-end
-
-function w2(x, t)
- x = t(x)
- return ((x - t(6)) * x + t(3)) * x - t(0.149)
-end
-
-
-function task3()
- println("Task3: ")
-
- test_poly(Float16, w)
- println()
- test_poly(Float32, w)
- println()
- test_poly(Float64, w)
- println()
-
- test_poly(Float16, w2)
- println()
- test_poly(Float32, w2)
- println()
- test_poly(Float64, w2)
- println()
-end
-
-
diff --git a/Semestr 3/anm/numerki/lista1/test.jl.txt b/Semestr 3/anm/numerki/lista1/test.jl.txt
deleted file mode 100644
index 81b4901..0000000
--- a/Semestr 3/anm/numerki/lista1/test.jl.txt
+++ /dev/null
@@ -1,16 +0,0 @@
-function string_to_float64(st)
- s = st[1]
- c = st[2:12]
- m = st[13:end]
-
- if s == '0'
- s = 1.0
- else
- s = -1.0
- end
-
- c = parse(Int, string("0b", c))
- c = 2.0 ^ (c - 1023)
- m = Float64(parse(Int64, string("0b", m))) / Float64(2^52) + 1.0
- return s * c * m
-end
diff --git a/Semestr 3/anm/numerki/lista2/rozw.ml b/Semestr 3/anm/numerki/lista2/rozw.ml
deleted file mode 100644
index f946051..0000000
--- a/Semestr 3/anm/numerki/lista2/rozw.ml
+++ /dev/null
@@ -1,33 +0,0 @@
-(* Zadanie 1 *)
-
-let sublists l =
- let rec backtrack sl = function
- | [] -> [sl]
- | hd :: tl -> (backtrack (sl @ [hd]) tl) @ backtrack sl tl
- in backtrack [] l
-
-
-(* Zadanie 2 *)
-
-(* Znalezione tutaj: https://stackoverflow.com/questions/2710233/how-to-get-a-sub-list-from-a-list-in-ocaml *)
-
-let rec super_sublist b e = function
- | [] -> failwith "empty list"
- | hd :: tl ->
- let tail = if e <= 1 then [] else super_sublist (b - 1) (e - 1) tl in
- if b > 0 then tail else hd :: tail
-
-(* Moje rozwiązanie: *)
-
-let rec sublist b e l =
- let rec suffix idx l =
- if idx = 0 then l else suffix (idx - 1) (List.tl l) in
- let rec prefix idx l =
- if idx = 0 then [] else (List.hd l) :: (prefix (idx - 1) (List.tl l)) in
- prefix (e - 1) (suffix b l)
-
-let cycle_with_sub sublist_fun xs n =
- sublist_fun n (n + (List.length xs)) (xs @ xs)
-
-let super_cycle = cycle_with_sub super_sublist
-let cycle = cycle_with_sub sublist