算額あれこれ

算額問題をコンピュータで解きます

2021-08-01から1ヶ月間の記事一覧

Julia で花菱をモチーフとした模様を描く(3)

Julia で花菱をモチーフとした模様を描く(3) include("plotter.jl") function hanabisi3(nx=6, ny=6; r=1, fcol1=:darkturquoise, fcol2=:green3, fcol3=:lightpink, fcol4=:lightsalmon, backcol=:cornsilk, circlecol=:gold, width=600, height=400) plo…

Julia で花菱をモチーフとした模様を描く(2)

Julia で花菱をモチーフとした模様を描く(2) include("plotter.jl") function hanabisi2(nx=6, ny=6; r=1, fcol=:brown, backcol=:cornsilk, width=600, height=400) plotbegin(w=width, h=height) nx += 1 ny += 2 x1, y1, x2, y2 = 2r, r*sqrt(3), (2nx+…

Julia で花菱をモチーフとした模様を描く(1)

Julia で花菱をモチーフとした模様を描く(1) include("plotter.jl") 以下の関数は単位としての花菱を1つ描く。 function hanabisi(x, y; r=1, lwd=2, fcol=:black, backcol=:white, frame=false, framecol=:red) u = r / 280 tangent = 5/7 plotcircle(x +…

家紋シリーズ 鱗(3) 六つ鱗

家紋シリーズ 鱗(3) 六つ鱗 include("plotter.jl") function mutuuroko(; r=1, width=400, height=400) plotbegin(w=width, h=height) plotpolygon2(0, 0, r, 3, lwd=0, fcol=:black) plotpolygon2(0, 0, r, 3, φ = 30, lwd=0, fcol=:black) plotpolygon2(0,…

家紋シリーズ 鱗(2) 三つ鱗,丸に三つ鱗

家紋シリーズ 鱗(2) 三つ鱗,丸に三つ鱗 include("plotter.jl") function mituuroko(; r=1, width=400, height=400, maru=false) u = sqrt(3)/6*r !maru && plotbegin(w=width, h=height) plotpolygon2(0, u, u, 3, lwd=0, fcol=:black) plotpolygon2(r/4, -…

家紋シリーズ 鱗(1) 丸に一つ鱗

家紋シリーズ 鱗(1) 丸に一つ鱗 include("plotter.jl") function marunihitotuuroko(; r=1, width=400, height=400) u = r/140 plotbegin(w=width, h=height) plotcircle(0, 0, 70u, fcol=:black) plotcircle(0, 0, 57u, fcol=:white) plotpolygon2(0, 0, 54…

家紋シリーズ 梅(9) 八重向こう梅

家紋シリーズ 梅(9) 八重向こう梅 include("plotter.jl") function yaemukouume(; r=1, width=400, height=400) u = r/72 plotbegin(w=width, h=height) for i = 54:72:342 plotcircle(43u*cosd(i), 43u*sind(i), 31u, fcol=:black) end for i = 18:72:306 p…

家紋シリーズ 梅(8) 向こう梅

家紋シリーズ 梅(8) 向こう梅 include("plotter.jl") function mukouume(; r=1, width=400, height=400) u = r/72 plotbegin(w=width, h=height) for i = 18:72:306 plotcircle(43u*cosd(i), 43u*sind(i), 28u, fcol=:black) end plotcircle(0, 0, 40u, fcol…

家紋シリーズ 梅(7) 八重梅,丸に八重梅

家紋シリーズ 梅(7) 八重梅,丸に八重梅 include("plotter.jl") function yaeume(; r=1, width=400, height=400, maru=false) u = r/70 ! maru && plotbegin(w=width, h=height) for i = 54:72:342 plotcircle(46u*cosd(i), 46u*sind(i), 26u, fcol=:black) …

家紋シリーズ 梅(6) 梅の花,丸に梅の花

家紋シリーズ 梅(6) 梅の花,丸に梅の花 include("plotter.jl") function umenohana(; r=1, width=400, height=400, maru=false) u = r/70 ! maru && plotbegin(w=width, h=height) for i = 18:72:306 plotcircle(46u*cosd(i), 46u*sind(i), 26u, fcol=:blac…

家紋シリーズ 梅(5) 丸に剣梅鉢

家紋シリーズ 梅(5) 丸に剣梅鉢 include("plotter.jl") function marunikenumebati(; r=1, width=400, height=400) u = r/70 plotbegin(w=width, h=height) plotcircle(0, 0, r, fcol=:black) plotcircle(0, 0, 58/70*r, fcol=:white) x = [-20.33,-20.33,26…

家紋シリーズ 梅(4) 丸に星梅鉢

家紋シリーズ 梅(4) 丸に星梅鉢 include("plotter.jl") function marunihosiumebati(; r=1, width=400, height=400) u = r/70 plotbegin(w=width, h=height) plotcircle(0, 0, r, fcol=:black) plotcircle(0, 0, 60u, fcol=:white) plotcircle(0, 0, 14u, fc…

家紋シリーズ 梅(3) 丸に梅鉢

家紋シリーズ 梅(3) 丸に梅鉢 include("plotter.jl") function maruniumebati(; r=1, width=400, height=400) u = r/70 plotbegin(w=width, h=height) plotcircle(0, 0, 70u, fcol=:black) plotcircle(0, 0, 58u, fcol=:white) plotpolygon2(0, 0, 18u, 5, φ…

家紋シリーズ 梅(2) 加賀梅鉢

家紋シリーズ 梅(2) 加賀梅鉢 include("plotter.jl") function kagaumebati(; r=1, width=400, height=400) u = r/25 plotbegin(w=width, h=height) plotpolygon2(0, 0, r, 5, φ=54, fcol=:black) plotcircle(0, 0, 16u, fcol=:white) for i = 0:36:324 plot…

家紋シリーズ 梅(1) 梅鉢

家紋シリーズ 梅(1) 梅鉢 include("plotter.jl") function umebati(; r=1, width=400, height=400) u = r/23 plotbegin(w=width, h=height) plotpolygon2(0, 0, 23u, 5, φ=54, fcol=:black) plotcircle(0, 0, 14u, fcol=:white) for i = 0:36:324 plotline(0…

Julia の小ネタ--034 13日の金曜日

「次の 13 日の金曜日はいつか?」は Dates パッケージで簡単に求まる。 2021/01/01 〜 2029/12/31 までの 13 日の金曜日は? using Datesdr = Date(2021):Day(1):Date(2029, 12, 31);result = filter(dr) do x dayofweek(x) == Fri && day(x) == 13end#=14-…

Julia の小ネタ--033 大きな配列も省略せずに全部表示

多くの言語において,REPL では大きな配列は全部表示しないで途中を省略して表示する。 それは便利だが,ときどき全部表示したいときもある。 そんなとき Julia ではこうする。 x = randn(50, 3); 制限なしにするio = IOContext(stdout, :limit => false)Bas…

Julia の小ネタ--032 IO バッファー

入力バッファー 複数行の文字列 a ="""10 200abc defxyz""" a は "10 200\nabc def\nxyz\n" という文字列と同じ。つまり,改行文字 "\n" が含まれる。 文字列を IO バッファーに設定する。 io = IOBuffer(a)#=IOBuffer(data=UInt8[...], readable=true, writ…

Julia の小ネタ--031 日本語での月と曜日の名前と略称

日本語での月と曜日の名前と略称 using Dates 最初に以下を定義しておく japanese_months = ["睦月", "如月", "弥生", "卯月", "皐月", "水無月", "文月", "葉月", "長月", "神無月", "霜月", "師走"];japanese_monts_abbrev = string.(1:12) .* "月";japane…

Julia で,k 番目の順列を取得するプログラム

順列を一瞬で取得するプログラムhttps://itakanaya9.hatenablog.com/entry/2014/02/17/121428 を Julia に移植する。 function nthpermutation(x, k) k -= 1 result = x if k > 0 x = copy(x) n = length(x) reminder = zeros(Int, n) for i = 1:n reminder[…

Julia で,ベクトル要素の全てと互いに素である整数のリストを求める

お題 ベクトル要素のそれぞれと互いに素である整数のリストを求める ベクトル a の全ての要素との gcd(最大公約数)が 1(つまり,互いに素)である m 以下の整数を列挙する。例えば,a = [4, 6] で,m = 20 のときa に含まれる数の約数は,2, 3 の2個1 〜 …

Julia で円をモチーフにした格子模様を描く with cherry blossoms(5)

Julia で円をモチーフにした格子模様を描く(5) plotter.jl を include sangaku0418.hatenablog.com include("plotter.jl") function en5(nx=6, ny=5; r=1, factor=0.985, width=600, height=400) function unit(x, y, r) deg = 180:0.25:270 xs = zeros(le…

Julia で円をモチーフにした格子模様を描く(4)

Julia で円をモチーフにした格子模様を描く(4) plotter.jl を include plotter.jl sangaku0418.hatenablog.com include("plotter.jl") function en4(nx=6, ny=5; r=1, factor=0.985, width=600, height=400) function unit(x, y, r) deg = 180:0.25:270 xs…

Julia で千鳥格子を描く

Julia で千鳥格子を描く 千鳥格子は利休間道(りきゅうかんとう)ともいい,英語ではハウンズ・トゥース(猟犬のキバ)とのこと。 plotter.jl をインクルード sangaku0418.hatenablog.com include("plotter.jl") function chidorigousi(nx, ny; a=1, width=6…

Julia で亀甲ベースの格子模様を描く(8)

plotter.jl を include sangaku0418.hatenablog.com plotter.jl に plotarc() を追加した(未完成だが一応使える) include("plotter.jl") function kikkou8(nx=6, ny=5; r=1, R=0.7r, width=600, height=400) function unit(x, y, r, R) udrl1 = [:left, :l…

Julia で亀甲ベースの格子模様を描く(7)

Julia で亀甲ベースの格子模様を描く(7) plotter.lj を include sangaku0418.hatenablog.com plotter.jl に plotarc() を追加した(未完成だが一応使える) include("plotter.jl") function kikkou7(nx=6, ny=5; r=1, d=r/3, width=600, height=400) funct…

Julia で亀甲ベースの格子模様を描く(6)

plotter.jl を include sangaku0418.hatenablog.com plotter.jl に plotarc() を追加した(未完成だが一応使える) include("plotter.jl") function kikkou6(nx=6, ny=5; r=1, d=r/4, width=600, height=400) function unit(x, y, r, d) udrl1 = [:lower, :l…

Julia で円をモチーフにした格子模様を描く(1)

plotter.jl を include sangaku0418.hatenablog.com lwd を適当(適切)に変えてください。 include("plotter.jl") function en(nx=6, ny=5; r=1, lwd=2, width=600, height=360) x1, y1, x2, y2 = 4r, r, 5r + (2nx+2)r -3r, (2ny+1)r println("(width, hei…

Julia で正方形基準の格子模様を描く(3)

Julia で正方形基準の格子模様を描く(3) plotter.jl を include sangaku0418.hatenablog.com include("plotter.jl") function asanoha7(nx=6, ny=5; a=1, width=600, height=400) function unit(x, y, a) xy = [0 0; 4a 0; 4a 4a; 0 4a; 0 0; 3a a; 4a 4a;…

Julia で正方形基準の格子模様を描く(2)

Julia で正方形基準の格子模様を描く(2) plotter.jl を include sangaku0418.hatenablog.com include("plotter.jl") function asanoha6(nx=6, ny=5; a=1, width=600, height=400) function unit(x, y, a) xy = [0 0; 4a 0; 4a 4a; 0 4a; 0 0; 3a a; 4a 4a;…