# Weekly Challenge

Solve the challenge, share your solution and summit the ranks of our Community!
###### IDEAS WANTED

We're actively looking for ideas on how to improve Weekly Challenges and would love to hear what you think!

Submit Feedback
We've recently made an accessibility improvement to the community and therefore posts without any content are no longer allowed. Please use the spoiler feature or add a short message in the message body in order to submit your weekly challenge.

## Challenge #200: Sudoku Solver

Highlighted
8 - Asteroid

Here's my beginner solution.

Will need to spend further time to get other two solutions.

Highlighted
8 - Asteroid

Beginner was easy.

Highlighted
8 - Asteroid

Here is my solution but only for the Beginner level. I will make the rest of the task during the weekend and will update my post as well. Very challenging task!

Highlighted
8 - Asteroid

Naming it as entering the death zone isn't inadequate, it was not easy, even the intermediate one.

Spoiler Highlighted
10 - Fireball

#200 - beginner for now.

Spoiler Highlighted
Alteryx Partner

Spoiler- beginner solution

Highlighted 12 - Quasar

This one was easy to comprehend in Alteryx (if you understand sudoku) but took quite a few tools.

on the flip side, the python solutions i've found and ultimately used can be a lot more tidy, but require a deeper understanding of data manipulation that isn't nearly as intuitive as alteryx.

Spoiler
``````# List all non-standard packages to be imported by your
# script here (only missing packages will be installed)
from ayx import Package
#Package.installPackages(['pandas','numpy'])

from ayx import Alteryx
import numpy as np
import pandas as pd
import time

# This is the Beginner Solution

dfBeginner = dfBeginner['quizzes'].str.extract('(.{9})'*9)
dfBeginner = np.transpose(dfBeginner)
dfBeginner = dfBeginner.str.extract('(.{1})'*9)
# print(dfBeginner)
Alteryx.write(dfBeginner,1)

# This is the start of the Intermediate/Advanced Solutions

dfInput = dfInput['quizzes'].str.extract('(.{9})'*9)
dfInput = np.transpose(dfInput)
# the .astype(int) is necessary for turning the data into an array
dfInput = dfInput.str.extract('(.{1})'*9).astype(int)
dfInput = dfInput.to_numpy()
container = dfInput

# This is not my code below, but i found it intuitive although i'm still digging into how it all works.

###  Defining Functions  ###
subtract_set = {1,2,3,4,5,6,7,8,9}

def check_horizontal(i,j):
return subtract_set - set(container[i])

def check_vertical(i,j):
ret_set = []
for x in range(9):
ret_set.append(container[x][j])
return subtract_set - set(ret_set)

def check_square(i,j):
first = [0,1,2]
second = [3,4,5]
third = [6,7,8]
find_square = [first,second,third]
for l in find_square:
if i in l:
row = l
if j in l:
col = l
ret_set = []
for x in row:
for y in col:
ret_set.append(container[x][y])
return subtract_set - set(ret_set)

def get_poss_vals(i,j):
poss_vals = list(check_square(i,j).intersection(check_horizontal(i,j)).intersection(check_vertical(i,j)))
return poss_vals

def explicit_solver(container):
stump_count = 1
for i in range(9):
for j in range(9):
if container[i][j] == 0:
poss_vals = get_poss_vals(i,j)
if len(poss_vals) == 1:
container[i][j] = list(poss_vals)
print_container(container)
stump_count = 0
return container, stump_count

def implicit_solver(i,j,container):
if container[i][j] == 0:
poss_vals = get_poss_vals(i,j)

#check row
row_poss = []
for y in range(9):
if y == j:
continue
if container[i][y] == 0:
for val in get_poss_vals(i,y):
row_poss.append(val)
if len(set(poss_vals)-set(row_poss)) == 1:
container[i][j] = list(set(poss_vals)-set(row_poss))
print_container(container)

#check column
col_poss = []
for x in range(9):
if x == i:
continue
if container[x][j] == 0:
for val in get_poss_vals(x,j):
col_poss.append(val)
if len(set(poss_vals)-set(col_poss)) == 1:
container[i][j] = list(set(poss_vals)-set(col_poss))
print_container(container)

#check square
first = [0,1,2]
second = [3,4,5]
third = [6,7,8]
find_square = [first,second,third]
for l in find_square:
if i in l:
row = l
if j in l:
col = l
square_poss = []
for x in row:
for y in col:
if container[x][y] == 0:
for val in get_poss_vals(x,y):
square_poss.append(val)
if len(set(poss_vals)-set(square_poss)) == 1:
container[i][j] = list(set(poss_vals)-set(square_poss))
print_container(container)
return container

def print_container(container):
for i, row in enumerate(container):
for j, val in enumerate(row):
if (j)%3 == 0 and j<8 and j>0:
print("|",end=' ')
print(val,end=' ')
print()
if (i-2)%3 == 0 and i<8:
print("_____________________", end='')
print()
print()
print()
print("||||||||||||||||||||||")
print()

# using explicit solver
start = time.time()
zero_count = 0
for l in container:
for v in l:
if v == 0:
zero_count += 1

print(f'There are {zero_count} moves I have to make!')
print()

print_container(container)
print()
solving = True

while solving:
#Solver Portion
container, stump_count = explicit_solver(container)

#Loop-Breaking Portion
zero_count = 0
for l in container:
for v in l:
if v == 0:
zero_count += 1
if zero_count==0:
print_container(container)
solving=False
if stump_count > 0:
for i in range(9):
for j in range(9):
container = implicit_solver(i,j,container)
print()
print('That took', time.time()-start, 'seconds!')
``````

#SnakingMyWayThruChallenges

Highlighted
9 - Comet

Solution for the Advanced level challenge. Tempting to leverage Python/R. Was able to use standard Alteryx tools, and in particular the Optimization Tool to create a solver. Really great challenge.

Spoiler Highlighted
8 - Asteroid

Cool one

Spoiler Highlighted
7 - Meteor

solution for beginner