Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
LT20261017
Search
denkyuu1
October 13, 2026
16
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
LT20261017
denkyuu1
October 13, 2026
More Decks by denkyuu1
See All by denkyuu1
LT20260516.pdf
denkyuu1
0
20
Featured
See All Featured
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
2
360
We Are The Robots
honzajavorek
0
400
From π to Pie charts
rasagy
1
400
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
520
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
Site-Speed That Sticks
csswizardry
13
1.6k
4 Signs Your Business is Dying
shpigford
187
23k
Done Done
chrislema
187
17k
The SEO identity crisis: Don't let AI make you average
varn
0
590
Abbi's Birthday
coloredviolet
4
10k
Optimizing for Happiness
mojombo
378
71k
Art, The Web, and Tiny UX
lynnandtonic
304
22k
Transcript
回文 1
自己紹介 denkyuu1 学部2年 でコードゴルフやってます おすすめサイト https://code.golf AtCoder(アルゴリズム)茶色になりました! Ruby, Julia 2
内容 ソースコードが回文になっているプログラムを書こう Rubyで挑戦します アイデア紹介と実際のコード if ~ fi 3
結果 print("abc") # )"cba"(tnirp 4
ルール コメント # ・変数展開 "#{var}" , "#$var" 禁止 "#{p 1}
}1 p{#" 禁止 エスケープシーケンス禁止 eval ["t\n", "n\t"] #エスケープシーケンス 改行は CRLF(\r\n) ではない(条件ゆるめ) 5
回文プログラムを調べた結果 様々な言語 回文の後半をコメントアウト エスケープシーケンス "\"" 文字列の区切りを変える Ruby を使う これより下の行は動かない __END__
6
構造 変数定義 計算 print tnirp 算計 義定数変 7
代入 abc = xyz zyx = cba a+=b # 加算代入
b=+a # 単項プラス a-=b b=-a 制約 回文にするとき a b はどちらも変数でなければならない 8
進数 16 ax0 = 0xa # 末尾がa-f 数値を逆にするとアルファベットが先頭にくる 変数の条件を満たす! 9
難所 かっこの対応 "( )".reverse # ") (" 未定義の変数によるエラー 型によるエラー 10
パターンマッチ? 10 => a # 右代入 a >= 10 #
比較 10 の部分は変数じゃなくてもいい! 11
完成! メソッドと変数が同じ名前 p 1 => p p p p >=
1 # 1 右代入(変数) -> 出力(メソッド・変数) -> 比較(変数) 例 "Hello, World!" => p p p p >= "!dlroW ,olleH" 12
print も使える 1 => print 2 => tnirp print tnirp
print >= 2 tnirp >= 1 出力 2 の逆 print >= 1 でエラーが出ないようにするため 先に print に右代入 1 => tnirp 13
短絡評価でエラー回避 括弧の対応が難しい! true && p 1 # syntax error true
&& (p 1) # 1 true && p(1) # 1 でうまい方法を発見 Stack Exchange stackexchange Palindromic palindrome checker [closed] CC BY-SA 2.5 https://codegolf.stackexchange.com/questions/1798/palindromic-palindrome-checker 14
代入 短絡評価と代入を組み合わせる x = a || b b || a
= x x = (a || b) # xに a || b を代入 b || (a = x) # bをtrueにしておけば a = x は実行されない(aは変数) 15
print への代入なし ax0 = 0xa cx0 = 0xc tnirp =
0xc - 0xa || print print tnirp tnirp || ax0 - cx0 = print cx0 = 0xc ax0 = 0xa 出力 2 は 12 - 10 = 2 0x2 の逆 2x0 は変数名にできない 短絡評価 0xc - 0xa 16
print への代入なし その2 2 => a tnirp = a ||
print print tnirp tnirp || a = print a >= 2 出力 2 短絡評価 a >= 2 でエラーが出ないようにする 17
変換して1を足す Int gets と短絡評価の部分はStack Exchange参考 g = gets || 1
g => s a = s || 1 b = Integer regetnI = a b + 1 => p p p p >= 1 + b a = Integer regetnI = b 1 || s = a s >= g 1 || steg = g 18
構造 コード 内容 備考 1 => a 変数定義 ax0=0xa 計算
出力する値を計算 pp 出力 ax0=0xa 比較・代入 エラーが出ないよう注意 a >= 1 19
ループは作れる? 未完成 ブロックは難しそう 再帰関数? 予約語 Ruby 4.0 リファレンスマニュアル 字句構造 {}
https://docs.ruby-lang.org/ja/latest/doc/spec=2flexical.html 20
参考文献 Yukku / Quines / Qalindrome_quine.js https://github.com/Yukkku/Quines/blob/main/Qalindrome_quine.js stackexchange Palindromic palindrome
checker [closed] CC BY-SA 2.5 https://codegolf.stackexchange.com/questions/1798/palindromic-palindrome-checker KvanTTT (Sep 12 2020 at 19:36) How to write Palindrome Polyglot Quines https://habr.com/en/articles/468711/ まめめも (2008-01-10) palindromic quine https://mametter.hatenablog.com/entry/20080110/p1 Ruby のメソッド呼び出しと変数参照について注意すること https://secret-garden.hatenablog.com/entry/2020/09/19/000342 21
ご清聴ありがとうございました 22