This file contains hidden or 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
| data <- read.csv('https://storage.googleapis.com/mledu-datasets/california_housing_train.csv') | |
| data$lat_bin <- cut(data$latitude, breaks=c(floor(min(data$latitude)):round(max(data$latitude))), include.lowest=T) | |
| data$lat_bin <- as.numeric(data$lat_bin) |
This file contains hidden or 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
| divisors <- function(a) { | |
| pairs <- data.frame() | |
| smallest <- NA | |
| for (b in 1:999999) { | |
| # No need to check further, as b*c = c*b. | |
| if (!is.na(smallest) && b >= smallest) | |
| break; | |
| # Find the next factor. |
This file contains hidden or 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
| hamming <- function(s1, s2) { | |
| distances <- NA | |
| # Ensure the strings are equal length. | |
| if (nchar(s1) == nchar(s2)) { | |
| # Split the strings into characters. | |
| s1 <- unlist(strsplit(s1, '')) | |
| s2 <- unlist(strsplit(s2, '')) | |
| # Mark characters that do not match. |
This file contains hidden or 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
| base62 <- function(num, n = 62) { | |
| result <- c() | |
| symbols <- unlist(strsplit('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', '')) | |
| total <- 0 | |
| place <- 0 | |
| index <- 0 | |
| # Find the most significant place and index that doesn't exceed our number. | |
| while (total < num) { | |
| # Start with the max value for this place. |
This file contains hidden or 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
| library(Metrics) | |
| # Load dataset. | |
| data <- read.csv('https://storage.googleapis.com/mledu-datasets/california_housing_train.csv') | |
| # Scale housing_median_value for an easier learning rate. | |
| data$median_house_value_scaled <- data$median_house_value / 1000 | |
| # Randomize the dataset. | |
| data <- data[sample(nrow(data)),] |
This file contains hidden or 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
| // | |
| // parent is a jQuery element of the parent container. | |
| // target is the DOM element to scroll into view. | |
| // | |
| scrollIntoViewIfNeeded = (parent, target) => { | |
| const rect = target.getBoundingClientRect(); | |
| // Check the bottom border to scroll view down. | |
| if (rect.bottom > window.innerHeight) { | |
| target.scrollIntoView(false); |
This file contains hidden or 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
| shelfCount <- function(shelves, books) { | |
| totalShelves <- sum(shelves) | |
| totalBooks <- sum(books[,1]) | |
| # Check if enough shelf space exists. | |
| if (totalShelves < totalBooks) { | |
| 'impossible' | |
| } | |
| else { | |
| # Sort shelf sizes. |
This file contains hidden or 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
| https://medium.freecodecamp.org/elegant-patterns-in-modern-javascript-roro-be01e7669cbd |
This file contains hidden or 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
| change <- function(target, coins, condition, numCoins) { | |
| # Finds all combinations of coins to equal the target value while using the condition number of coins. | |
| solutions <- c() | |
| for (h in 1:max(numCoins, length(coins))) { | |
| # Start by considering h = 1, 2, 3, ... coins. | |
| combinations <- combn(coins, h) | |
| solutions <- c(solutions, sapply(1:ncol(combinations), function(colIndex) { | |
| combination <- combinations[,colIndex] | |
| total <- sum(combination) |
This file contains hidden or 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
| library(ggplot2) | |
| simulate <- function(numMales, numFemales, goal) { | |
| result <- data.frame() | |
| # Create rabbits. | |
| males <- c(0, numMales) | |
| females <- c(0, numFemales) | |
| month <- 0 | |