This commit is contained in:
jverzani
2022-05-24 13:51:49 -04:00
parent 5c0fd1b6fe
commit 244f492f9e
240 changed files with 65211 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
From [bennedich](https://discourse.julialang.org/t/love-in-245-characters-code-golf/20771)
```
0:2e-3:2π .|>d->(P=
fill(5<<11,64 ,25);z=8cis(
d)sin(.46d);P[ 64,:].=10;for
r=0:98,c=0 :5^3 x,y=@.mod(2-
$reim((.016c-r/49im-1-im)z),
4)-2;4-x^2>√2(y+.5-√√x^2)^
2&&(P[c÷2+1,r÷4+1]|=Int(
")*,h08H¨"[4&4c+1+r&
3])-40)end;print(
"\e[H\e[1;31m",
join(Char.(
P)))
);
```
[New York Times](https://www.nytimes.com/2019/02/14/science/math-algorithm-valentine.html)
Süss — German for “sweet” — is an interactive widget that allows you to tweak the algebra and customize the heart to your soulss delight. It was created for Valentines Day by Imaginary, a nonprofit organization in Berlin that designs open-source mathematics programs and exhibitions.
You can stretch and squeeze the heart by moving the two left-most sliders, which change the “a” and “b” parameters; the right-most slider zooms in and out. Better yet, canoodle directly with Süsss equation and engage in the dialectical interplay between algebra and geometry. (Change that final z³ to a z² to see the heart in its underwear.)
```
(x^2+((1+b)*y)^2+z^2-1)^3-x^2*z^3-a*y^2*z^3
```

View File

@@ -0,0 +1,72 @@
"","elevation","elev_units","longitude","latitude"
"1",126.85,"meters",-74.2986363,40.7541939
"2",125.19,"meters",-74.298561,40.754122
"3",123.52,"meters",-74.298505,40.754049
"4",121.92,"meters",-74.298435,40.753972
"5",119.86,"meters",-74.298402,40.753872
"6",119.86,"meters",-74.298416,40.753818
"7",119.86,"meters",-74.298393,40.753805
"8",118.32,"meters",-74.298233,40.753717
"9",118.48,"meters",-74.298113,40.753706
"10",118.48,"meters",-74.298079,40.753714
"11",110.65,"meters",-74.297548,40.753434
"12",108.68,"meters",-74.297364,40.753392
"13",108.68,"meters",-74.2973338,40.7533463
"14",107.67,"meters",-74.2972265,40.7533169
"15",107.54,"meters",-74.297087,40.753356
"16",107.54,"meters",-74.2970438,40.7533584
"17",106.74,"meters",-74.296979,40.753397
"18",107.69,"meters",-74.29689,40.753533
"19",108.01,"meters",-74.296812,40.753661
"20",108.34,"meters",-74.296718,40.753785
"21",108.93,"meters",-74.296627,40.753874
"22",109.26,"meters",-74.296514,40.753973
"23",109.44,"meters",-74.296377,40.754026
"24",107.8,"meters",-74.296184,40.754049
"25",108.14,"meters",-74.29596,40.754119
"26",108.31,"meters",-74.295761,40.754191
"27",107.08,"meters",-74.295542,40.754277
"28",106.54,"meters",-74.295345,40.754276
"29",105.18,"meters",-74.295177,40.754295
"30",104.93,"meters",-74.2951,40.754358
"31",103.79,"meters",-74.294976,40.754381
"32",103.79,"meters",-74.294943,40.754379
"33",103.62,"meters",-74.294873,40.754362
"34",103.46,"meters",-74.294805,40.754359
"35",102.68,"meters",-74.294687,40.754349
"36",102.78,"meters",-74.294537,40.754269
"37",100.91,"meters",-74.294341,40.754248
"38",101.24,"meters",-74.294228,40.754249
"39",101.15,"meters",-74.294146,40.75427
"40",100.73,"meters",-74.294043,40.754277
"41",100.77,"meters",-74.293997,40.75418
"42",97.54,"meters",-74.293672,40.75418
"43",97.58,"meters",-74.293539,40.754324
"44",97.41,"meters",-74.293442,40.754447
"45",97.02,"meters",-74.29342,40.754555
"46",96.78,"meters",-74.293397,40.754677
"47",96.72,"meters",-74.293319,40.754787
"48",96.98,"meters",-74.2933093,40.7549621
"49",97.04,"meters",-74.2931914,40.7550903
"50",95.89,"meters",-74.2931359,40.7552002
"51",95.48,"meters",-74.293124,40.75528
"52",95.43,"meters",-74.293142,40.755375
"53",95.58,"meters",-74.293163,40.7554692
"54",95.58,"meters",-74.2931806,40.7555174
"55",95.31,"meters",-74.2930826,40.7555402
"56",95.45,"meters",-74.2930283,40.7555572
"57",94.19,"meters",-74.2929292,40.7555853
"58",93.57,"meters",-74.2928114,40.7556067
"59",92.9,"meters",-74.2927408,40.7556127
"60",92.9,"meters",-74.2926921,40.7556257
"61",91.46,"meters",-74.2926528,40.7556602
"62",91.46,"meters",-74.2926104,40.7556888
"63",88.42,"meters",-74.2925696,40.7557042
"64",88.42,"meters",-74.2925272,40.7556876
"65",85.62,"meters",-74.2924927,40.7556674
"66",85.32,"meters",-74.2924503,40.755646
"67",85.32,"meters",-74.2924377,40.7556222
"68",85.32,"meters",-74.2924377,40.7555877
"69",84.49,"meters",-74.2924346,40.7555365
"70",84.49,"meters",-74.2924236,40.755502
"71",84.36,"meters",-74.2923562,40.7554961
1 elevation elev_units longitude latitude
2 1 126.85 meters -74.2986363 40.7541939
3 2 125.19 meters -74.298561 40.754122
4 3 123.52 meters -74.298505 40.754049
5 4 121.92 meters -74.298435 40.753972
6 5 119.86 meters -74.298402 40.753872
7 6 119.86 meters -74.298416 40.753818
8 7 119.86 meters -74.298393 40.753805
9 8 118.32 meters -74.298233 40.753717
10 9 118.48 meters -74.298113 40.753706
11 10 118.48 meters -74.298079 40.753714
12 11 110.65 meters -74.297548 40.753434
13 12 108.68 meters -74.297364 40.753392
14 13 108.68 meters -74.2973338 40.7533463
15 14 107.67 meters -74.2972265 40.7533169
16 15 107.54 meters -74.297087 40.753356
17 16 107.54 meters -74.2970438 40.7533584
18 17 106.74 meters -74.296979 40.753397
19 18 107.69 meters -74.29689 40.753533
20 19 108.01 meters -74.296812 40.753661
21 20 108.34 meters -74.296718 40.753785
22 21 108.93 meters -74.296627 40.753874
23 22 109.26 meters -74.296514 40.753973
24 23 109.44 meters -74.296377 40.754026
25 24 107.8 meters -74.296184 40.754049
26 25 108.14 meters -74.29596 40.754119
27 26 108.31 meters -74.295761 40.754191
28 27 107.08 meters -74.295542 40.754277
29 28 106.54 meters -74.295345 40.754276
30 29 105.18 meters -74.295177 40.754295
31 30 104.93 meters -74.2951 40.754358
32 31 103.79 meters -74.294976 40.754381
33 32 103.79 meters -74.294943 40.754379
34 33 103.62 meters -74.294873 40.754362
35 34 103.46 meters -74.294805 40.754359
36 35 102.68 meters -74.294687 40.754349
37 36 102.78 meters -74.294537 40.754269
38 37 100.91 meters -74.294341 40.754248
39 38 101.24 meters -74.294228 40.754249
40 39 101.15 meters -74.294146 40.75427
41 40 100.73 meters -74.294043 40.754277
42 41 100.77 meters -74.293997 40.75418
43 42 97.54 meters -74.293672 40.75418
44 43 97.58 meters -74.293539 40.754324
45 44 97.41 meters -74.293442 40.754447
46 45 97.02 meters -74.29342 40.754555
47 46 96.78 meters -74.293397 40.754677
48 47 96.72 meters -74.293319 40.754787
49 48 96.98 meters -74.2933093 40.7549621
50 49 97.04 meters -74.2931914 40.7550903
51 50 95.89 meters -74.2931359 40.7552002
52 51 95.48 meters -74.293124 40.75528
53 52 95.43 meters -74.293142 40.755375
54 53 95.58 meters -74.293163 40.7554692
55 54 95.58 meters -74.2931806 40.7555174
56 55 95.31 meters -74.2930826 40.7555402
57 56 95.45 meters -74.2930283 40.7555572
58 57 94.19 meters -74.2929292 40.7555853
59 58 93.57 meters -74.2928114 40.7556067
60 59 92.9 meters -74.2927408 40.7556127
61 60 92.9 meters -74.2926921 40.7556257
62 61 91.46 meters -74.2926528 40.7556602
63 62 91.46 meters -74.2926104 40.7556888
64 63 88.42 meters -74.2925696 40.7557042
65 64 88.42 meters -74.2925272 40.7556876
66 65 85.62 meters -74.2924927 40.7556674
67 66 85.32 meters -74.2924503 40.755646
68 67 85.32 meters -74.2924377 40.7556222
69 68 85.32 meters -74.2924377 40.7555877
70 69 84.49 meters -74.2924346 40.7555365
71 70 84.49 meters -74.2924236 40.755502
72 71 84.36 meters -74.2923562 40.7554961

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,294 @@
## container of points into vectors n vectors of length N
## N points, each of size n
## Lesson learned -- this is a very bad idea!
## better to handle the T a different way
evec(T,n) = Tuple(T[] for _ in 1:n)
evec(T, N, n) = Tuple(Vector{T}(undef, N) for _ in 1:n)
## julia> @btime xs_ys1(vs) setup=(vs=[randn(1000) for i in 1:3]);
## 83.308 μs (1013 allocations: 172.67 KiB)
## julia> @btime xs_ys2(vs) setup=(vs=[randn(1000) for i in 1:3]);
## 222.371 μs (2016 allocations: 180.72 KiB)
## julia> @btime xs_ys3(vs) setup=(vs=[randn(1000) for i in 1:3]);
## 1.003 ms (1019 allocations: 165.20 KiB)
## julia> @btime xs_ys4(vs) setup=(vs=[randn(1000) for i in 1:3]);
## 1.115 ms (5474 allocations: 210.95 KiB)
## julia> @btime xs_ys5(vs) setup=(vs=[randn(1000) for i in 1:3]);
## 1.120 ms (5474 allocations: 210.95 KiB)
## julia> @btime xs_ys6(vs) setup=(vs=[randn(1000) for i in 1:3]);
## 76.604 μs (1008 allocations: 164.63 KiB)
## julia> @btime xs_ys7(vs) setup=(vs=[randn(1000) for i in 1:3]);
## 74.306 μs (1008 allocations: 164.63 KiB)
## julia> @btime xs_ys8(vs) setup=(vs=[randn(1000) for i in 1:3]);
## 36.098 μs (2006 allocations: 94.25 KiB)
## julia> @btime xs_ys9(vs) setup=(vs=[randn(1000) for i in 1:3]);
## 85.732 μs (3006 allocations: 203.63 KiB)
## ....
## THE WINNER, but we would use one with keywords
## julia> @btime xs_ys13a(vs) setup=(vs=[randn(1000) for i in 1:3]);
## 62.768 μs (1003 allocations: 117.28 KiB)
## julia> @btime xs_ys13akw(vs) setup=(vs=[randn(1000) for i in 1:3]);
## 65.905 μs (1003 allocations: 117.28 KiB)
## make a matrix n x N, then go down 1:n
function xs_ys1(vs)
A=hcat(vs...)
Tuple([A[i,:] for i in eachindex(first(vs))])
end
## broadcast push!
function xs_ys2(vs)
u = first(vs); N = length(vs)
T = eltype(u); n = length(u)
v0 = evec(T,n)
for v in vs
push!.(v0, v)
end
v0
end
## broadcast push!
function xs_ys2a(vs)
u = first(vs); N = length(vs)
n = length(u)
v0 = Tuple(eltype(u)[] for _ in eachindex(u))
for v in vs
push!.(v0, v)
end
v0
end
## broadcast setindex!
function xs_ys3(vs)
u = first(vs); N = length(vs)
T = eltype(u); n = length(u)
v0 = evec(T,N,n)
for (i,v) in enumerate(vs)
setindex!.(v0, v, i)
end
v0
end
## 10 times faster ~77mus avoiding passing T
function xs_ys3a(vs)
u = first(vs); N = length(vs)
n = length(u)
v0 = Tuple(Vector{eltype(u)}(undef, N) for _ in eachindex(u))
for (i,v) in enumerate(vs)
setindex!.(v0, v, i)
end
v0
end
function xs_ys3b(vs)
u = first(vs); N = length(vs)
n = length(u)
v0 = ntuple(_ -> Vector{eltype(u)}(undef, N), n)
for (i,v) in enumerate(vs)
setindex!.(v0, v, i)
end
v0
end
## loop N n
function xs_ys4(vs)
u = first(vs); N = length(vs)
T = eltype(u); n = length(u)
v0 = evec(T,N,n)
for i in 1:N
for j in 1:n
v0[j][i] = vs[i][j]
end
end
v0
end
## loop N n
function xs_ys4a(vs)
u = first(vs); N = length(vs)
T = eltype(u); n = length(u)
v0 = evec(T,N,n)
for (i,v) in enumerate(vs)
for j in 1:n
v0[j][i] = v[j]
end
end
v0
end
## fast 67mus
function xs_ys4b(vs)
u = first(vs); N = length(vs)
n = length(u)
v0 = Tuple(Vector{eltype(u)}(undef, N) for _ in eachindex(u))
for (i,v) in enumerate(vs)
for j in 1:n
v0[j][i] = v[j]
end
end
v0
end
## loop n N
function xs_ys5(vs)
u = first(vs); N = length(vs)
T = eltype(u); n = length(u)
v0 = evec(T,N,n)
for j in 1:n
for i in 1:N
v0[j][i] = vs[i][j]
end
end
v0
end
function xs_ys6(vs)
u = first(vs); N = length(vs)
T = eltype(u); n = length(u)
A = Matrix{T}(undef, (N,n))
for (i,v) in enumerate(vs)
A[i,:] = v
end
Tuple(A[:,i] for i in 1:n)
end
function xs_ys7(vs)
u = first(vs); N = length(vs)
T = eltype(u); n = length(u)
A = Matrix{T}(undef, (n, N))
for (i,v) in enumerate(vs)
A[:,i] = v
end
Tuple(A[i, :] for i in 1:n)
end
# faster but doesn't wotk with plot recipes
# and may be slower once realized
function xs_ys8(vs)
N = length(vs)
u = first(vs); T = eltype(u); n = length(u)
Tuple((vs[j][i] for j in 1:N) for i in 1:n)
end
function xs_ys9(vs)
N = length(vs)
u = first(vs); T = eltype(u); n = length(u)
Tuple(collect(vs[j][i] for j in 1:N) for i in 1:n)
end
function xs_ys10(vs)
N = length(vs)
u = first(vs); T = eltype(u); n = length(u)
v0 = evec(T,N, n)
for j in 1:n
v0[j][:] .= (v[j] for v in vs)
end
v0
end
# mauro3 https://github.com/JuliaDiffEq/ODE.jl/issues/80
_pluck(y,i) = eltype(first(y))[el[i] for el in y]
xs_ys11(vs) = Tuple(_pluck(vs, i) for i in eachindex(first(vs)))
# slower
xs_ys11a(vs) = ntuple(i->_pluck(vs, i), length(first(vs)))
# one liner
xs_ys11b(vs) = Tuple(eltype(first(vs))[el[i] for el in vs] for i in eachindex(first(vs)))
function xs_ys11c(vs)
u = first(vs)
Tuple(eltype(u)[el[i] for el in vs] for i in eachindex(u))
end
xs_ys11d(vs) = (u=first(vs); Tuple(eltype(u)[el[i] for el in vs] for i in eachindex(u)))
xs_ys11e(vs) = (u=first(vs); ntuple(i->eltype(u)[v[i] for v in vs], length(u)))
xs_ys11f(vs) = (u=first(vs);n::Int=length(u);T::DataType=eltype(u);ntuple(i->eltype(u)[v[i] for v in vs], n))
xs_ys11g(vs::Vector{Vector{T}}) where {T} = (u=first(vs);n::Int=length(u);ntuple(i->T[v[i] for v in vs], n))
@inline _pluck(T, y, i) = T[el[i] for el in y]
function xs_ys11b(vs)
T = eltype(first(vs))
Tuple(_pluck(T, vs, i) for i in eachindex(first(vs)))
end
function xs_ys12(vs)
N = length(vs)
u = first(vs); T = eltype(u); n = length(u)
Tuple(T[el[i] for el in vs] for i in eachindex(first(vs)))
end
function xs_ys12a(vs)
N = length(vs)
u = first(vs); T = eltype(u); n = length(u)
ntuple( i -> T[el[i] for el in vs], n)
end
function xs_ys11h(vs)
u = first(vs)
T = eltype(u)
Tuple(T[el[i] for el in vs] for i in eachindex(u))
end
function xs_ys11i(vs)
u = first(vs)
Tuple(eltype(u)[el[i] for el in vs] for i in eachindex(u))
end
function _xs_ys12(vs, u::Vector{T}) where {T}
Tuple(T[el[i] for el in vs] for i in eachindex(u))
end
xs_ys13(vs, u::Vector{T}=first(vs)) where {T} = Tuple(T[el[i] for el in vs] for i in eachindex(u))
xs_ys13a(vs, u::Vector{T}=first(vs), n::Val{N}=Val(length(u))) where {T,N} = ntuple(i -> T[el[i] for el in vs], n)
## cleaned up
function xs_ys13a(vs, u::Vector{T}=first(vs), n::Val{N}=Val(length(u))) where {T,N}
plucki = i -> T[el[i] for el in vs]
ntuple(plucki, n)
end
function xs_ys13akw(vs; u::Vector{T}=first(vs), n::Val{N}=Val(length(u))) where {T,N}
plucki = i -> T[el[i] for el in vs]
ntuple(plucki, n)
end
function xs_ys13b(vs, u::Vector{T}=first(vs), n::Val{N}=Val(length(u))) where {T,N}
Tuple(T[el[i] for el in vs] for i in eachindex(u))
end
xs_ys14(vs) = Tuple(eltype(vs[1])[vs[i][j] for i in 1:length(vs)] for j in 1:length(vs[1]))
xs_ys14a(vs) = Tuple([vs[i][j] for i in 1:length(vs)] for j in 1:length(first(vs)))