Skip to content

Instantly share code, notes, and snippets.

View mayonesa's full-sized avatar
🇺🇦

John Jimenez mayonesa

🇺🇦
  • Florida, USA
View GitHub Profile
@mayonesa
mayonesa / Week.scala
Created February 6, 2022 22:40
Find the longest period of time when there are no ongoing meetings
import math.max
/*
James is a businessman. He is on a tight schedule this week. The week starts
on Monday at 00:00 and ends on Sunday at 24:00. His schedule consists of M
meetings he needs to take part in. Each of them will take place in a period of
time, beginning and ending on the same day (there are no two ongoing meetings
at the same time). James is very tired, thus he needs to find the longest
possible time slot to sleep. In other words, he wants to find the longest
period of time when there are no ongoing meetings. The sleeping break can
@mayonesa
mayonesa / InterestingTimes.scala
Created February 6, 2022 22:35
Time using at most 2 numbers
import java.text.SimpleDateFormat
import java.time.Instant
import java.util.Date
import java.util.concurrent.TimeUnit
import TimeUnit.{MILLISECONDS => Milliseconds}
import TimeUnit.{SECONDS => Seconds}
import scala.annotation.tailrec
/*
@mayonesa
mayonesa / Assassin.scala
Last active February 6, 2022 22:31
Given a board, `b`, with obstacles, guards, and an assassin, will determine if said assassin can reach the bottom right undetected
import scala.annotation.tailrec
/*
Assassin
--------
Write a method that given a board, `b`, with obstacles, guards, and an assassin, will determine if said assassin can
reach the bottom right undetected:
object Assassin {
def undetected(b: Array[String]): Boolean
object ArrayRotation {
def rotate(a: Array[Int], k: Int): Array[Int] = {
val n = a.length
lazy val kRn = k % n
if (n == 0 || kRn == 0)
a
else
Array.tabulate(n) { i =>
val j = i - kRn
@mayonesa
mayonesa / DivBy3.scala
Last active February 6, 2022 22:25
Given a string representation of a number, returns the number of variations of said input that is divisible by 3
/* Divisible by 3
--------------
Given a string representation of a number, returns the number of variations of said input that is divisible by 3. The variations consist of changing one digit for each variation.
For example, "21"'s variations are:
01
11
21
31
@mayonesa
mayonesa / MusicSharingRoom.scala
Last active February 4, 2022 17:34
music-listening rooms that allow for adding and vote-for-skipping songs, and chatting
package jj.musicshareroomapp.msr
import scala.concurrent
import concurrent.{ Future, Promise, ExecutionContext }
import ExecutionContext.Implicits.global
import Future.firstCompletedOf
import concurrent.duration._
import scala.util.{ Success, Failure }
import scala.collection
import collection.parallel
log_factorial <- function (n) {
# Return the log of factorial(n) for any integer n > 0
if (n <= 1)
return (0)
return (log(n) + log_factorial(n - 1))
}
sum_log_factorial <- function (n) {
# Return the sum of log_factorial(i) for i in 1..n
sum <- 0
@mayonesa
mayonesa / pr2.Rmd
Last active February 4, 2022 17:33
---
title: 'Project 2: Modeling and Evaluation'
subtitle: '<p>CSE6242 - Data and Visual Analytics</p><p>Due: Friday, April 21, 2017
at 11:59 PM UTC-12:00 on T-Square</p>'
output:
pdf_document: default
html_document: default
---
# Data
@mayonesa
mayonesa / ac4.R
Last active February 4, 2022 17:33
# AC4: Visualize Vehicular Accident Non-motorist Mortalities per State
# inspirational reference: https://blog.dominodatalab.com/geographic-visualization-with-rs-ggmaps/
# infrastructure
install.packages("ggmap", type = "source")
library(ggmap)
setwd("~/Google Drive/gatech/dva/ac4") # **** Needs to accomodate particular workstation ****
vas <- read.csv("vehicle-accidents.csv")
# only continental states
# Activity: Time Series Analysis
library(zoo) # basic time series package
library(xts) # eXtensible Time Series package
data_dir <- "data"
label_dir <- "labeled_windows"
load_ts <- function(csv_filename) {
# Load and return time series data from a CSV file.