{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 22: Races "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example number 22.1, Page number 22.3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "A's time over the course is 241.0 sec\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "bt=9;       #beat time(sec)\n",
    "st=0;       #start time(sec)\n",
    "bd=36;      #beat distance(m)\n",
    "sd=0;       #start distance(m)\n",
    "L=1000-36;   #loser's distance(m)\n",
    "\n",
    "#Calculation\n",
    "At=(bt+st)*L/(bd+sd);     #A's time over the course(sec)\n",
    "\n",
    "#Result\n",
    "print \"A's time over the course is\",At,\"sec\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example number 22.2, Page number 22.4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "length of race of winning post is 120.0 m\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "V=1;     #assume\n",
    "A=4/3;   #speed of A relative to B\n",
    "d=30;    #distance(m)\n",
    "\n",
    "#Calculation\n",
    "L=d/(V-(1/A));      #length of race of winning post(m)\n",
    "\n",
    "#Result\n",
    "print \"length of race of winning post is\",L,\"m\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example number 22.3, Page number 22.4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "start distance is 40.0 m\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "bt=0;       #beat time(sec)\n",
    "st=10;       #start time(sec)\n",
    "bd=0;      #beat distance(m)\n",
    "L=250;   #loser's distance(m)\n",
    "W=1000;    #winner's distance(m)\n",
    "\n",
    "#Calculation\n",
    "x=L/W;\n",
    "sd=((bt+st)/x)-bd;    #start distance(m)\n",
    "\n",
    "#Result\n",
    "print \"start distance is\",sd,\"m\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example number 22.4, Page number 22.4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "beat distance is 3.33 m\n",
      "answer given in the book is wrong\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "bt=10;       #beat time(sec)\n",
    "st=0;       #start time(sec)\n",
    "sd=0;      #start distance(m)\n",
    "L=300;   #loser's distance(m)\n",
    "W=100;    #winner's distance(m)\n",
    "\n",
    "#Calculation\n",
    "x=L/W;\n",
    "bd=((bt+st)/x)-sd;    #beat distance(m)\n",
    "\n",
    "#Result\n",
    "print \"beat distance is\",round(bd,2),\"m\"\n",
    "print \"answer given in the book is wrong\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example number 22.5, Page number 22.4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "C would beat B by 2.04 m\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "L=100;    #length of race(m)\n",
    "x12=2;    #A beats C by(m)\n",
    "x13=4;    #A beats B by(m)\n",
    "\n",
    "#Calculation\n",
    "x23=L*(x13-x12)/(L-x12);      #C would beat B by(m)\n",
    "\n",
    "#Result\n",
    "print \"C would beat B by\",round(x23,2),\"m\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example number 22.6, Page number 22.5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "C would beat B by 20.0 m\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "L=1000;    #length of race(m)\n",
    "x12=50;    #A beats C by(m)\n",
    "x13=69;    #A beats B by(m)\n",
    "\n",
    "#Calculation\n",
    "x23=L*(x13-x12)/(L-x12);      #C would beat B by(m)\n",
    "\n",
    "#Result\n",
    "print \"C would beat B by\",x23,\"m\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example number 22.7, Page number 22.5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "speed of B is 1.6 m/s\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "Ad=100;     #distance of A(m)\n",
    "Bd=Ad-4;     #distance of B(m)\n",
    "As=2;       #speed of A(m/s)\n",
    "bt=10;       #beat time(sec)\n",
    "st=0;       #start time(sec)\n",
    "\n",
    "#Calculation\n",
    "t=bt+st;\n",
    "Bs=Bd/(t+(Ad/As));      #speed of B(m/s)\n",
    "\n",
    "#Result\n",
    "print \"speed of B is\",Bs,\"m/s\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example number 22.8, Page number 22.5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "B wins by 1.0 s\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "Bd=330;     #distance of B(m)\n",
    "Bt=44;      #time of B(sec)\n",
    "sd=30;      #start distance(m)\n",
    "A=41;       #time taken for A(sec)\n",
    "\n",
    "#Calculation\n",
    "B=Bt*(Bd-sd)/Bd;    #time taken for B(sec)\n",
    "T=A-B;     #B wins by(s)\n",
    "\n",
    "#Result\n",
    "print \"B wins by\",T,\"s\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example number 22.9, Page number 22.5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "time taken for A is 24.0 sec\n",
      "answer given in the book is wrong\n",
      "time taken for B is 30.0 sec\n",
      "time taken for C is 32.0 sec\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "L=200;    #length of race(m)\n",
    "x12=40;    #A beats C by(m)\n",
    "x13=50;    #A beats B by(m)\n",
    "Tc=2;      #time for C(sec)\n",
    "\n",
    "#Calculation\n",
    "x23=L*(x13-x12)/(L-x12);      #C would beat B by(m)\n",
    "C=Tc*L/x23;       #time taken for C(sec)\n",
    "B=C-Tc;         #time taken for B(sec)\n",
    "A=B*(L-x12)/L;   #time taken for A(sec)\n",
    "\n",
    "#Result\n",
    "print \"time taken for A is\",A,\"sec\"\n",
    "print \"answer given in the book is wrong\"\n",
    "print \"time taken for B is\",B,\"sec\"\n",
    "print \"time taken for C is\",C,\"sec\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example number 22.10, Page number 22.6"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "A can give C a start of 64.0 m\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "L=1000;    #length of race(m)\n",
    "x12=40;    #A beats C by(m)\n",
    "x23=25;    #A beats B by(m)\n",
    "\n",
    "#Calculation\n",
    "x13=(x23*(L-x12)/L)+x12;      #A can give C a start of(m)\n",
    "\n",
    "#Result\n",
    "print \"A can give C a start of\",x13,\"m\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example number 22.11, Page number 22.6"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "A will beat C by 58.0 m\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "L=400;    #length of race(m)\n",
    "L1=600;   #full length of race(m)\n",
    "L2=500;   #length of another race(m)\n",
    "x12=60;    #A beats B by(m)\n",
    "x23=25;    #A beats C by(m)\n",
    "\n",
    "#Calculation\n",
    "x12=x12*L/L1;    #A beats B by(m)\n",
    "x23=x23*L/L2;    #A beats C by(m)\n",
    "x13=(x23*(L-x12)/L)+x12;      #A will beat C by(m)\n",
    "\n",
    "#Result\n",
    "print \"A will beat C by\",x13,\"m\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example number 22.12, Page number 22.7"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "speed of A is 8.0 m/s\n",
      "speed of B is 7.0 m/s\n"
     ]
    }
   ],
   "source": [
    "#importing modules\n",
    "import math\n",
    "from __future__ import division\n",
    "\n",
    "#Variable declaration\n",
    "L=400;    #length of race(m)\n",
    "Bt1=50/7;   #time taken by B more than A(sec)\n",
    "Bt2=5;      #time taken by B with lesser distance(sec)\n",
    "d=15;       #lesser distance(m)\n",
    "\n",
    "#Calculation\n",
    "Bt=Bt1-Bt2;   #time taken for B(sec)\n",
    "Bs=d/Bt;      #speed of B(m/s)\n",
    "VA=L/((L/Bs)-Bt1);    #speed of A(m/s)\n",
    "\n",
    "#Result\n",
    "print \"speed of A is\",VA,\"m/s\"\n",
    "print \"speed of B is\",Bs,\"m/s\""
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}