Ȼ/12

Top / Ȼ / 12

βˤĤ

ơβˤĤ褦ƷǤȰʲΤȤǤ롥

եȥեϤξȤɬפ롤ξץ񤱡ϰʲ̤Ǥ롥

  1. ѤΥǡäƤե̾Ĥεưѥ᡼ȤƤ餦
  2. ¹ԻˤޤϺǽ˥եΥХååפԤ
  3. Ĥεưѥ᡼1ʸǤ롥ʸ c ɽƤȡץϥǡγƹԤʸ c ʸޤǤ뤫Ĵ١output.dat Ȥե˹ֹȶ˽Ϥ.


ι¤

ĤΤ褦ˡޤι¤Ϥ褦
ݤʤȤϴؿɤФܤ§äơĤΤ褦ˤʤ

  1. include Math
  2. require "fileutils"
  3.  
  4. # ʸʸ餦ȡʸǤƤ뤫򥫥Ȥ
  5. def c_count(st, c)
  6.   # ϤȤ
  7.   return 0
  8. end
  9.  
  10. # ե̾餦ȡХååפԤ
  11. def backup(fn)
  12.   # ϸ
  13. end
  14.  
  15.  
  16. # ʲץ
  17.  
  18. # ϥե̾
  19. input_fn = ARGV[0]
  20.  
  21. # ʤ餫򤹤˥Хååפ
  22. backup(input_fn)
  23.  
  24. # ٤ʸ
  25. search_char = ARGV[1]
  26.  
  27. # ϥեΥץ
  28. in_f = open(input_fn,"r")
  29. out_f = open("output.dat","w")
  30.  
  31. # Ԥɤ߹ǡʸ򥫥,
  32. line_number = 1
  33. while (line = in_f.gets) do
  34.   line.chomp!
  35.  
  36.   # ιԤˤʸʸäƤ뤫롥
  37.   count = c_count(line,search_char)
  38.  
  39.   # ̤Ϥ
  40.   out_f.print(line_number, " : ", count, "\n")
  41.  
  42.   #  ܤΥȤ䤹
  43.   line_number += 1
  44. end
  45.  
  46. # եβ
  47. in_f.close
  48. out_f.close

warning.png ݥȤϡ֥Хååϲǽʸ¤ʳǹԤפȤ



NG.png Хåå¾ä˥ե open ʤɤԤΤϤʤ٤򤱤٤
ϡopen Υ⡼ɻְ㤨ȡեȤ̵ʤäƤޤХååפϤִפΰƶʤ褦˥եȤƤȤäƤȤʤΤ顤֤Ϥ褯褯ͤ褦



ΰƶͽ¬
ץ٤

ȤȤˤʤ롥


ؿμ: Хåå

ޤϴñʥХåå״ؿμȤäƤñ˥ԡ򤹤ФޤѤ­ΤǡΤ褦˴ñ˽񤱤롥
󡤲ʬΥХååפȤʬȤäư̤򤫤̵̤򸺤餹ȤȤС󥳥ȥ륽եȤȤȤѤϤǤ⤢ΤǡĴ٤ƤߤΤ褤

# ե̾餦ȡХååפԤ
def backup(fn)

  # Хååץե̾롥
  bk_fn = fn + ".bak"

  # Хåå(ñʤ륳ԡ)
  FileUtils.cp(fn,bk_fn)

end


ؿμ: ʸ

δؿ⤽ʤѤǤϤʤޤǤμϰľ˹ͤ㤨аʲΤ褦ˤʤ

# ʸʸ餦ȡʸǤƤ뤫򥫥Ȥ
def c_count(st, c)

  count = 0
  for i in 1..st.length do
    if (c == st[i-1].chr) then
      count += 1
    end
  end
  
  return count
end

warning.png (Ը) ʤߤˡRuby ˤ .count Ȥ̿᤬롥Ĵ٤ƻȤäƤߤΤ褤


ưŪײˡɤ

ơϥޥɱǤϤʤץऽΤΤƤ
ƵѤץؤϤεդΤ򶵤褦
ưŪײˡ(ɤ)ȤΤǤ롥ΤˤϡκƵ򺣰ٻפФ
Ƶˤץߥ󥰤ȤϡޤȤƤޤ

[Ƶˤץߥ󥰤Ȥ]
꾮ʬ䤷
Ǹߤ = 꾮Ȥ߹碌
Ȥ񤤤ơȤϤǤ

ȤΤǤäСʬ䤷סֺǸ饢ץˡǤ롥ФưŪײˡȤϡʬ䤷סְ־꤫饢ץˡǡɸŪ˽񤤤Ƥޤ

[ưŪײˡɤˤץߥ󥰤Ȥ]

꾮ʬ䤷
־򤤤ơ¸Ƥơ
ѤƼ˾򤤤ơ¸
ơ Ȥ֤ǺǸޤä齪λ

ȤΤǤ롥


warning.png ưŪײˡΰյ,
򾮤ʬ򤷤ơزɬפΤʤΤƤĤġɬפ򾮤򤤤ƤȤߤ碌ĤĤ礭򤯡
ȤΤǡŬФƼ˻ȤΤǤ롥ưŪפȤΤϡ͡ȽǤ׻ǹԤ뤳ȤĤƤ롥
ʬ򤷤ƾ򤯤ȤʬˤĤƤΤƤ뤬ΡزɬפΤʤΤƤ٤ȤǷ׻̤ʤΤǡ¤ϽפʤȤ򤹤ˤŪʺγؽʳǤϲ٤ŤΤǡˤĤƤϺʤԤϤ줾Ĵ٤ƤߤΤ褤

ơԥʤ顤򤤤Ĥ

ưŪײˡɤȺƵ

եܥʥå(Fibonacci)

ޤ˥ץߥ󥰤ԤäȤΤեܥʥåˤȤ
եܥʥåˡˤϡƵȥ롼פˤ̤꤬ꡤ줾ħץߥ󥰤ˤĤƳؤ
¤ϡΡ֥롼פˤˡפǤưŪײˡɤˤˡǤäΤ
ơޤˤȼΤ褦ʴطˤʤ롥

fibonacci-alg.png

ɤˡ⡤꾮Ѥ礭ȤʬפˤĤƤƱˡǤ뤬뤿ιͤθդǤ롥
ܤ褦

warning.png 㤢ɤǤƱ󡤤Ȼפʤ졥եܥʥåϡֿפʤΤǡʬή줬1ŪʤΤǡƱ˸Τ줫ǡĤƱǤʤȤʬäƤ


ĥ꡼(ڹ¤)ΥΡɤδط

ˡʬ(Ρɤβ˥åܤĥ꡼)ǡΡɤο
ܤƤΡɤˤĤƤ = ľΥΡɤˤĤƤιס
Ȥطˤͤ褦
ȤƤϡ(ֲΥΡ)פˤϴ˿ͿƤȤơ־ΥΡ()ˤĤ٤Ĥ衤ȤȤ褦
ޤˤȡ㤨мΤ褦ʤΤˤʤ롥

tree.png

ФơޤƵǷ׻뤿Υץ򼨤

  1. include Math
  2.  
  3. # f ͤؿ
  4. def f(i,j)
  5.  
  6.   # դοʬäƤ롥
  7.   if (i==3) then
  8.     ini = [1, 5, 2, 4, 3, 1, 2, 6]
  9.     return ini[j-1]
  10.   end
  11.  
  12.   # հʳϺƵǡ
  13.   return f(i+1, 2*j-1) + f(i+1, 2*j)
  14.  
  15. end
  16.  
  17. # ͤ׻ơɽ롥
  18. print(f(0,1),"\n")

ä񤷤ȤϤʤ

ơưŪײˡɤˤäƷ׻ץ(ξñʤ롼פ)򼨤

  1. include Math
  2.  
  3. # ʬڤäơ­Ƥäƺ֤ͤ(դΥǡʬäƤȲꤷ)
  4. def calc_top(f)
  5.  
  6.   for i in 1..(f.size-1) do
  7.  
  8.     # Ȥ׻Ƥ(depth = f.size-2, f.size-3, ..., 1, 0)
  9.     depth = (f.size-1) - i
  10.  
  11.     # ʿȤ2Ĥ­.
  12.     #  0 ϤޤΤǤΤޤ޻Ȥ뤬֤ 1 ϤޤΤǡ1 ƻȤȤˤʤ롥
  13.     for j in 1..(2**depth) do
  14.       f[depth][j-1] = f[depth+1][2*j -2] + f[depth+1][2*j -1]
  15.     end
  16.  
  17.   end
  18.  
  19.   # f(0,1) ֤źԹ f(0,1) f[0][0] Ȥʤ뤳Ȥ.
  20.   return f[0][0]
  21.  
  22. end
  23.  
  24.  
  25. # Ȥ f
  26. f = Array.new(4){ Array.new(8){ 0 } }
  27.  
  28. # դʬΥǡ
  29. f[3] = 1, 5, 2, 4, 3, 1, 2, 6
  30.  
  31. # f ͤ׻
  32. ans = calc_top(f)
  33.  
  34. # Τꤿͤɽ
  35. print(ans,"\n")


ưŪײˡɤɤΤ狼äƤȻפ
ǡƵӤħҤ٤褦褽Τ褦ʴ

[ưŪײˡɤ]

  • ⲽ̵κƵ١Ū˥ץब®ư
  • ¦򤯤ΤǡץưǤ狼䤹
  • ˤäƤϡץष䤹

[ưŪײˡɤη]

  • ˴طʤ׻(= )򤷤ƤޤȤ
  • ˤäƤϥץबʣˤʤäƤޤ


ħΤ˴طʤ׻(= )򤷤ƤޤȤפȤˤĤƤ狼ˤ󤲤褦㤨СΤ褦ʾǺͤȤ褦

tree2.png

ǥåڤƤ뤿˰ֲ 3+1 ʬη׻פʤΤǡͿˤäƤϤ줬ȽưŪײˡɤȷ׻򤷤ƤޤȤˤʤ롥η׻Ťäꡤоݤ礭ʥդǡڤƤս꤬ˤäꤹȤ֤礭ʤ뤳Ȥˤʤ롥ƵɬפʤΤ׻Τạ̇̄ǤΥϤʤ


դ˥ⲽ̵κƵȥʷ׻󤲤ƤޤǤ롥

tree3.png

ξ硤ⲽ̵κƵȲƱ׻򤹤뤳Ȥˤʤꡤʬ̵̤ˤʤ롥

warning.png Τ褦ˡʬ䤹ȤŪʥǥƱºݤΥץȤƤˤäƺƵưŪײˡɤ˸Ը롥ΰ㤤ϻιͻˤäʬ뤳Ȥ¿ΤǡץȤ夤ƹͤ褦

warning.png (Ը) ޤǤäȽǤȡ֥ⲽƵǶפȤȤˤʤ뤬ºݤϤñǤϤʤʤʤ顤Ƶޤޤ¿ξ֤ݻƤͤФʤ餺֥̤ˤʤ꤬פȤĤưŪײˡˤäƤϡפʬΤƤ뤳ȤǤơ(μȤǤϿƤʤ)׻̤礭餻뤫Ǥ롥


ž夲

ơǤϼ򤯥ץĽ񤳤ޤ롥

  • ޤˤ褦ʷϩijͤ롥ȡStart Goal ޤǤϺû 10 step ǹԤ뤬ιԤϲ̤⤢롥ιԤ̤ꤢ뤫׻ץ񤱡

    route.png

ץˤĤƤξϰʲ̤Ǥ롥

  1. ץ A ϺƵˤΤȤ롥Ԥϥⲽ褦
  2. ץ B ưŪײˡɤˤΤȤ롥
  3. Ĥפ뤳Ȥǧ补

OK.png (ҥ) Goal ޤǤκûϩ򤤤ʤͤ񤷤ֲ¾ Goal ȤȡޤǤκûϩοϤɤפȹͤơ餬ɤΤ褦ʴطˤ뤫ͤƤߤ褦
㤨СStart Τ¦ Goal ξϺûϩ 1 ǡƱͤ 1 ơStart κ Goal ξϺûϩ 2 Ȥʤ롥ơϤɤΤ褦ʴطˤ


Ը

Ըˡʲβ꤬롥ϰǤ뤬ηϩη㤦𤫤⤷ʤͤƤߤ褦

route2.png


ݡ

ֵӹԤä½ˤĤơñˤޤȤ᤿򤻤.
ޤž夲ʬǼʬǽ񤤤ץ𤻤.

Ƽ

  1. °(ز)
  2. ֹ
  3. ǯ
  4. ̾
  5. οΥݡ(θȤˤĤƵŤ)

񤯤Τ˺ʤ褦.

about Icons, ClipArts

Some icons in this page are downloadable at ICONFINDER.

The "note" icon notes.png designed by Marco Martin is distributed with the LGPL licence,
the "warning" icon warning.png designed by Alexandre Moore with the GPL licence
and the "triangle" icon JNorth_arrow-right-sm.png designed by Joseph North is distributed with the Creative Commons (Attribution-Noncommercial-Share Alike 3.0 Unported) licence.

Some clip arts used in this page are downloadable at Open Clip Art Library.
We deeply appreciate their superb works. With licence, they describe that "the actual clipart content on open clipart library is Public domain" in the web.


źեե: fileroute2.png 819 [ܺ] filetree.png 118 [ܺ] filefibonacci-alg.png 89 [ܺ] filetree2.png 96 [ܺ] fileroute.png 117 [ܺ] filetree3.png 102 [ܺ]