From 60aa80574e365a1e0274573501668dad05f79302 Mon Sep 17 00:00:00 2001 From: Elex Date: Fri, 31 Mar 2023 01:13:15 +0900 Subject: [PATCH] 2023-03-31 --- .gitignore | 1 + src/array.jl | 26 ++++++++++++++++++++++++ src/array2.jl | 52 +++++++++++++++++++++++++++++++++++++++++++++++ src/array3.jl | 19 +++++++++++++++++ src/dictionary.jl | 20 ++++++++++++++++++ src/function.jl | 16 +++++++++++++++ src/hello.jl | 14 ++++++++++++- src/numbers.jl | 17 +++++++++++++--- src/set.jl | 16 +++++++++++++++ src/string.jl | 21 +++++++++++++++++++ src/string2.jl | 22 ++++++++++++++++++++ src/tuple.jl | 11 ++++++++++ 12 files changed, 231 insertions(+), 4 deletions(-) create mode 100755 src/array.jl create mode 100755 src/array2.jl create mode 100755 src/array3.jl create mode 100755 src/dictionary.jl create mode 100755 src/function.jl create mode 100755 src/set.jl create mode 100755 src/string.jl create mode 100755 src/string2.jl create mode 100755 src/tuple.jl diff --git a/.gitignore b/.gitignore index e69de29..e68d15f 100644 --- a/.gitignore +++ b/.gitignore @@ -0,0 +1 @@ +/.idea/** \ No newline at end of file diff --git a/src/array.jl b/src/array.jl new file mode 100755 index 0000000..0fc548c --- /dev/null +++ b/src/array.jl @@ -0,0 +1,26 @@ +#!/snap/bin/julia + +a = [] +println(typeof(a)) # Vector{Any} + +a = Int64[] +println(typeof(a)) # Vector{Int64} + +a = Array{Int64, 1}() +println(typeof(a)) # Vector{Int64} +a = Vector{Int64}() +println(typeof(a)) # Vector{Int64} + +a = zeros(5) +println(a) # [0.0, 0.0, 0.0, 0.0, 0.0] + +a = ones(Int64, 5) +println(a) # [1, 1, 1, 1, 1] + +a = [1;2;3] +println(a) # [1,2,3] +a = [1,2,3] +println(a) # [1,2,3] + +a = [1 2 3] +println(a) # [1 2 3] \ No newline at end of file diff --git a/src/array2.jl b/src/array2.jl new file mode 100755 index 0000000..6dbe68c --- /dev/null +++ b/src/array2.jl @@ -0,0 +1,52 @@ +#!/snap/bin/julia + +a = [1, 2] +b = [4, 5, 6] +println(a) # [1,2] + +push!(a, 3) +println(a)# [1,2,3] + +append!(a, b) +println(a) # [1,2,3,4,5,6] + +c = vcat(a, b) +println(a) # [1,2,3,4,5,6] +println(b) # [4, 5, 6] +println(c) # [1,2,3,4,5,6,4,5,6] + +x = pop!(a) +println(a) # [1,2,3,4,5] +println(x) # 6 + +x = popfirst!(a) +println(a) # [2,3,4,5] +println(x) # 1 + +deleteat!(a, 2) +println(a) # [2,4,5] + +pushfirst!(a,0) +println(a) # [0,2,4,5] + +c = a[end:-1:1] +println(a)# [0,2,4,5] +println(c)# [5,4,2,0] + +using Random # 셔플을 하려면 Random을 불러와야 한다. +shuffle!(a) +println(a) +sort!(a) +println(a)# [0,2,4,5] + +println(1 in a)# false +println(2 in a) # true + +println(length(a)) # 4 +println(maximum(a)) # 5 +println(minimum(a)) # 0 + +empty!(a) +println(a) # Int64[] + +println(isempty(a)) # true diff --git a/src/array3.jl b/src/array3.jl new file mode 100755 index 0000000..4de7a70 --- /dev/null +++ b/src/array3.jl @@ -0,0 +1,19 @@ +#!/snap/bin/julia + +a = [[1,2,3] [4,5,6]] # 열 우선 +println(a)# [1 4; 2 5; 3 6] +a = [1 4; 2 5; 3 6] # 행 우선 + +a = zeros(2, 3) # 2x3 크기의 행렬 +println(a)# [0.0 0.0 0.0; 0.0 0.0 0.0] + +a = fill("hello", 2, 3) +println(a)# ["hello" "hello" "hello"; "hello" "hello" "hello"] + +a = [[1,2,3] [4,5,6]] + +println(size(a))# (3,2) +println(ndims(a))# 2 + +println(a')# [1 2 3; 4 5 6] +println(permutedims(a)) \ No newline at end of file diff --git a/src/dictionary.jl b/src/dictionary.jl new file mode 100755 index 0000000..e59f4de --- /dev/null +++ b/src/dictionary.jl @@ -0,0 +1,20 @@ +#!/snap/bin/julia + +d = Dict("name"=>"Charlie", "age"=>13) + +d["gender"] = "male" + +for (k,v) in d + println("$k is $v") +end + +println(d["name"]) +println(get(d, "name", "noname")) + +for k in keys(d) + println(k) +end + +println(haskey(d, "job")) # false + +println(in("name"=>"Charlie", d)) # true \ No newline at end of file diff --git a/src/function.jl b/src/function.jl new file mode 100755 index 0000000..c9a0ab0 --- /dev/null +++ b/src/function.jl @@ -0,0 +1,16 @@ +#!/snap/bin/julia + +name = "World" +println("Hello, $name.") + + + +for i = 1:2, j = 3:4 + println((i, j)) +end + +try + sqrt("ten") +catch e + println("You should have entered a numeric value") +end \ No newline at end of file diff --git a/src/hello.jl b/src/hello.jl index 922fef0..c9a0ab0 100755 --- a/src/hello.jl +++ b/src/hello.jl @@ -1,4 +1,16 @@ #!/snap/bin/julia name = "World" -println("Hello, $name.") \ No newline at end of file +println("Hello, $name.") + + + +for i = 1:2, j = 3:4 + println((i, j)) +end + +try + sqrt("ten") +catch e + println("You should have entered a numeric value") +end \ No newline at end of file diff --git a/src/numbers.jl b/src/numbers.jl index c84f158..e6cf147 100755 --- a/src/numbers.jl +++ b/src/numbers.jl @@ -1,10 +1,10 @@ #!/snap/bin/julia x = 11 -println(typeof(x)) +println(typeof(x)) # Int64 y = 11.8 -println(typeof(y)) +println(typeof(y)) # Float64 println(Sys.WORD_SIZE) # 32 or 64 ... @@ -23,4 +23,15 @@ println(arr .^ 2) # [1,4,9] println(sin.(arr)) c = 2//3 + 1 -println(c) # 5//3 \ No newline at end of file +println(c) # 5//3 + + +a = 1 +b = 2 +Σ = a + b + +println(Σ) + + +println(rand()) # 0~1사이의 부동 소수 +println(rand(1:6)) # 범위 내의 정수 \ No newline at end of file diff --git a/src/set.jl b/src/set.jl new file mode 100755 index 0000000..73661c5 --- /dev/null +++ b/src/set.jl @@ -0,0 +1,16 @@ +#!/snap/bin/julia + +s = Set() + +s = Set([1,2,3,2,4,3,7,8]) + +println(s) # Set([4, 7, 2, 8, 3, 1]) + +set1 = Set([1,2,3]) +set2 = Set([4,2,3]) + +println(intersect(set1, set2)) # Set([2, 3]) +println(union(set1, set2)) # Set([4, 2, 3, 1]) +println(setdiff(set1, set2)) # Set([1]) + + diff --git a/src/string.jl b/src/string.jl new file mode 100755 index 0000000..884e1c4 --- /dev/null +++ b/src/string.jl @@ -0,0 +1,21 @@ +#!/snap/bin/julia + +str = "Hello, World!" + +println(str[1]) # 'H' +println(str[end]) # '!' +println(str[end-2]) # 'l' +println(str[3:6]) # 'llo,' + +name = "Charlie" +hello = string("Hello, ", name, "!\n") +println(hello) + +hello2 = "Hello, " * name * "!\n" +println(hello2) + +hello3 = "Hello, $name.\n" +println(hello3) + +hello3 = "Hello, $(name)!\n" +println(hello3) \ No newline at end of file diff --git a/src/string2.jl b/src/string2.jl new file mode 100755 index 0000000..dea3346 --- /dev/null +++ b/src/string2.jl @@ -0,0 +1,22 @@ +#!/snap/bin/julia + +str = "Hello, World!" + +println(firstindex(str)) # 1 +println(lastindex(str)) # 13 +println(length(str)) # 13 + +substr = SubString(str, 3,6) +println(substr) # llo, + +s = repeat("A", 4) +println(s) + +s = split(str, ",") +println(s) + +s = replace(str, ("l" => "L")) +println(s) + +s = join(["A", "B", "C"], ", ") +println(s) diff --git a/src/tuple.jl b/src/tuple.jl new file mode 100755 index 0000000..27620fb --- /dev/null +++ b/src/tuple.jl @@ -0,0 +1,11 @@ +#!/snap/bin/julia + +a = (1,2,3) +var1, var2 = a + + +println(var1)# 1 +println(var2)# 2 + +a = (x=1, y=2) +println(a.x)# 1