Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
chillin

Ryan Yan apsicle

💭
chillin
  • Gamechanger
  • New York, New York
View GitHub Profile
View nQueens.js
function nQueens(n) {
const placeNQueens = (n) => {
let allPermutations = [];
let board = Array(n).fill(Array(n).fill(1));
let permutation = [];
const placeQueen = (board, row, col) => {
const n = board[0].length;
let newBoard = board.map((row) => {
return row.slice();
View backupthreadsSolved.js
// Rewrote my solution from scratch to be more modular
/* Datto is working on creating a backup-time estimator. For simplicity's sake, let's assume that there is only one server completing multiple jobs (i.e. backups) in parallel. Without any parallelization, the ith job takes backupDurationi units of time to be backed up. But if there are n jobs running in parallel, the backup process goes n times slower for each job.
For the ith job you know the value of backupDurationi and the moment startTimesi it was added to the backup queue. Your task is to estimate all the backup completion times. Note that it is impossible to have more than maxThreads threads performing backups in parallel. If there is more than one job waiting to be backed up, the one with the smallest initial backup time is chosen. It's guaranteed that all the jobs are added to the backup queue at different times.
Example
For startTimes = [461620201, 461620202, 461620203],
backupDuration = [2, 2, 2] and maxThreads = 2,
the output should be
@apsicle
apsicle / backupthreads.js
Created Nov 14, 2017
codefights problem I may come back to.
View backupthreads.js
// if you have backup time k for each of n jobs, and each job in parallel goes n times slow (k * n), the completion time for the whole batch is always k * n with or without parallelization.
function backupTimeEstimator(startTimes, backupDuration, maxThreads) {
// Null case
if (startTimes.length === 0) {
return [];
}
// Set up jobs queue, ending time array, jobs running array, and current time.
let jobsQueue = startTimes.map((time, index) => {
View package.json
{
"name": "react_redux",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"scripts": {
"serve": "live-server public/",
"build": "webpack",
"build-babel": "babel src/app.js --out-file=public/scripts/app.js --presets=env,react --watch",
"dev-server": "webpack-dev-server",
View ExpenseForm.test.js
import React from 'react';
import { shallow } from 'enzyme';
import ExpenseForm from '../../components/ExpenseForm.js';
import expenses from '../fixtures/expenses';
test('should render ExpenseForm correctly', () => {
const wrapper = shallow(<ExpenseForm />);
expect(wrapper).toMatchSnapshot();
});
View TestComponent.test.js
import React from 'react';
import { shallow } from 'enzyme';
class TestComponent extends React.Component {
constructor(props) {
super(props);
this.state = {
description: 'asdf123'
};
View portfolio_gallery.js
View egyptian_decompose.py
from fractions import Fraction as f
import math
def decompose(n):
frac = f(n)
out = []
current_denom = 1
if frac >= 1:
number = int(frac)
View tictactoe_comp.py
# Written by: Ryan Yan
# Paired with Oskar Thoren
# Date: October 11th, 2016
#
# This program lets you play tic tac toe in the console using keyboard input against a computer.
import random
class Player:
'''Player objects keep track of the spaces they control on the grid (add_square and get_squares)
and has their symbol, default X's and O's as their string representation'''
View tictactoe.py
# Written by: Ryan Yan
# Date: October 10th, 2016
#
# This program lets two players play tic tac toe in the console using keyboard input.
class Player:
'''Player objects keep track of the spaces they control on the grid (add_square and get_squares)
and has their symbol, default X's and O's as their string representation'''