Skip to content

Instantly share code, notes, and snippets.

@gennad
Created May 31, 2012 11:49
Show Gist options
  • Select an option

  • Save gennad/2842895 to your computer and use it in GitHub Desktop.

Select an option

Save gennad/2842895 to your computer and use it in GitHub Desktop.
Еще одна старая задача, не помню условие, но есть решение на Python
from decimal import Decimal, ROUND_HALF_UP
import logging
logging.basicConfig(level=logging.DEBUG)
# Constants for rounding
TWO_DIGITS_ROUND = Decimal("0.01")
SIX_DIGITS_ROUND = Decimal("0.000001")
result_lst = []
# Number of crawfish we want to sell.
# By the condition, we sell a crawfish in a day. It means that if we want to
# sell less than i crawfish (i < 7), we will sell them i days and (7 - i) days
# we do nothing.
crawfish_num = Decimal(7).quantize(TWO_DIGITS_ROUND)
# Cost of 'weekly pack' of crawfish
crawfish_cost = Decimal(1.02).quantize(TWO_DIGITS_ROUND)
# Out balance to Ith day
balance = Decimal(0)
# Collected amount of money to Ith day
for i in range(1, crawfish_num + 1): # For every day
i = Decimal(i)
expected = i * (crawfish_cost / crawfish_num)
expected = expected.quantize(TWO_DIGITS_ROUND, ROUND_HALF_UP)
today_collected = (expected - sum(result_lst))
result_lst.append(today_collected)
print 'Result:', result_lst, 'sum:', sum(result_lst)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment