Jump to content

Recommended Posts

Posted

hi everyone

i am stuck on a easy problem but i can't find the solution

how can i filter black cell in an array 7*7

filter.png.8c4eb22bd65baad7a0635caad93e3ff4.png

for $jj=0 to 6
      for  $ii=0 to 6
         if??
      Next
   Next

Posted
42 minutes ago, orphan said:

how can i filter black cell in an array 7*7

#include <Array.au3>

; 1 = Black, 0 = White
Global $g_aCells = [[1,1,1,0,1,1,1], _
                    [1,1,0,0,0,1,1], _
                    [1,0,0,0,0,0,1], _
                    [0,0,0,0,0,0,0], _
                    [1,0,0,0,0,0,1], _
                    [1,1,0,0,0,1,1], _
                    [1,1,1,0,1,1,1]]
_ArrayDisplay($g_aCells)

For $iRow = 0 To 6
    For $iCol = 0 To 6
        If $g_aCells[$iCol][$iRow] = 1 Then
            ConsoleWrite("+ $iCol:" & $iCol & "  $iRow:" & $iRow & " is BLACK" & @CRLF)
        Else
            ConsoleWrite("> $iCol:" & $iCol & "  $iRow:" & $iRow & " is WHITE" & @CRLF)
        EndIf
    Next
    ConsoleWrite(" -----------------------------" & @CRLF)
Next

 

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Posted

Small addendum :

As long as each cell of the field can have only two states (Black=1, White=0) you can represent each line with a single value.

Bit7  Bit6  Bit5  Bit4  Bit3  Bit2  Bit1
(64)  (32)  (16)  (8)   (4)   (2)   (1)
 1     1     1     0     1     1     1  <== first row
 
 ==> 119 (Dec) or 77 (Hex)

 

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Posted

hi 

thx for first post, i try to find formulea for array[n][n]

i dont understand that lol

5 minutes ago, Musashi said:

Small addendum :

As long as each cell of the field can have only two states (Black=1, White=0) you can represent each line with a single value.

Bit7  Bit6  Bit5  Bit4  Bit3  Bit2  Bit1
(64)  (32)  (16)  (8)   (4)   (2)   (1)
 1     1     1     0     1     1     1  <== first row
 
 ==> 119 (Dec) or 77 (Hex)

 

 

Posted
24 minutes ago, orphan said:

thx for first post, i try to find formulea for array[n][n]

I am not quite sure what your goal is 🤔. Could you be a little more specific.

26 minutes ago, orphan said:

i dont understand that lol

Search with e.g. Google for 'autoit bitwise operations' ;).

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Posted

 i would like generalization for an array [n][n] on the array g_aCells

and your first post give me idea to find the formulea:)

$n must be impair (3,5,7 etc)

#include <array.au3>

local $tt[7][7]
_Build($tt,7)
_ArrayDisplay($tt)

Func _Build(byref $filtre,$n)
    $k = 0
    For $i=0 to $n-1

      for $j=0 to $n-1
         if $j > ($n-1)/2-1-$k and $j < ($n-1)/2+1+$k then
            $filtre[$i][$j] = 1
         else
            $filtre[$i][$j] = 0
         endif
      next
      if $i < ($n-1)/2 then
         $k=$k+1
      Else
         $k=$k-1
      EndIf
   Next
EndFunc

 

i see some post on your second post

Posted (edited)

As there is a complete symmetry (horizontal & vertical), you could check only the left upper quadrant and fill the symmetric cells, something like this :

#include <array.au3>

Local $iOdd = 15, $tt[$iOdd][$iOdd]
_Build($tt, $iOdd)
_ArrayDisplay($tt)

Func _Build(ByRef $filtre, $iOdd)
    Local $iOdd2 = Int($iOdd / 2) - 1 ; $iOdd = 15 => $iOdd2 = 6
    For $iRow = 0 To $iOdd2 ; 0 To 6 (no matter $iOdd2 will be decremented later)
        For $iCol = 0 To $iOdd2 ; 0 To 6, then 0 To 5... until 0 To 0
            $filtre[$iRow][$iCol] = "X" ; left upper quadrant
            $filtre[$iRow][$iOdd - $iCol - 1] = "X" ; right upper quadrant
            $filtre[$iOdd - $iRow - 1][$iCol] = "X" ; left lower quadrant
            $filtre[$iOdd - $iRow - 1][$iOdd - $iCol - 1] = "X" ; right lower quadrant
        Next
        $iOdd2 -= 1 ; from 6 To 0
    Next
EndFunc

 

Edited by pixelsearch
comments in code

"I think you are searching a bug where there is no bug... don't listen to bad advice."

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...