September Morn Update
This commit is contained in:
parent
4e2d22a71d
commit
aac6731f2c
6856 changed files with 141342 additions and 21127 deletions
|
|
@ -1,61 +1,62 @@
|
|||
import system'routines.
|
||||
import extensions.
|
||||
import system'routines;
|
||||
import extensions;
|
||||
import extensions'text;
|
||||
|
||||
extension op
|
||||
{
|
||||
printSolution : bits
|
||||
= self zip:bits by
|
||||
(:s:b)( s iif("T","F") + (s xor:b) iif("* "," ") ); summarize(String new).
|
||||
printSolution(bits)
|
||||
= self.zipBy(bits,
|
||||
(s,b => s.iif("T","F") + (s.xor:b).iif("* "," "))).summarize(new StringWriter());
|
||||
|
||||
toBit
|
||||
= self iif(1,0).
|
||||
toBit()
|
||||
= self.iif(1,0);
|
||||
}
|
||||
|
||||
puzzle =
|
||||
(
|
||||
(:bits)( bits length == 12 ),
|
||||
puzzle = new Func1[]
|
||||
{
|
||||
(bits => bits.Length == 12),
|
||||
|
||||
(:bits)( bits last:6; selectBy(:x)( x toBit ); summarize == 3 ),
|
||||
(bits => bits.last(6).selectBy:(x => x.toBit()).summarize() == 3 ),
|
||||
|
||||
(:bits)( bits zip(RangeEnumerator new from:1 to:12)
|
||||
by(:x:i)( (i int; isEven)and:x; toBit ); summarize == 2 ),
|
||||
(bits => bits.zipBy(new Range(1, 12),
|
||||
(x,i => (i.toInt().isEven()).and:x.toBit())).summarize() == 2 ),
|
||||
|
||||
(:bits)( bits[4] iif(bits[5] && bits[6],true) ),
|
||||
(bits => bits[4].iif(bits[5] && bits[6],true) ),
|
||||
|
||||
(:bits)( (bits[1] || bits[2] || bits[3]) not ),
|
||||
(bits => ((bits[1] || bits[2]) || bits[3]).Inverted ),
|
||||
|
||||
(:bits)( bits zip(RangeEnumerator new from:1 to:12)
|
||||
by(:x:i)( (i int; isOdd)and:x; toBit ); summarize == 4 ),
|
||||
(bits => bits.zipBy(new Range(1, 12),
|
||||
(x,i => (i.toInt().isOdd()).and:x.toBit() )).summarize() == 4 ),
|
||||
|
||||
(:bits)( bits[1] xor(bits[2]) ),
|
||||
(bits => bits[1].xor(bits[2]) ),
|
||||
|
||||
(:bits)( bits[6] iif(bits[5] && bits[4],true) ),
|
||||
(bits => bits[6].iif(bits[5] && bits[4],true) ),
|
||||
|
||||
(:bits)( bits top:6; selectBy(:x)( x toBit ); summarize == 3 ),
|
||||
(bits => bits.top(6).selectBy:(x => x.toBit() ).summarize() == 3 ),
|
||||
|
||||
(:bits)( bits[10] && bits[11] ),
|
||||
(bits => bits[10] && bits[11] ),
|
||||
|
||||
(:bits)( (bits[6] toBit + bits[7] toBit + bits[8] toBit)==1 ),
|
||||
(bits => (bits[6].toBit() + bits[7].toBit() + bits[8].toBit())==1 ),
|
||||
|
||||
(:bits)( bits top:11; selectBy(:x)( x toBit ); summarize == 4 )
|
||||
).
|
||||
(bits => bits.top(11).selectBy:(x => x.toBit()).summarize() == 4 )
|
||||
};
|
||||
|
||||
program =
|
||||
[
|
||||
console writeLine:"".
|
||||
public program()
|
||||
{
|
||||
console.writeLine();
|
||||
|
||||
0 till(2 power int:12) do(:n)
|
||||
[
|
||||
var bits := BitArray32 new:n; top:12; toArray.
|
||||
var results := puzzle selectBy(:r)( r(bits) ); toArray.
|
||||
for(int n := 0, n < 2.power(12), n += 1)
|
||||
{
|
||||
var bits := BitArray32.load(n).top(12).toArray();
|
||||
var results := puzzle.selectBy:(r => r(bits)).toArray();
|
||||
|
||||
var counts := bits zip:results by(:b:r)( b xor:r; toBit ); summarize.
|
||||
var counts := bits.zipBy(results, (b,r => b.xor:r.toBit() )).summarize();
|
||||
|
||||
counts =>
|
||||
0 [ console printLine("Total hit :",results printSolution:bits) ];
|
||||
1 [ console printLine("Near miss :",results printSolution:bits) ];
|
||||
12 [ console printLine("Total miss:",results printSolution:bits) ].
|
||||
].
|
||||
0 { console.printLine("Total hit :",results.printSolution:bits) }
|
||||
1 { console.printLine("Near miss :",results.printSolution:bits) }
|
||||
12 { console.printLine("Total miss:",results.printSolution:bits) };
|
||||
};
|
||||
|
||||
console readChar.
|
||||
].
|
||||
console.readChar()
|
||||
}
|
||||
|
|
|
|||
87
Task/Twelve-statements/VBA/twelve-statements.vba
Normal file
87
Task/Twelve-statements/VBA/twelve-statements.vba
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
Public s As String '-- (eg "101101100010")
|
||||
Public t As Integer '-- scratch
|
||||
|
||||
Function s1()
|
||||
s1 = Len(s) = 12
|
||||
End Function
|
||||
Function s2()
|
||||
t = 0
|
||||
For i = 7 To 12
|
||||
t = t - (Mid(s, i, 1) = "1")
|
||||
Next i
|
||||
s2 = t = 3
|
||||
End Function
|
||||
Function s3()
|
||||
t = 0
|
||||
For i = 2 To 12 Step 2
|
||||
t = t - (Mid(s, i, 1) = "1")
|
||||
Next i
|
||||
s3 = t = 2
|
||||
End Function
|
||||
Function s4()
|
||||
s4 = Mid(s, 5, 1) = "0" Or ((Mid(s, 6, 1) = "1" And Mid(s, 7, 1) = "1"))
|
||||
End Function
|
||||
Function s5()
|
||||
s5 = Mid(s, 2, 1) = "0" And Mid(s, 3, 1) = "0" And Mid(s, 4, 1) = "0"
|
||||
End Function
|
||||
Function s6()
|
||||
t = 0
|
||||
For i = 1 To 12 Step 2
|
||||
t = t - (Mid(s, i, 1) = "1")
|
||||
Next i
|
||||
s6 = t = 4
|
||||
End Function
|
||||
Function s7()
|
||||
s7 = Mid(s, 2, 1) <> Mid(s, 3, 1)
|
||||
End Function
|
||||
Function s8()
|
||||
s8 = Mid(s, 7, 1) = "0" Or (Mid(s, 5, 1) = "1" And Mid(s, 6, 1) = "1")
|
||||
End Function
|
||||
Function s9()
|
||||
t = 0
|
||||
For i = 1 To 6
|
||||
t = t - (Mid(s, i, 1) = "1")
|
||||
Next i
|
||||
s9 = t = 3
|
||||
End Function
|
||||
Function s10()
|
||||
s10 = Mid(s, 11, 1) = "1" And Mid(s, 12, 1) = "1"
|
||||
End Function
|
||||
Function s11()
|
||||
t = 0
|
||||
For i = 7 To 9
|
||||
t = t - (Mid(s, i, 1) = "1")
|
||||
Next i
|
||||
s11 = t = 1
|
||||
End Function
|
||||
Function s12()
|
||||
t = 0
|
||||
For i = 1 To 11
|
||||
t = t - (Mid(s, i, 1) = "1")
|
||||
Next i
|
||||
s12 = t = 4
|
||||
End Function
|
||||
|
||||
Public Sub twelve_statements()
|
||||
For i = 0 To 2 ^ 12 - 1
|
||||
s = Right(CStr(WorksheetFunction.Dec2Bin(64 + i \ 128)), 5) _
|
||||
& Right(CStr(WorksheetFunction.Dec2Bin(256 + i Mod 128)), 7)
|
||||
For b = 1 To 12
|
||||
Select Case b
|
||||
Case 1: If s1 <> (Mid(s, b, 1) = "1") Then Exit For
|
||||
Case 2: If s2 <> (Mid(s, b, 1) = "1") Then Exit For
|
||||
Case 3: If s3 <> (Mid(s, b, 1) = "1") Then Exit For
|
||||
Case 4: If s4 <> (Mid(s, b, 1) = "1") Then Exit For
|
||||
Case 5: If s5 <> (Mid(s, b, 1) = "1") Then Exit For
|
||||
Case 6: If s6 <> (Mid(s, b, 1) = "1") Then Exit For
|
||||
Case 7: If s7 <> (Mid(s, b, 1) = "1") Then Exit For
|
||||
Case 8: If s8 <> (Mid(s, b, 1) = "1") Then Exit For
|
||||
Case 9: If s9 <> (Mid(s, b, 1) = "1") Then Exit For
|
||||
Case 10: If s10 <> (Mid(s, b, 1) = "1") Then Exit For
|
||||
Case 11: If s11 <> (Mid(s, b, 1) = "1") Then Exit For
|
||||
Case 12: If s12 <> (Mid(s, b, 1) = "1") Then Exit For
|
||||
End Select
|
||||
If b = 12 Then Debug.Print s
|
||||
Next
|
||||
Next
|
||||
End Sub
|
||||
Loading…
Add table
Add a link
Reference in a new issue