Closed24

知見01

麦茶が好き麦茶が好き

パッケージ管理方法

meiji@penguin:~/src/hitokage/Aoringo$ julia -q
julia> using Pkg

julia> Pkg.activate(".")
  Activating new project at `~/src/hitokage/Aoringo`

julia> Pkg.add("JuliaFormatter")
   Resolving package versions...
   Installed Tokenize ─────── v0.5.27
   Installed DataStructures ─ v0.18.16
    Updating `~/src/hitokage/Aoringo/Project.toml`
  [98e50ef6] + JuliaFormatter v1.0.45
    Updating `~/src/hitokage/Aoringo/Manifest.toml`
  [00ebfdb7] + CSTParser v3.3.6
  [a80b9123] + CommonMark v0.8.12
  [34da2185] + Compat v4.10.1
  [a8cc5b0e] + Crayons v4.1.1
  [864edb3b] + DataStructures v0.18.16
  [c27321d9] + Glob v1.3.1
  [682c06a0] + JSON v0.21.4
  [98e50ef6] + JuliaFormatter v1.0.45
  [bac558e1] + OrderedCollections v1.6.3
  [69de0a69] + Parsers v2.8.1
  [aea7be01] + PrecompileTools v1.2.0
  [21216c6a] + Preferences v1.4.1
  [0796e94c] + Tokenize v0.5.27
  [5c2747f8] + URIs v1.5.1
  [0dad84c5] + ArgTools v1.1.1
  [56f22d72] + Artifacts
  [2a0f44e3] + Base64
  [ade2ca70] + Dates
  [f43a241f] + Downloads v1.6.0
  [7b1f6079] + FileWatching
  [b77e0a4c] + InteractiveUtils
  [b27032c2] + LibCURL v0.6.4
  [76f85450] + LibGit2
  [8f399da3] + Libdl
  [56ddb016] + Logging
  [d6f4376e] + Markdown
  [a63ad114] + Mmap
  [ca575930] + NetworkOptions v1.2.0
  [44cfe95a] + Pkg v1.10.0
  [de0858da] + Printf
  [3fa0cd96] + REPL
  [9a3f8284] + Random
  [ea8e919c] + SHA v0.7.0
  [9e88b42a] + Serialization
  [6462fe0b] + Sockets
  [fa267f1f] + TOML v1.0.3
  [a4e569a6] + Tar v1.10.0
  [cf7118a7] + UUIDs
  [4ec0a83e] + Unicode
  [deac9b47] + LibCURL_jll v8.4.0+0
  [e37daf67] + LibGit2_jll v1.6.4+0
  [29816b5a] + LibSSH2_jll v1.11.0+1
  [c8ffd9c3] + MbedTLS_jll v2.28.2+1
  [14a3606d] + MozillaCACerts_jll v2023.1.10
  [83775a58] + Zlib_jll v1.2.13+1
  [8e850ede] + nghttp2_jll v1.52.0+1
  [3f19e933] + p7zip_jll v17.4.0+2
Precompiling project...
  4 dependencies successfully precompiled in 44 seconds. 12 already precompiled.

julia> exit()
麦茶が好き麦茶が好き

ソースコード

strings = readline() |> collect

@show strings

入力

meiji@penguin:~/ramenya$ julia sample.jl 
pusan
strings = ['p', 'u', 's', 'a', 'n']
麦茶が好き麦茶が好き

ソースコード

for i = 1:3, j = 1:3, k = 1:3
    println("$i $j $k")
end

実行結果

meiji@penguin:~/ramenya$ julia sample.jl 
1 1 1
1 1 2
1 1 3
1 2 1
1 2 2
1 2 3
1 3 1
1 3 2
1 3 3
2 1 1
2 1 2
2 1 3
2 2 1
2 2 2
2 2 3
2 3 1
2 3 2
2 3 3
3 1 1
3 1 2
3 1 3
3 2 1
3 2 2
3 2 3
3 3 1
3 3 2
3 3 3
麦茶が好き麦茶が好き

Float64型の値を整数かどうか判定する方法

help?> isinteger
search: isinteger

  isinteger(x) -> Bool

  Test whether x is numerically equal to some integer.

  Examples
  ≡≡≡≡≡≡≡≡

  julia> isinteger(4.0)
  true

julia> typeof(4.0)
Float64

julia> isinteger(4.0)
true
麦茶が好き麦茶が好き

パッケージは、PkgTemplates.jlで作成するらしい。今まで手動で作っていたので、次回はPkgTemplates.jlにお任せしよう。

麦茶が好き麦茶が好き

今日からは、次のコマンドを使ってみる。

xsel --clipboard --output | julia 200b.jl
麦茶が好き麦茶が好き

文字種別毎に数え上げる

s = split(readline(), "")

dict = Dict{String, Int}()

for key in s
    key ∈ keys(dict) ? dict[key] += 1 : dict[key] = 1
end
麦茶が好き麦茶が好き

String型からChar型に変換する

julia> str = "i"
"i"

julia> typeof(str)
String

julia> first(str)
'i': ASCII/Unicode U+0069 (category Ll: Letter, lowercase)

julia> typeof(first(str))
Char
このスクラップは3ヶ月前にクローズされました