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
package practice | |
/** | |
* @author tejsudha | |
*/ | |
// To execute Scala code, please define an object named Solution that extends App | |
// open this pic: | |
// http://www.meeplemountain.com/wp-content/uploads/2017/05/scoring-example-1.jpg |
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 sys | |
import os | |
from optparse import OptionParser | |
def create_crif(input_filename=None, output_filename=None): | |
if input_filename and output_filename: | |
if os.path.exists(input_filename): | |
input_f = open(input_filename, "r") | |
# f = sys.stdout |
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 json | |
import pandas as pd | |
import numpy as np | |
from sklearn.decomposition import PCA | |
from sklearn import mixture | |
from mpl_toolkits.mplot3d import Axes3D | |
from sklearn.model_selection import train_test_split | |
from sklearn.metrics import confusion_matrix | |
def load_tmdb_movies(path): |
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 json | |
import pandas as pd | |
def load_tmdb_movies(path): | |
df = pd.read_csv(path) | |
df['release_date'] = pd.to_datetime(df['release_date']).apply(lambda x: x.date()) | |
json_columns = ['genres', 'keywords', 'production_countries', 'production_companies', 'spoken_languages'] | |
for column in json_columns: | |
df[column] = df[column].apply(json.loads) | |
return df |
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 java.io.PrintWriter | |
import scala.collection.mutable | |
import scala.collection.mutable.ListBuffer | |
object Solution { | |
def popular(num: Int, requests: Array[String]): Array[String] = { | |
val dateMap = new mutable.HashMap[String, mutable.HashMap[String, mutable.HashSet[String]]] | |
requests.foreach { request => |
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
case class MyShow[T](f: T => String) extends AnyVal | |
trait LowPriorityShow { | |
implicit def showAnything[T] = MyShow[T](_.toString) | |
} | |
object MyShow extends LowPriorityShow { | |
implicit val showDateTime = MyShow[DateTime](ISODateTimeFormat.dateTime().withZone(DateTimeZone.forID("America/New_York")).print _) |
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
# def matrix_sum(arr, i1, j1, i2, j2) | |
# sum = 0 | |
# (i1..(i2-1)).each do |i| | |
# (j1..(j2-1)).each do |j| | |
# sum += arr[i][j] | |
# end | |
# end | |
# return sum | |
# end |
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
def print_spiral(n) | |
arr = Array.new(n) | |
visited = Array.new(n) | |
(0..(n-1)).each do |i| | |
visited[i] = Array.new(n, false) | |
arr[i] = Array.new(n) | |
end | |
i = (n-1)/2 |
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
["309ccc71-9a29-3c44-e3c7-9c585a54c052", "20e5030b-5624-9bf9-3a36-e0b21fb96280", "bd587e52-96cb-9194-574d-b3dfebea0cad", "abe524e0-c24b-faa3-046b-cd74422090c2", "1fe9ce0b-d5e9-6bec-968c-651e16f5a03e", "e34affae-cfda-cec7-4122-eaf368db7205", "09136de3-651b-6ebf-ef05-bb02c91e2da3", "b754a956-ec4c-a081-01c6-85e160f50750", "ef9bf7f6-717c-4890-12f1-191a1e97649c", "05f0f35e-5cef-2ba1-a31a-3142db2ce0ad", "40f531de-ea24-4751-8bdb-c3b2cf978aab", "f81e1a5f-30e0-fff9-01bb-aba21a4b358c", "c8464f85-5161-f4a5-a519-0a14d4125f88", "df62e416-4de7-43fa-8eb7-a181b0ea6224", "2c10ea1a-15a3-7c28-3ae3-93a9fc6e5dd9", "f3dfeb0a-40a8-cf97-60db-7f8b5a6332ad", "26b092f7-3cc3-5360-266b-70c659393cf1", "3e3df53e-1609-eaa7-8d40-c2bfc1c44a4c", "cd992614-e8a9-1e79-efff-09ca6d957a97", "547813fe-1a01-8f1d-5118-a55c0b002ce0", "455917de-a5e6-11e2-8883-0025906a929e", "38d97059-6709-cb96-0ac3-c87c74fa8c8c", "ce1dd24a-292b-11e2-935a-00259061289e", "9199da6e-43ae-37bc-7b64-a2028f38d2bd", "28e1aa50-bd7b-ab51-6851-0c823cf7de20", "bcb2670a-75bb-687b-91b |
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
@sym_arr = ['/', '*', '+', '-'] | |
class Node | |
attr_accessor :val, :next, :prev | |
end | |
def createLinkedList(exp_arr) | |
prev = nil | |
head = nil |