def num_to_str(val, num_sys = 10):
    result = format(val, {2:'b', 10:'d', 16:'x'}[num_sys])
    return result 

def get_adjacency(index, arr):
    """
    get the adjacency number. 
    
    Args: 
        index: for an 4-bit array, indexs are[0, 1, 2, 3]
        arr: 4-bit int array. 

    """

    result=0
    left=index - 1
    while(left >= 0 and arr[left] == arr[index]):
        left=left - 1
        result=result + 1
    
    right=index + 1
    while (right < len(arr) and arr[right] == arr[index]):
        right=right + 1
        result=result + 1

    return result

def get_code_reward(index, arr, code_digits):    
    """
    compare arr[2] and arr[3] against with code digits.
    return code digits number in arr. 

    Args:
        index: for an 4-bit array, indexs are [0, 1, 2, 3]
        arr: 4-bt int array.
        code_digits: 2-bit int array. 
    """
    
    result=0
    if index < 2:
        return result
    if arr[2] == code_digits[0]: result=result + 1    
    if arr[3] == code_digits[1]: result=result + 1
    return result

@@ -886,25 +886,27 @@
  %0A    result
-=
+ = 
 0%0A    if ind
@@ -906,53 +906,166 @@
  if 
+(
 index 
-%3C 2:%0A        return result
+== 2) and (arr%5B2%5D == code_digits%5B0%5D):%0A        result=result + 1%0A        if arr%5B3%5D == code_digits%5B1%5D: result=result + 1
 %0A    
+el
 if 
+(index == 3) and (
 arr%5B
-2
+3
 %5D ==
@@ -1081,11 +1081,20 @@
 its%5B
-0%5D:
+1%5D):%0A       
  res
@@ -1107,21 +1107,21 @@
 sult + 1
+%0A
     
-%0A
     if a
@@ -1115,33 +1115,33 @@
 %0A        if arr%5B
-3
+2
 %5D == code_digits
@@ -1133,33 +1133,33 @@
  == code_digits%5B
-1
+0
 %5D: result=result

fix util.py get_code_reward().