You may have seen ads for the Water Sort puzzle game. In case you haven’t, it’s a pretty standard puzzle game: you’ve got n+2 test tubes filled with n different colors. Your job is to pour from one test tube into another until the colors are all sorted out into their own test tubes. The only rule is you can only pour into a tube that is either empty or that has open space over another section of the same color.
We’ve all been there: you’re digging around for a freely-available data set that’s interesting, Goldilocks-sized, and has the right types of data fields to support your learning objectives. You’re an hour or two deep in searching, and nothing you find seemes quite right. What’s an instructional designer to do?
Well, if you’re me, the answer seems obvious: create a simulated data set to use in your examples. I’ve done this in technical writing contexts as well, when I needed to use “patient data” in some examples but of course could not use data for actual patients.
Working with Pandas DataFrames Pandas uses the DataFrame class for working with tabular data. DataFrames allow you to read, sort, manipulate, and display data. In this exercise, you’ll create your first DataFrame and use it to do some initial exploration of a data set.
Objectives When you finish this lab, you should be comfortable with:
Loading data into a DataFrame from a CSV file Printing out the first or last five rows Viewing DataFrame attributes like its columns and shape Accessing individual columns Manipulating the data set including sorting, ranking, and grouping Adding new columns and populating them with generated data Changing the data type of a column Filtering data by column values using loc and numerical or qualitative values We’ll build on these further in the next lab.
Have you ever wondered how many unique games of Tic-Tac-Toe there are? This question snuck into my brain the other day and I just had to find out. Come with me and see! My full source code for this exercise, including comments and random debugging notes that I omitted in this post, can be seen at https://replit.com/@KendraPendolino/TicTacToe.
Before we dive in, I want to talk a little bit about equivalent boards.
Emboldened by my recent completion of Project Euler 96, I decided to take a crack at another problem: Problem 93. You can read the full text of the problem at the link above, but the gist of it is this: working with a set of four distinct individual digits, arranged in any order, with any combination of parentheses and basic mathematical operations (+, -, /, *), which combination of digits can form the longest string of consecutive positive integers from 1 to n before reaching an integer that can’t be formed using those digits?
Looks like this project is done! I plugged the semi-solved Grid 42 into a sudoku app to check for the next step, and immediately saw it: locked intersections. This happens when all of the candidates for a given digit in a box appear in the interesction of that box and a row/column or vice versa. If every cell that could contain a 1 in box 0 is in row 0, you know that the digit 1 can’t appear anywhere else in row 0.
WELL turns out I had a glitch in my code. Let’s recap where the last installment left off. My algorithm thought that this was fully solved:
829|31 |475 5 7|489|123 1 4|275|689 ---+---+--- 2 3|64 |9 7 461|927|538 97 |138|246 ---+---+--- 713|852|694 92|764|851 648|3 |7 2 So, that’s a miss. I went back through my code to identify the issue and discovered that there was a bug in my hiddenPairs code.
The next order of business was to see how far we could get solving using only naked singles and hidden singles.
easy=[ [0,5,0,4,0,9,0,0,2], [4,0,0,6,0,0,0,7,0], [0,0,2,0,0,0,8,0,9], [0,0,0,0,3,0,0,0,7], [0,0,4,0,0,0,3,6,0], [0,0,0,0,2,0,0,0,4], [0,0,3,0,0,0,7,0,5], [1,0,0,3,0,0,0,2,0], [0,4,0,7,0,8,0,0,1]] gr=Grid(easy) gr.solve() 358|479|612 491|682|573 672|153|849 ---+---+--- 816|534|297 524|917|368 739|826|154 ---+---+--- 963|241|785 187|395|426 245|768|931 Score: 0 Sum: 405 Oh, ok. I guess I’ll keep going then.
moderate = [ [8,0,0,0,6,0,0,0,3], [0,0,2,0,0,0,4,0,0], [0,3,6,2,0,4,7,8,0], [0,0,1,3,0,7,5,0,0], [4,0,0,0,5,0,0,0,7], [0,0,8,1,0,6,2,0,0], [0,8,9,4,0,1,3,7,0], [0,0,4,0,0,0,8,0,0], [3,0,0,0,7,0,0,0,2]] Grid(moderate).solve() 847|569|123 192|783|456 536|214|789 ---+---+--- 921|347|568 463|852|917 758|196|234 ---+---+--- 689|421|375 274|635|891 315|978|642 Score: 0 Sum: 405 Oh.
Today’s work had some ups and downs for sure. Once again, if you want to follow along, you can see my code here: @KendraPendolino/UnlinedSeashellMineral. I started by adding basic elimination for cells in the same group as a solved cell. While there, I realized I had forgotten to put in a reference from the cell back to the grid, so I added that too.
class Cell(): ... def setGrid(self,grid): self.grid=grid def solve(self,value): self.
I wasn’t able to get as much done today as I’d hoped, but I did get started with it. I’m doing my coding using Replit.com; you can see my code here: @KendraPendolino/UnlinedSeashellMineral. So, let’s see what we have so far.
I found a very easy sudoku puzzle to start with. Here it is as a two-dimensional array.
test = [ [0,0,6,9,0,1,2,0,0], [0,2,0,3,0,4,0,7,0], [1,0,0,0,7,0,0,0,8], [4,6,0,0,0,0,0,2,5], [0,0,3,0,0,0,7,0,0], [7,9,0,0,0,0,0,6,4], [6,0,0,0,3,0,0,0,7], [0,4,0,2,0,9,0,8,0], [0,0,8,7,0,6,5,0,0]] I made some game-day changes to the setup.
I got the idea for this project from Project Euler. If you’re someone who likes tinkering with code and algorithms, I highly recommend checking out Project Euler to add a little something extra to your personal and professional development.
Anyway, here’s the project: I want to create a sudoku-solving algorithm. That’s it, really. It’s nothing particularly groundbreaking, but I want to do it for myself and capture my thought process along the way.