Skip to content

Instantly share code, notes, and snippets.

View aksnell's full-sized avatar
🏠
Working from home

Alex Snell aksnell

🏠
Working from home
  • Walmart Global Tech
  • Bentonville, Arkansas
  • 12:46 (UTC -12:00)
View GitHub Profile
function christmasTree(height) {
if (height === 0) return ''
const tree = ['*'.repeat((height*2)-1)]
for (let i = 0; i < height - 1; i++) {
tree.push(tree[i].replace(/(\*)(?=\s|$)|(?<=\s|^)(\*)/g, ' '))
}
return tree.reverse().join('\n')
function inAscOrder(arr) {
let prevNum = 0
for (num of arr) {
if (num < prevNum) {
return false
} else {
prevNum = num
}
}
return true
function count(array){
let result = {}
for (ele of array) {
result[ele] = (ele in result) ? result[ele] + 1 : 1
}
return result
}
def sudoku(puzzle):
class Board(object):
def __init__(self, parse_board):
self.board = parse_board
self.row_list = {i: set(self.board[i]) for i in range(0,9)}
self.col_list = {i: set(x[i] for x in self.board) for i in range(0,9)}
self.grid_list = {i: list(self.yieldGrids())[i] for i in range(0,9)}
self.tile_list = list(self.insertTiles())
def insertTiles(self):
for row_index, row in enumerate(self.board):
import re
def simplify(poly):
poly = re.findall(r'([+-])?(\d)?([a-z]+)',poly)
poly_groups = [[group[0], ''.join(sorted(group[2]))] if group[0] == '-'
else ['+', ''.join(sorted(group[2]))]
for group in poly
for x in range(max([int(y)
for y in filter(lambda z: z.isdigit(), ['1',group[1]])]))]
new_poly = []
using namespace std;
string alphabetWar(string fight) {
const string left = "sbpw";
const string right = "zdqm";
int left_score = 0;
int right_score = 0;
for (int i = 0; i < fight.length(); i++) {
if (fight[i] == '*' || fight[i+1] == '*' || fight[i-1] == '*') continue;
function insertDash(num) {
return num.toString()
.split('')
.reduce((acc, n, i, array) => {
return acc += (i > 0 && parseInt(array[i]) % 2 != 0 && parseInt(array[i-1]) % 2 !== 0) ? `-${n}` : n
}, '')
}
const rps = (firstThrow, secondThrow) => {
if (firstThrow === secondThrow) {
return 'Draw!'
}
switch (firstThrow) {
case 'rock':
return (secondThrow === 'scissors') ? 'Player 1 won!' : 'Player 2 won!'
case 'paper':
return (secondThrow === 'rock') ? 'Player 1 won!' : 'Player 2 won!'
function dontGiveMeFive(start, end)
{
let count = 0;
for (index = start; index < end + 1; index++) {
if (!index.toString().includes('5')) {
count++;
}
}
return count;
}
using System;
using System.Linq;
public class Kata
{
public static int LargestPairSum(int[] numbers)
{
return numbers.OrderByDescending(x => x).ToArray()[0..2].Sum();
}
}