標題:
燈泡亮與滅的設定?
[打印本頁]
作者:
q1a2z5
時間:
2012-12-24 13:56
標題:
燈泡亮與滅的設定?
在C2,B4,B7,D4,D7儲存格代表一個燈泡,當在C2輸入"亮",則會牽動C2左右兩邊的燈泡,C2會變滅;而C2左右兩邊則會變亮,
也就是說,滅的會變亮;亮的會變滅,
正確解法為五個燈泡全都亮。
問題:有沒有辦法用公式來設定?或者顯示正確解法呢?
謝謝!
作者:
mark15jill
時間:
2012-12-25 08:01
沒看到燈泡 亮 與 滅的圖示...
且
正確解法為五個燈泡全都亮。
這是?
作者:
q1a2z5
時間:
2012-12-25 09:20
回復
2#
mark15jill
不好意思,這個是沒有燈泡圖示,只是用文字來顯示。就像數獨可用公式來設定正確解法。
所以,此問題可否用公式來設定呢?
3Q
作者:
stillfish00
時間:
2012-12-25 15:32
回復
3#
q1a2z5
自定義函數 , 複製下面代碼至一般模組
如在A1打上 =LightGame(C2,B4,B7,D7,D4)
會顯示C2,B4,B7 , 即是使五燈全亮所需開關的燈
須注意參數要依順時針或逆時針填入
代碼粗糙就不多解釋了
Function LightGame(in1, in2, in3, in4, in5) As String
Dim adr(1 To 5)
Dim d
Dim init_s As String, op As String
Dim i, j, k, m, ks
adr(1) = in1.Address(0, 0)
adr(2) = in2.Address(0, 0)
adr(3) = in3.Address(0, 0)
adr(4) = in4.Address(0, 0)
adr(5) = in5.Address(0, 0)
Set d = CreateObject("scripting.dictionary")
init_s = in1 & "," & in2 & "," & in3 & "," & in4 & "," & in5 '初始狀態
d.Add "0", init_s
For i = 1 To 5
For Each k In d.keys
ks = Split(k, ",")
For j = ks(UBound(ks)) + 1 To 5
s = Split(d(k), ",")
Select Case j - 1
Case LBound(s)
s(UBound(s)) = IIf(s(UBound(s)) = "亮", "滅", "亮")
s(j - 1) = IIf(s(j - 1) = "亮", "滅", "亮")
s(j) = IIf(s(j) = "亮", "滅", "亮")
Case UBound(s)
s(j - 2) = IIf(s(j - 2) = "亮", "滅", "亮")
s(j - 1) = IIf(s(j - 1) = "亮", "滅", "亮")
s(LBound(s)) = IIf(s(LBound(s)) = "亮", "滅", "亮")
Case Else
s(j - 2) = IIf(s(j - 2) = "亮", "滅", "亮")
s(j - 1) = IIf(s(j - 1) = "亮", "滅", "亮")
s(j) = IIf(s(j) = "亮", "滅", "亮")
End Select
d(k & "," & j) = Join(s, ",")
If Join(s, ",") = "亮,亮,亮,亮,亮" Then
ks = Split(k & "," & j, ",")
For m = 1 To UBound(ks)
If op = "" Then op = adr(ks(m)) Else op = op & "," & adr(ks(m))
Next m
LightGame = op
Set d = Nothing
Exit Function
End If
Next j
Next k
Next i
End Function
複製代碼
歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)