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 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(); |
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
// 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 |
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
// 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) => { |
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
{ | |
"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", |
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 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(); | |
}); |
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 React from 'react'; | |
import { shallow } from 'enzyme'; | |
class TestComponent extends React.Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
description: 'asdf123' | |
}; |
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
"use strict"; | |
let n = 5; //number of images, i.e. sides of the carousel | |
let panel_width = window.innerWidth * .4167; //width of a panel, i.e. length of a side on the polygon | |
let ratio_mismatch = false; | |
if(Math.abs((window.innerWidth / window.innerHeight) - (1920 / 1012)) > .20) { | |
// if the aspect ratio of the viewport and the video is off, since you can't change the aspect ratio of | |
// the video on the fly, the video sometimes will not completely cover the image it's laid on top of. | |
// In this case, we'll hide the image when the user hovers over the image. | |
ratio_mismatch = true; | |
$('.carousel_image').css("transition", "opacity 0.5s ease-out"); |
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
from fractions import Fraction as f | |
import math | |
def decompose(n): | |
frac = f(n) | |
out = [] | |
current_denom = 1 | |
if frac >= 1: | |
number = int(frac) |
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
# 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''' |
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
# 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''' |
NewerOlder