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
object FizzBuzz { | |
def mod3(x: Int) = x % 3 | |
def mod5(x: Int) = x % 5 | |
def main(args: Array[String]) = { | |
val output = (1 to 1000000).map { | |
case x if mod3(x) + mod5(x) == 0 => "Fizz Buzz" | |
case x if mod5(x) == 0 => "Buzz" | |
case x if mod3(x) == 0 => "Fizz" |
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 numpy,math | |
import matplotlib.pyplot as plt | |
import random as random | |
random.seed(1) # set random seed. | |
# Draw random samples from Salpeter IMF. | |
# N ... number of samples. | |
# alpha ... power-law index. | |
# M_min ... lower bound of mass interval. |
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
object FizzBuzz { | |
def main(args: Array[String]) { | |
for (x <- 1 until 100001) { | |
if (0 == ((x%3)+(x%5))){ | |
println("Fizz Buzz"); | |
} else if (0 == (x%5)){ | |
println("Buzz"); | |
} else if (0 == (x%3)){ | |
println("Fizz"); | |
} else { |
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 fizzBuzz(x:Int) = { | |
if (x % 15 == 0) | |
"FizzBuzz" | |
else if (x % 3 == 0) | |
"Fizz" | |
else if (x % 5 == 0) | |
"Buzz" | |
else | |
x | |
} |
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 fizzbuzz(n): | |
if n % 3 == 0 and n % 5 == 0: | |
return 'FizzBuzz' | |
elif n % 3 == 0: | |
return 'Fizz' | |
elif n % 5 == 0: | |
return 'Buzz' | |
else: | |
return str(n) |
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 get_max_profit(stock_prices_yesterday): | |
# make sure we have at least 2 prices | |
if len(stock_prices_yesterday) < 2: | |
raise IndexError('Getting a profit requires at least 2 prices') | |
# we'll greedily update min_price and max_profit, so we initialize | |
# them to the first price and the first possible profit | |
min_price = stock_prices_yesterday[0] | |
max_profit = stock_prices_yesterday[1] - stock_prices_yesterday[0] |
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
# these modules are needed for the task | |
import luigi | |
import smtplib | |
from email.mime.multipart import MIMEMultipart | |
from email.mime.text import MIMEText | |
from email.mime.base import MIMEBase | |
from email import encoders | |
from dataextract import Manager | |
import pandas as pd | |
import json |
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
object Factorial2 { | |
def main(args: Array[String]) | |
{ for (i <- 1 to 30) | |
println("Factorial of " + i + ": = " + factorial(i)) | |
} | |
def factorial(n: BigInt): BigInt = { | |
if (n <= 1) | |
1 | |
else |
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
class SendEmail(luigi.Task): | |
def run(self): | |
fromaddr = EMAIL | |
toaddr = EMAIL | |
msg = MIMEMultipart() | |
msg['From'] = fromaddr | |
msg['To'] = toaddr | |
msg['Subject'] = "Daily Update of Cohorts" | |
body = "Here is the cohort update" | |
msg.attach(MIMEText(body, 'plain')) |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.