repl.it
@HristoGueorguie/

Infinite9s

Python

No description

fork
loading
Files
  • main.py
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
input_list = [ 1, 239, 18, 23, 3, 17, 25, 9 ]

input_list_simple = [1, 2, 3, 4, 5, 6,7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18]

def sort_by_col(inp_list):
  results = {}
  for number in inp_list:
    col = number % 9 if number % 9 else 9 
    results[col].append(number) if results.get(col) else results.update({col:[number]})

  return results

def sort_by_row(inp_list):
  results = {}
  for number in inp_list:
    row = ((number - 1) // 9) + 1
    results[row].append(number) if results.get(row) else results.update({row:[number]})

  return results

def sort_by_row_no_mod(inp_list):
  results = {}
  def digital_sum(number):
    sum = 0
    for digit in str(number):
      sum += int(digit)

    return sum if sum < 10 else digital_sum(sum)  

  for number in inp_list:
    col = digital_sum(number)

    results[col].append(number) if results.get(col) else results.update({col:[number]})

  return results

# This approximates int divdison by 9
# If they get this bitshifty they can
# probably code. So still a win by seeing
# loophole in rules.
def approx_div_9(num):
  res = num>>3
  if res >= 10:
    res += ~approx_div_9(res) + 1
  return res
  
print('Sorted by col:')
print(sort_by_col(input_list_simple))

print('\nSorted by row:')
print(sort_by_row(input_list_simple))

print('\nSort by col no module')
print(sort_by_row_no_mod(input_list_simple))
Fetching token
?