èªç¶ã¯æ¾ã£ã¦ããã¨ãèªç¶ã«å¹³è¡¡ç¶æ ï¼èªå·±çµç¹åè¨çç¶æ ã¨å義èªï¼ï¼ã«ãªããããã§ãããã®ç¶æ ã§ã¯ã大å°ãã¾ãã¾ãªåºæ¥äºããã¹ãä¹åã«å¾ã£ã¦äºæ¸¬ä¸å¯è½ãªã¿ã¤ãã³ã°ã§èµ·ãã¾ããä¾ãã°ãå°éã®çºçããç å±±ã®éªå´©ç¾è±¡ããèªç¶æã®æå ã®ã£ããã®åå¸ãªã©ãããã®æ³åã«å¾ã£ã¦ãã¾ãã
ããã§åé¡ãªã®ã¯ãèªç¶ç°å¢ã®çæ³ã®å§¿ã¯ããã®è¨çç¶æ ãªã®ãï¼ã¯ãã¾ãããããªããªãããã«ã³ã³ããã¼ã«ããæ¹ãããã®ãï¼ã©ã£ã¡ãªãã ããã¨ãããã¨ã§ãããããããèãã¦è¡ããããã¼ãã§ããï¼ä¸éã§ã¯ãããçµè«ã§ã¦ããã§ããããï¼ä¸éç¥ãããªãã®ã§ãããï¼
â»ä½è«ãªãããç¾å¨ã®è³æ¬ä¸»ç¾©ãããã®è¨çç¶æ ã«éããããããªããããã¨æã£ã¦ãã¾ãããããªãã¨ãäºç´°ãªåºæ¥äºãåå ã§ã大ããªäºä»¶ãäºæ¸¬ä¸å¯è½ã«çºçãã¡ããã
ãã®ããã«ãã¨ããããããã¹ããã¨ã¯ã
- èªå·±çµç¹åè¨çç¶æ ãç解ããããã·ãã¥ã¬ã¼ã·ã§ã³ããã°ã©ã ãå®è¡ãã¦ã¿ãã
- æ¥æ¬ã®æ£®æã¯ãè¨çç¶æ ãªã®ãã©ããã確ãããããã®æ¹æ³ã調ã¹ãã
ä»åã¯ãã¾ãèªå·±çµç¹åè¨çç¾è±¡ã®ä¾ã¨ãã¦ãç 山崩ãã¢ãã«ãEXCEL VBAã§ããã°ã©ãã³ã°ãã¦å®è¡ããæ¹æ³ãç´¹ä»ãã¾ãã
ç 山崩ãã¢ãã«EXCEL VBAããã°ã©ãã³ã°
ãããªãã§ãããããã°ã©ã ãå¼µã£ã¦ããã¾ãã解説ã¯ãã¾ãä»åº¦ã
åèæç®ã¯ããã¡ããªã®ã§ãç§ã®è§£èª¬ããã¯ããã£ã¡ãèªãã æ¹ãæ©ãã¨æãã¾ãã
Option Explicit Const L = 64 'ã¨ãªã¢ã®ç¯å² Const STEP = 60000 'ç ãè½ã¨ãåæ° Dim d(L, L) As Integer 'ç ã®é«ã(å³å¯ã«ã¯é«ãã®å·®å) Dim df(L, L) As Integer 'å´©ãããã©ããã®ãã©ã°ãè¨é² Dim nsize As Integer 'å´©ããç®æã®ç·æ°ï¼éªå´©ã®ãµã¤ãºï¼ Dim count(STEP) As Integer 'ç ãè½ã¨ããã¹ããããã¨ã®éªå´©ãµã¤ãºãè¨é² Sub BTW() Dim k, i As Long Dim myrnd1, myrnd2 As Integer Dim x, y As Integer Randomize For y = 1 To L 'ã»ã«ã®åæå For x = 1 To L Cells(x, y).Interior.Color = &H0 Next Next k = 0 While k < STEP nsize = 0 Erase df 'ã¨ãªã¢å ã®ç ãè½ã¨ãå ´æãä¹±æ°ã§æ±ºãã myrnd1 = Int(Rnd() * L + 1) myrnd2 = Int(Rnd() * L + 1) 'ç ãè½ã¨ã d(myrnd1, myrnd2) = d(myrnd1, myrnd2) + 1 'å´©ãããã©ãããå帰çã«ãã§ãã¯ãã Call check(myrnd1, myrnd2) If k >= L * L * 2 Then 'å®å¸¸ç¶æ ã«ãªãã¾ã§ã¾ã¤ For y = 1 To L For x = 1 To L 'éªå´©ãèµ·ããããªã¨ãããè²ã¤ãã®å ´å ' If d(x, y) = 3 Then ' Cells(x, y).Interior.Color = RGB(255, 255, 255) ' Else ' Cells(x, y).Interior.Color = RGB(0, 0, 0) ' End If 'ç ã®é«ããã¨ã«è²ã¤ãã®å ´å ' If d(x, y) = 0 Then ' Cells(x, y).Interior.Color = RGB(0, 0, 0) ' ElseIf d(x, y) = 1 Then ' Cells(x, y).Interior.Color = RGB(85, 85, 85) ' ElseIf d(x, y) = 2 Then ' Cells(x, y).Interior.Color = RGB(170, 170, 170) ' ElseIf d(x, y) = 3 Then ' Cells(x, y).Interior.Color = RGB(255, 255, 255) ' End If 'éªå´©ãèµ·ããã¨ãããè²ä»ãã®å ´å If df(x, y) = 1 Then Cells(x, y).Interior.Color = RGB(255, 255, 255) Else Cells(x, y).Interior.Color = RGB(0, 0, 0) End If Next Next End If count(k) = nsize k = k + 1 Wend 'Sheets2ã«ã¹ããããã¨ã®éªå´©ãµã¤ãºãæ¸ãåºã For i = 1 To STEP Worksheets("Sheet2").Cells(i, 1) = count(i - 1) Next End Sub Sub check(x, y) If d(x, y) >= 4 Then 'ç ã®é«ãã4以ä¸ã ã¨å´©ãã If df(x, y) = 0 Then 'éªå´©ãµã¤ãºãã«ã¦ã³ããã nsize = nsize + 1 df(x, y) = 1 End If 'ãã®å ´æãå´©ããä¸ä¸å·¦å³ã«æ£ãã°ãã 'æ£ãã°ã£ãå ´æããå´©ããªããåã³ãã§ã㯠d(x, y) = d(x, y) - 4 If x + 1 <= L Then d(x + 1, y) = d(x + 1, y) + 1 If x - 1 >= 1 Then d(x - 1, y) = d(x - 1, y) + 1 If y + 1 <= L Then d(x, y + 1) = d(x, y + 1) + 1 If y - 1 >= 1 Then d(x, y - 1) = d(x, y - 1) + 1 If x + 1 <= L Then Call check(x + 1, y) If x - 1 >= 1 Then Call check(x - 1, y) If y + 1 <= L Then Call check(x, y + 1) If y - 1 >= 1 Then Call check(x, y - 1) End If End Sub
ãã¡ãã¯ãè¨çç¶æ ãç解ããã®ã«èªã¿ãããã¦é¢ç½ãã¦åãããããã§ãã