Sudoku puzzles can be generated by a switching the rows and columns of a valid puzzle. The switch has to be done between the 123, 456 and 789 rows/columns. ie; 1 cannot be switched with 7 for example. A random pair can be generated and if a loop is run say 50 times, we get a new puzzle. Then the cells can be hidden again randomly. The following code generates the puzzle from a base character string which is converted to a 81 length Char array. The output is the solution as well as the puzzle with blank (or 0s) Dim stdArray As String = "317849265245736891869512473456398712732164958981257634174925386693481527528673149" Dim charArray() As Char = stdArray.ToCharArray Dim rng As New Random Dim m As Integer Dim row1 As Integer Dim row2 As Integer Dim col1 As Integer Dim col2 As Integer Dim i As Integer Dim cell1 As Integer Dim cell2 As Integer Dim tempC A
This code will let you convert an arbitrary string with 0s and 1s only into a Hex value, and back. Why? Maybe you have a Javascript component that renders based on a long array of bits. Lets say var b = "101010101100101001000101011101010010011100000010100110000010001010010011000000000001000010101001110000000001100010100000" The string can be stored in the DB as nvarchar(max) field, but then if you want to reduce the length by 1/8th, you can convert it into a Hexadecimal representation The above would be equivalent to 27029822 930010A9C018A0 Ok, this is the 'bit packing' concept implemented in a very crude way. Anyhow, the output is human readable and probably easier to pass in a JSON The functions are as below Private Function bitArrayStrtoHex(b As String) As String Dim sb As New System.Text.StringBuilder For i As Integer = 0 To b.Length - 1 Step 8 Dim cut8 As String If b.Length - i <= 8 Then