IPL: THE RUN CHASE

I was recently watching a IPL T20 match on Youtube. It was Kings-XI vs. Kolkata Knight Riders.

The highlight of the match was when Chris Gayle got going and hauled 5 consecutive sixes in an over. What was amazing was the ease with which he was timing the ball. He was simply hitting the ball wherever he wanted around the stadium. Spin, pace, line, length… nothing mattered. Once the bowler delivered the ball, Gayle used to simply make contact in one fluid motion, and the ball would launch as if it suddenly had fired-up rocket boosters and continued flying skywards out of the stadium…

This happened not once or twice… BUT 5 TIMES IN A ROW!!

But it was not for long. Pity he got out trying to haul one over long-off in the next over.

It reminded me of that one over by Chris Broad in which Yuvraj Singh smashed 6 sixes of 6 balls continuously.

|| Yuvraj Singh : 6 sixes in 6 balls ||

The way batsmen can pound and smash away on a good day kind of got me wondering. What if some day batsmen are able to score at will. If one is chasing a big score and can score at will. What is the best way to chase the target. In other words, given a target of N runs and x balls to achieve it, what is the least risky way to achieve the target?

IPL Problem No.1 : THE RUN CHASE

1. Assume you can score exactly as you want on each ball.

2. Single/Double/Triple/Four/Six are the options available to you.

3. RISK is defined as the square of the score on each ball.

* * * *

Write a program that accepts:-
a. Target runs to score (N)
b. No. of balls to score it in (x)

and prints the runs to score on each ball.

Remember U have to ACHIEVE the target with MINIMUM RISK possible.

Here’s a sample :

Target: 16

Balls: 6

Scoring: 2 2 3 3 3 3
(order is not important i.e. 2 3 3 2 3 3 is right too)

Risk involved: 44 << This should be minimum possible.

(calculated using the table above)

4 triples i.e. 4 * 9 = 36
2 doubles i.e. 2 * 4 = 8
________________
Total RISK = 36 + 8 = 44

NOTE: A basic understanding of runs in CRICKET could be helpful. 😉

Post in ur code/algorithm/analyses as the comments below. Good Luck!!

__________________________

UPDATE :
People who solved the Puzzle.

Checkout the Hall-of-FAME.


Add to FacebookAdd to DiggAdd to Del.icio.usAdd to StumbleuponAdd to RedditAdd to BlinklistAdd to TwitterAdd to TechnoratiAdd to Yahoo BuzzAdd to Newsvine

Advertisements

~ by CVS268 on Sun, 04 Apr, 2010.

12 Responses to “IPL: THE RUN CHASE”

  1. isnt dis the napsack problem??

  2. Easy:

    while x>0
    r=ceil(N/x)
    if r=5 then r=6
    print r
    N=N-r
    x=x-1
    endwhile

  3. Your example is wrong. The correct minimization of risk occurs with 2 2 3 3 3 3. With those scores you get 16 runs with a risk of 2*4 + 4*9 = 44.

  4. Isn’t it just (pseudo code):
    smallScore = runs div balls
    largeScore = smallScore + 1
    largeScoreCount = runs mod balls
    smallScoreCount = balls – largeScoreCount

  5. #include
    score1(int n,int x);
    score2(int n,int x);
    score3(int n,int x);
    score4(int n,int x);
    score6(int n,int x);
    void main()
    {
    int n,x,risk=0;
    clrscr();
    printf(“Enter the runs we have to score & number of balls available\n”);
    scanf(“%d%d”,&n,&x);
    if(n<=x)
    risk=score1(n,x);
    else if(n/2.0<=(float)x)
    risk=score2(n,x);
    else if(n/3.0<=(float)x)
    risk=score3(n,x);
    else if(n/4.0<=(float)x)
    risk=score4(n,x);
    else if(n/6.0<=(float)x)
    risk=score6(n,x);
    else
    printf("The given score is impossible to score under given number of balls !!!");
    printf("\nRisk factor=%d%",risk);
    getch();
    }
    score1(int n,int x)
    {
    int i;
    for(i=0;i<n;i++)
    {
    if(x==0)
    break;
    printf("1,");
    x–;
    }
    return(i);
    }
    score2(int n,int x)
    {
    static int rsk=0;
    int i,m=n;
    for(i=1;i<=m;i++)
    {
    printf("2,");
    n=n-2;
    x–;
    rsk=rsk+4;
    if(n<=x)
    break;
    }
    rsk=rsk+score1(n,x);
    return(rsk);
    }
    score3(int n,int x)
    {
    static int rsk=0;
    int i,m=n;
    float j;
    for(i=1;i<=m;i++)
    {
    printf("3,");
    n=n-3;
    x–;
    rsk=rsk+9;
    j=n/2.0;
    if(j<=(float)x)
    break;
    }
    rsk=rsk+score2(n,x);
    return(rsk);
    }
    score4(int n,int x)
    {
    static int rsk=0;
    int i,m=n;
    float j;
    for(i=1;i<=m;i++)
    {
    printf("4,");
    n=n-4;
    x–;
    rsk=rsk+16;
    j=n/3.0;
    if(j<=(float)x)
    break;
    }
    rsk=rsk+score3(n,x);
    return(rsk);
    }
    score6(int n,int x)
    {
    static int rsk=0;
    int i,m=n;
    float j;
    for(i=1;i<=m;i++)
    {
    printf("6,");
    n=n-6;
    x–;
    rsk=rsk+36;
    j=n/4.0;
    if(j<=(float)x)
    break;
    }
    rsk=rsk+score4(n,x);
    return(rsk);
    }

  6. Sorry for spotting you so late :

    #include
    int main()
    {
    int runs=0,balls=0; // I love cricket puzzles.
    int risk=0; // risk involved.
    cin>>runs>>balls;
    int rpb=runs/balls; // rate per ball.
    if(rpb<=6)
    {
    cout<0)
    {
    rpb=runs/balls;
    cout<<rpb<<" ";
    risk+=rpb*rpb; // guaranteed to be minimum!
    runs-=rpb;
    balls–;
    }
    cout<<"\nRisk Involved : "<<risk;
    }
    else
    cout<<"Impossible!"<<endl;
    return 0;
    }

    • #include
      int main()
      {
      int runs=0,balls=0;
      int risk=0;
      cin>>runs>>balls;
      int rpb=runs/balls;
      if(rpb<=6)
      {

      cout<0)
      {
      rpb=runs/balls;
      cout<<rpb<<" ";
      risk+=rpb*rpb;
      runs-=rpb;
      balls–;
      }
      cout<<"\nRisk Involved : "<<risk;
      }
      else
      cout<<"Impossible!"<<endl;
      return 0;
      }

  7. # Ruby code
    print “How many runs : ”
    n = gets.to_i
    print “How many balls : ”
    x = gets.to_i
    scores = []
    if x*6 = n
    scores.push r
    n = n – r
    break
    end
    end
    x = x-1;
    end
    end

    puts “\nScoring : #{scores.join(‘, ‘)}”

    puts “\n Minimum Risk : #{scores.map {|s| s * s}.inject {|sum, s| sum + s }}”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s