Determine the winning amount

Let us assume betting game in which the outcome or result will be purely random.

In our hypothetical game, we have a black pot. There are three balls in the black pot. Red, Green, Blue.

Three players can play the game. Each player can bet on a ball or a combination of two balls.

So there are following possibilities to bet

  1. Red
  2. Green
  3. Blue
  4. Red & Green
  5. Red & Blue
  6. Green & Blue

Let X be the amount a player bet on Red.
You are the host who is conducting this game.
How will you determine an amount win by the player bet on red ball ?
And how will you determine the winning amount for six bets (Green, Red & Green,  etc..,)

Naming is hard

There are only two hard things in Computer Science: cache invalidation and naming things. – Phil Karlton

When discussing Property mechanism(a language feature of, I have encountered a basic question. I was saying ‘. .. the code will be used(or reused)  .. ‘. To confirm his interpretation my friend rephrase it as ‘so it is shared’.

I am bit stuck by encountering his words. I said in programming context we call it as “Code Reuse” and sharing has a different meaning in the context. Actually at first I couldn’t articulate it. He argued why can’t we use the word “sharing” until I explained.

Actually it is fundamental that there are terms which have some special meaning in some contexts.This reflects the fact that the Indian society lacks the culture of critical thinking and other knowledge movements.

This discussion triggers me to think about naming the functions, concepts, data in source code. Giving a meaningful name is really a challenge as stated in this blog. I borrowed title for this blog post from Hanselman.

Two Programming Problems – Computing Fiscal / Academic Calendar Dates

In lot of institution they follow their official calendar year that may starts from April to next year’s March of Gregorian calendar . Each institution choose their start month and end month of their calendar year. Each calendar year should have 365 days (366 in case of leap year)

Here goes First Problem.

Financial Institutions follows April-March Calendar period. Some Academic Institutions follow June-July Period. The Problem is if Start&End months of Calendar Period for an Institution and a date is provided, To Find Calendar year’s Start Date and End Date for given date.

Sample input: Current Date = 25th December 2014
Start Month = April
End Month = March
Output: Current Calendar year’s Start Date = 1st April 2014
Current Calendar year’s End Date = 31st March 2015

Sample input: Current Date = 14th February 2015
Start Month = April
End Month = March
Output: Current Calendar year’s Start Date = 1st April 2014
Current Calendar year’s End Date = 31st March 2015

Second Problem:  A person can subscribe to a Daily NewsPaper Company a range of date. The Daily News Paper Company follows the April-March Fiscal calendar. Find what are the financial years and no of days in each financial year company needs to deliver paper to the person.

for example Mr.X is subscribed to a Daily NewsPaper Company from 15th November 2014 to  26 February 2016. Then Company need to deliver newspaper for

Sample Input:Date Range: 15th November 2014 to  26 February 2016                                                                                  Start&End months of a Fiscal year:   April to March

Output:136 days in financial year of 1st April 2014 – 31st March 2015                                                                          331 days in financial year of 1st April 2015 – 31st March 2016

The intention is to get various points of view in Problem decomposition and solving a problem. So share your code in jsfiddle or any thing  for this two Problem in what ever Programming Languages.

May be given data is redundant or insufficient !

 What name would you give to the method (OR function OR procedure OR subroutine)  you going to implement for these problems ? The third skill specified in this post
I want the code with function (or what ever is in your context)  returning the output for each problem not printf statement 😛
And same conditions that told for Given data is also  apply for Output.  i.e. redundant or insufficient.
So give it in optimal way.
Your code should be with the test code to prove  your implementation is correct in all scenarios. So that any one can verify the implementation by running your code
I am eager for your replies