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
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') |
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
function inAscOrder(arr) { | |
let prevNum = 0 | |
for (num of arr) { | |
if (num < prevNum) { | |
return false | |
} else { | |
prevNum = num | |
} | |
} | |
return true |
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
function count(array){ | |
let result = {} | |
for (ele of array) { | |
result[ele] = (ele in result) ? result[ele] + 1 : 1 | |
} | |
return result | |
} |
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
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): |
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
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 = [] |
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
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; |
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
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 | |
}, '') | |
} |
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 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!' |
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
function dontGiveMeFive(start, end) | |
{ | |
let count = 0; | |
for (index = start; index < end + 1; index++) { | |
if (!index.toString().includes('5')) { | |
count++; | |
} | |
} | |
return count; | |
} |
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
using System; | |
using System.Linq; | |
public class Kata | |
{ | |
public static int LargestPairSum(int[] numbers) | |
{ | |
return numbers.OrderByDescending(x => x).ToArray()[0..2].Sum(); | |
} | |
} |
NewerOlder