Skip to content

Instantly share code, notes, and snippets.

@ooade
ooade / weighted_mean.py
Created September 5, 2016 12:07
Hackerrank Statistics Day 0: Weighted Mean
raw_input()
m = raw_input()
w = raw_input()
w = [float(i) for i in w.split()]
m = sum([w[int(i)] * int(j) for i, j in enumerate(m.split())])
print "%.1f" % (m / sum(w))
@ooade
ooade / bank_account.py
Created September 5, 2016 13:18
Bank Account
class BankAccount():
def withdraw():
pass
def deposit():
pass
class SavingsAccount(BankAccount):
def __init__(self):
self.balance = 500
@ooade
ooade / replicate.py
Created September 6, 2016 01:37
Replicate
def replicate_recur(times, data):
try:
if type(data) is not(int) and type(data) is not(str):
raise ValueError("Wrong Input Found!")
arr = []
def recur(times, data):
if times <= 0:
return arr
else:
arr.append(data)
@ooade
ooade / manipulate_data.py
Created September 6, 2016 01:48
Manipulate Data, Return sum of negatives and number of positives
def manipulate_data(lst):
if type(lst) is not(list):
print type(lst)
return "Only lists allowed"
negatives = sum(filter(lambda x: x < 0, lst))
positives = len(filter(lambda x: x > -1, lst))
return [positives, negatives]
@ooade
ooade / mars1.js
Created September 6, 2016 20:29
Mars Exploration 1
function main() {
let N = readLine()
let S = N.match(/.{1,3}/g);
let R = 'SOS'.repeat(N.length / 3).match(/.{1,3}/g);
let count = 0;
for (let i in S) {
for (let j in S[i]) {
if (S[i][j] !== R[i][j]) {
@ooade
ooade / mars2.js
Created September 6, 2016 20:30
Mars Exploration 2
function main() {
let S = readLine().match(/.{1,3}/g);
let count = 0;
for (let i in S) {
if (S[i][0] !== 'S') {
count++;
}
@ooade
ooade / quartiles.js
Created September 10, 2016 13:41
Hackerrank Day 1 Quartiles; 10 Days of Statistics
const log = (...args) => args.map(arg => console.log(arg)); // Pollyfill for Logging each args on a new line
function processData(input) {
let ARR = input.split('\n');
ARR.shift();
ARR = ARR.join().split(' ').map(Number).sort((a, b) => a - b);
let Q1a = []; // First Quartile Array
let Q3a = []; // Third Quartile Array
@ooade
ooade / left_rotation.js
Created October 7, 2016 06:35
Hackerrank (Arrays: Left Rotation)
function main() {
var n_temp = readLine().split(' ');
var n = parseInt(n_temp[0]);
var k = parseInt(n_temp[1]);
a = readLine().split(' ');
a = a.map(Number);
var i = k;
if (k > n) {
@ooade
ooade / server.dev.js
Last active November 3, 2016 04:14
Initialize express without webpack
const express = require('express');
// Chalk was added by create-react-app, use only on the dev side
const chalk = require('chalk');
// Initialize express
const app = express();
const PORT = process.env.PORT || 3000;
// Start up our express server
app.listen(PORT, (error) => {
@ooade
ooade / package.json
Created November 3, 2016 04:23
Express...
{
"name": "express-without-eject",
"version": "0.1.0",
"private": true,
"devDependencies": {
"react-scripts": "0.7.0"
},
"dependencies": {
"express": "^4.14.0"
},