View module_inheritance.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Module_A | |
def greeting_a | |
puts "Hello from Module A" | |
end | |
end | |
module Module_B | |
include Module_A |
View subscription_tracker_environment.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'bundler' | |
Bundler.require | |
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: 'db/development.db') | |
ActiveRecord::Base.logger = nil | |
require_relative '../app/tools/funstuff.rb' #=> Begin loading files from the bottom of the heirarchy | |
require_relative '../app/tools/cli_controls.rb' #=> Step 2 on the heirarchy |
View center_align.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'tty-screen' | |
class String | |
def center_align | |
screen_width = TTY::Screen.width | |
screen_center = screen_width / 2 | |
string_length = self.length | |
string_center = string_length/2 | |
offset = screen_center - string_center | |
"#{sprintf("%#{offset}s" % self)}" |
View sudoku-box-condition.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// puzzleArray is the game board being solved. A 9x9 matrix | |
// emptyCell = {rowIndex: INT , colIndex: INT } INT = coordinates of currently empty cell | |
// num = integer value 1-9 being tested | |
const boxSafe = (puzzleArray, emptyCell, num) => { | |
// Define top left corner of box region for empty cell | |
boxStartRow = emptyCell.rowIndex - (emptyCell.rowIndex % 3) | |
boxStartCol = emptyCell.colIndex - (emptyCell.colIndex % 3) | |
let safe = true |
View sudoku-initialize-functions.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const newSolvedBoard = _ => { | |
startTime = new Date | |
// Create an unaffiliated clone of a fresh board | |
const newBoard = BLANK_BOARD.map(row => row.slice() ) | |
// Populate the board using backtracking algorithm | |
fillPuzzle(newBoard) | |
return newBoard | |
} |
View sudoku-row-condition.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// puzzleArray is the game board being solved. A 9x9 matrix | |
// emptyCell = {rowIndex: INT , colIndex: INT } INT = coordinates of currently empty cell | |
// num = integer value 1-9 being tested | |
const rowSafe = (puzzleArray, emptyCell, num) => { | |
// -1 is return value of .find() if value not found | |
return puzzleArray[ emptyCell.rowIndex ].indexOf(num) == -1 | |
} |
View sudoku-safe-helper.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const safeToPlace = ( puzzleArray, emptyCell, num ) => { | |
return rowSafe(puzzleArray, emptyCell, num) && | |
colSafe(puzzleArray, emptyCell, num) && | |
boxSafe(puzzleArray, emptyCell, num) | |
} |
View sudoku-fill-puzzle.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// startingBoard is a 9x9 matrix of zeros | |
const numArray = [1, 2, 3, 4, 5, 6, 7, 8, 9] | |
const shuffle = array => { | |
let newArray = [...array] | |
for ( let i = newArray.length - 1; i > 0; i-- ) { | |
const j = Math.floor( Math.random() * ( i + 1 ) ); | |
[ newArray[ i ], newArray[ j ] ] = [ newArray[ j ], newArray[ i ] ]; | |
} |
View sudoku-next-empty.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const nextEmptyCell = puzzleArray => { | |
const emptyCell = {rowIndex: "", colIndex: ""} | |
puzzleArray.forEach( (row, rowIndex) => { | |
// If this key has already been assigned, skip iteration | |
if (emptyCell.colIndex !== "" ) return | |
// find first zero-element | |
let firstZero = row.find( col => col === 0) | |
View sudoku-col-condition.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// puzzleArray is the game board being solved. A 9x9 matrix | |
// emptyCell = {rowIndex: INT , colIndex: INT } INT = coordinates of currently empty cell | |
// num = integer value 1-9 being tested | |
const colSafe = (puzzleArray, emptyCell, num) => { | |
return !puzzleArray.some(row => row[ emptyCell.colIndex ] == num ) | |
} |