Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

はじめての数論 with Ruby (v. v.) (関西Ruby会議03 LT)

2,268 views

Published on

関西Ruby会議03 (2010/11/6)のLightning Talksで発表したものです。

Published in: Technology, Education
  • Be the first to comment

  • Be the first to like this

はじめての数論 with Ruby (v. v.) (関西Ruby会議03 LT)

  1. 1. li L:6’1>'C0)§5l§fi With Ruby (V. V. ) l, ’r}‘&: [Ryu Nzigziil sushizuto :1 |3ElERuby€: ’§$03 Tld: Li61)‘C0)fi? n‘i with Ruby (v. v. )J
  2. 2. person(: shizuto) . introduce > fi’= HiA«7+%7°III’J“57 > 7‘: “Lf: l,Co D'7°fi= ’r’1‘fi75.tE'C~‘Tc| ¢‘:7‘JRubytfJ‘. . > 7T: §I$‘V= $/u » ¥¥5I§fi(§I§fi%§1EI)«’°o'C$L,7‘: o > §E§t! ¥% » EIIFEE > $333 »75>x% >9fiu7% > Ruby > 2 |3§ERuby€: ‘303 | 'liL1&)‘C0)fi§n‘B with Ruby (v. v. )J
  3. 3. ii L‘L<V)T0)Ruby (3"FL0)ia%’S) C: ¥Users¥Shizuto>irb irb(main) 00120) 2**i024 = > 17976931348623i5907729305i90789024733617976978942 30657273430081i57732675805500963i3270847732240753602 I1201138798713933576587897688i44i6622492847430639474 I243777678934248654852763022196012460941194530829520 8500576883815068234246288i4739i3ii05408272371633505i 06845862982399472459384797163048353563296242241372i6 irb(main)I0O2I0> 3 E5lERuby’z%§§03 | 'iiLZ&’)‘C0)§$I§ii with Ruby (v. v. )J
  4. 4. i%5z$i: RubyE-i; =E o 'Co'L/ L31 5 '5'. ‘/7’)l»é: l,’C. 5*e$%*5zi%L. EL: ca+$6'. . 4 EE-lERuby’z‘: §§03 | 'iiL2&’)‘C0)§$I§ii with Ruby (v. v. )J
  5. 5. %e&&m? ii (E £3*€'l3‘, -'r‘<). ‘f:9iéfiI0)i*~D7‘J“§ Erc‘: %L, <72£Z9f: %‘§éfl0>. :c‘: 1911 40>i9§azi; t1,2. 1+ 2 = 3.. 4i: I?E%§2fi’C‘i: i7Z£Lo 60)ifi'Ji3ifil2lZ1,2,3o 1+ 2 + 3 = 60 6ii? E’£§é5I. . 120). ‘i: ‘~Ji€Ii; t1,2,3.4,6o 1+2+3+4+6= 16.. 12ii? ‘?: %§fi'Gi3t7?; l,o 5 E§lERuby’z‘: §§03 | 'iiL2&’)‘C0)§$I§ii with Ruby (v. v. )J
  6. 6. §rt-§-- :2/‘Zn §|13E0)$>Za2€‘/ “Jl~“i: §a‘-EIJLJI5 ’}‘LFf’). 3—l~°*&fiE7‘J‘2S")7faIf)“| ‘o%’~L'CLi'}‘é —lfli_L,7”: <'/ §i’3T: “o—’: §‘l35JT: ‘H'_lfi'_‘l‘; *?o '%‘iEit: b<uZ§§7‘otFo. i§75v57)i, :i")7<‘. /.EZ§ELot5 %‘l§l0)1%%id: - - - %'JL)t)]9rL%'a7’Jc‘: °’375$'J/ “u"JTZa (divided_by? ) iUéfi0>'J7I~%: vi’iE%a (| ist_of_divisor) . ‘i‘~]§3fi0)r°if‘a? $lJ’¢“'E3.“r5.s'%'L7f?9 (sum/ of/ divisor) Jfiéifil/ J‘cE575‘45ll/ till’? -%l) (complete? ) 6 BE-lERuby’z‘: §§03 | 'iiLi&’)‘C0)§3IEii with Ruby (v. v. )J
  7. 7. TXbE§_9 describe 'lnteger' do describe '#divided_by? (i)' do it 'should judge if it is divided by i’ do l0.divided_by? (5). should be_true I8. div ided_by? (4). should be_fa| se end and describe '#comp| ete? ' do it ‘should judge if it is a complete number’ do 6. complete? . should be_true i2.comp| ete? .shou| d be_fa| se end end end P 7 | ¥lERuby‘£‘7fi03 | 'id: L'. &b‘C0)&§u‘i with Ruby (v. v. )J
  8. 8. :—FE%:5 class integer def divided by7(i) self / i * i = = self end def llSl of d visor ary = [J for i in l. .self ary << i if divided_by? (i) end ary end def c0*p| ete7 return false if self = 0 sum_of_divisor = = self end end 8 F§5lERuby%§§03 | 'li| .ZN)‘C0)fi§fii with Ruby (v. v. )J
  9. 9. L 3‘. 5*-Eéiéit 5 D ¥test¥ntheory>irb -r ntheory. rb irb. ..> for i in l. .l00O00 irb. ..> puts "#li} is complete" if i. comp| ete? irb. ..> end 6 s complete 28 is complete 496 is complete 8128 is complete = > I . l00000 9 F§5lERuby%§§03 | 'li| .ZN)‘C0)fi§fii with Ruby (v. v. )J
  10. 10. F §l. 7":75O7’: Z c‘: » Rubyl: l:Web’€= SC$§| l7‘: “l‘tL‘L«’=72iL ! > ailiiztiliiifi”. l§L$L, ..t5o > fi§‘iii’&%"'= ,S‘i0)l: . Rubyo‘Cfi*| l ! > iHi%~. ;§fil:7J‘)75i#; f£l1't°. 7°El’7‘5E‘/7‘? 'ZatilZ%§El’~]l: §=i7l< ll: ?”*5:tl: t,E*3'C. Ififihiifiiéo > '7‘—’5'£»7‘: <é/ ui§'r4‘o9rL%)o » IEiE7i. t.l_—. :7p. .: A;7:: §E—: ‘C%'%¥zb»5AJ7‘: “7:'375? » 5:57:95. $iiiaea¢s~t= a=. !rFaiHizotEa%5ia7t; . :25», 10 |3ElERuby‘%7fi03 | 'l: l:Li&)‘C0)fi§ii‘i with Ruby (v. v. )J
  11. 11. 11 ’ 4 * 4. r' ‘A-4:. — . —c. r_: . r—. _ V . ,1; 3 . . . 1 .1‘ . . ‘ ~. - »_. _' {I ; I;; . ‘ V . ll? ’ . 05;, ". _‘ ; "'i r ' . " —-—. ag. . ‘A it »‘ : --. _.. - . ... ... .* , . at . , — _. ——_. .q ‘ ‘ -. .. "" *1’ ~. ~L. -.a. .____ ' . ... . . . . _ : ’ ' - v n u 0‘, ._g _ " ’ . _ ii 4 1 -- . qz eeee _— . _,. .. F$5lERuby%§§03 | 'li| .ZN)‘C0)fi§fii with Ruby (v. v. )J

×