注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号 
x
#
# In order to solve the problems below you can import any standard
# python3 library.
#
# If you don't know Python, implement it in any other language.
#
# Good luck!
#
############
#
# Cheap Crowdfunding Problem
#
# There is a crowdfunding project that you want to support. This project
# gives the same reward to every supporter, with one peculiar condition:
# the amount you pledge must not be equal to any earlier pledge amount.
#
# You would like to get the reward, while spending the least amount > 0.
#
# You are given a list of amounts pledged so far in an array of integers.
# You know that there is less than 100,000 of pledges and the maximum
# amount pledged is less than $1,000,000.
#
# Implement a function find_min_pledge(pledge_list) that will return
# the amount you should pledge.
#
############
# The idea is based on bucket sort, we can easily do it with a sort, but the time complexity will be n * long(n)
def find_min_pledge(pledge_list):
nums = len(pledge_list)
for num in range(nums):
while 0 <= pledge_list[num] - 1 < nums and pledge_list[pledge_list[num] - 1] != pledge_list[num]:
tmp = pledge_list[num] - 1
pledge_list[num], pledge_list[tmp] = pledge_list[tmp], pledge_list[num]
for num in range(nums):
if pledge_list[num] != num + 1:
return num + 1
return nums + 1
assert find_min_pledge([1, 3, 6, 4, 1, 2]) == 5
# print(find_min_pledge([1, 3, 6, 4, 1, 2]))
assert find_min_pledge([1, 2, 3]) == 4
# print(find_min_pledge([1, 2, 3]))
assert find_min_pledge([-1, -3]) == 1
# print(find_min_pledge([-1, -3]))
############
#
# Extract Titles from RSS feed
#
# Implement get_headlines() function. It should take a url of an RSS feed
# and return a list of strings representing article titles.
#
############
google_news_url="https://news.google.com/news/rss"
def get_headlines(rss_url):
"""
@returns a list of titles from the rss feed located at `rss_url`
"""
return []
print(get_headlines(google_news_url))
############
#
# Streaming Payments Processor
#
# The function `process_payments()` is processing a large, but finite
# amount of payments in a streaming fashion.
#
# It relies on two library functions to do its job. The first function
# `stream_payments_to_storage(storage)` reads the payments from a payment
# processor and writes them to storage by calling `storage.write(buffer)`
# on it's `storage` argument. The `storage` argument is supplied by
# calling `get_payments_storage()` function. The API is defined below.
#
# TODO: Modify `process_payments()` to print a checksum of bytes written
# by `stream_payments_to_storage()`. The existing functionality
# should be preserved.
#
# The checksum is implemented as a simple arithmetic sum of bytes.
#
# For example, if bytes([1, 2, 3]) were written, you should printct(dict):
"""
Given a dict representing a row from a namespaces csv file,
returns a DAG configuration as a pair whose first element is the
DAG name
and whose second element is a dict describing the DAG's properties
"""
namespace = dict['Namespace']
return (dict['Airflow DAG'],
{"earliest_available_delta_days": 0,
"lif_encoding": 'json',
"earliest_available_time":
get_value(dict, 'Available Start Time', '07:00'),
"latest_available_time":
get_value(dict, 'Available End Time', '08:00'),
"require_schema_match":
get_value(dict, 'Requires Schema Match', 'True',
mapper=string_to_bool),
"schedule_interval":
get_value(dict, 'Schedule', '1 7 * * * '),
"delta_days":
get_value(dict, 'Delta Days', 'DAY_BEFORE',
lookup=DeltaDays),
"ftp_file_wildcard":
get_value(dict, 'File Naming Pattern', None),
"ftp_file_prefix":
get_value(dict, 'FTP File Prefix',
ftp_file_prefix(namespace)),
"namespace": namespace
}
)
# DeltaDays is not defined
# No error checking. dict.get() is better than directly assume key will be in dict
原题奉上, 第二题完全看不懂在问什么
|