<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="../feed.xsl" type="text/xsl"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title>Susam's Stories</title>
  <subtitle>Feed for Susam's Stories</subtitle>
  <link href="https://susam.net/"/>
  <link href="https://susam.net/tag/story.xml" rel="self"/>
  <id>https://susam.net/tag/story.xml</id>
  <updated>2026-05-16T00:00:00Z</updated>
  <author><name>Susam Pal</name></author>
  <entry>
    <title>Five Minutes of Prime Time</title>
    <link href="https://susam.net/five-minutes-of-prime-time.html"/>
    <id>urn:uuid:98fe77c7-c72a-4c4a-93da-315d1342a76b</id>
    <updated>2026-05-16T00:00:00Z</updated>
    <content type="html">
<!-- BEGIN HTML -->
&lt;p&gt;
  Let me share a very silly story from roughly 18 years ago!  In 2008,
  I joined
  &lt;a href=&quot;https://en.wikipedia.org/wiki/RSA_Security&quot;&gt;RSA&lt;/a&gt;, the
  network security company named after the initials of the inventors
  of the RSA algorithm, Rivest, Shamir and Adleman, who were also the
  founders of RSA, the company.
&lt;/p&gt;
&lt;p&gt;
  There was a bit of a nerd culture in the workplace where topics like
  prime numbers, combinatorics, probability theory, etc. were
  discussed fervently.  A prime-number employee number was considered
  a lucky charm.  I had a rather nice large five-digit prime number as
  my employee number, which I remember being quite pleased about.
  There were internal forums for almost all kinds of topics.  A few I
  remember fondly were a mathematics forum where colleagues would
  challenge each other with mathematical puzzles and a similar physics
  forum where, for some reason, crafting contrived paradoxes using
  special and general relativity and putting them up for debate was a
  common activity.  The participants would analyse each paradox to
  determine if it truly was one or if it could be resolved into
  something that was no longer a paradox.  In fact, my
  &lt;a href=&quot;langford-pairing.html&quot;&gt;Langford Pairing&lt;/a&gt; (2011) post was
  the result of a question I had stumbled upon in the mathematics
  forum.
&lt;/p&gt;
&lt;p&gt;
  The human resources (HR) department used to organise afternoon games
  once every month where people would self-organise into teams and
  solve a small challenge.  There was a cash prize for the winning
  team each time.  The HR folks were very well aware of the nerd
  culture and the fascination with prime numbers, but they probably
  did not know enough about exactly what type of problems we were
  fascinated with.  So in one of the monthly game events, the HR team
  gave us this challenge.
&lt;/p&gt;
&lt;p class=&quot;highlight&quot;&gt;
  Write as many prime numbers between 1 and 1000 as you can in 5
  minutes.
&lt;/p&gt;
&lt;p&gt;
  The 5-minute timer started immediately.  Really, that was the
  challenge.  We all looked at each other in surprise, wondering if
  that really was the problem.  The game was already on.  No
  constraints were set.  Were we allowed to look up a list on the web?
  Probably not, otherwise what would be the point of the game?
&lt;/p&gt;
&lt;p&gt;
  There were five or six teams with a total of about 30 or so
  participants.  We began working on the challenge.  The first thing I
  did was load up the list of all 168 prime numbers from 1 to 1000 on
  my mobile phone and begin copying them meticulously to our sheet of
  paper.
&lt;/p&gt;
&lt;p&gt;
  I would learn later that another team had followed the same approach
  too.  The person writing their list decided to omit a few numbers so
  that it did not look like they had copied the numbers verbatim from
  an external source.  I think they were being overcautious because
  there were no rules, and all is fair in love and listing prime
  numbers.
&lt;/p&gt;
&lt;p&gt;
  I completed writing our list with about half a minute to spare.  We
  turned in our sheets after the timer ran out.  The HR folks then
  evaluated the sheets.  The winner was announced.  Our team won with
  all 168 numbers written accurately.  We won the cash prize.  One of
  the HR folks asked me later what formula we had used to generate all
  the prime numbers so accurately.  I told them that we had used the
  ancient formula of looking up a list of prime numbers compiled by
  someone else and writing it down.  We spent the cash prize
  immediately and ordered pizza and soft drinks for everyone.
&lt;/p&gt;
&lt;p&gt;
  The monthly afternoon games were not usually this silly.  The other
  games were more interesting, more challenging and better designed.
  But I don&apos;t remember what those games were at all now.  It is only
  this silly game that remains etched in my memory.
&lt;/p&gt;
<!-- ### -->
&lt;p&gt;
  &lt;a href="https://susam.net/five-minutes-of-prime-time.html"&gt;Read on website&lt;/a&gt; |
  &lt;a href=&quot;https://susam.net/tag/miscellaneous.html&quot;&gt;#miscellaneous&lt;/a&gt; |
  &lt;a href=&quot;https://susam.net/tag/story.html&quot;&gt;#story&lt;/a&gt;
&lt;/p&gt;
<!-- END HTML -->
    </content>
  </entry>
  <entry>
    <title>A4 Paper Stories</title>
    <link href="https://susam.net/a4-paper-stories.html"/>
    <id>urn:uuid:06e5304d-c242-481c-bf94-e23b019b0a36</id>
    <updated>2026-01-06T00:00:00Z</updated>
    <content type="html">
<!-- BEGIN HTML -->
&lt;p&gt;
  I sometimes resort to a rather common measuring technique that is
  neither fast, nor accurate, nor recommended by any standards body
  and yet it hasn&apos;t failed me whenever I have had to use it.  I will
  describe it here, though calling it a technique might be overselling
  it.  Please do not use it for installing kitchen cabinets or
  anything that will stare back at you every day for the next ten
  years.  It involves one tool: a sheet of A4 paper.
&lt;/p&gt;
&lt;p&gt;
  Like most sensible people with a reasonable sense of priorities, I
  do not carry a ruler with me wherever I go.  Nevertheless, I often
  find myself needing to measure something at short notice, usually in
  situations where a certain amount of inaccuracy is entirely
  forgivable.  When I cannot easily fetch a ruler, I end up doing what
  many people do and reach for the next best thing, which for me is a
  sheet of A4 paper, available in abundant supply where I live.
&lt;/p&gt;
&lt;p&gt;
  From photocopying night-sky charts to serving as a scratch pad for
  working through mathematical proofs, A4 paper has been a trusted
  companion since my childhood days.  I use it often.  If I am
  carrying a bag, there is almost always some A4 paper inside: perhaps
  a printed research paper or a mathematical problem I have worked on
  recently and need to chew on a bit more during my next train ride.
&lt;/p&gt;
&lt;h2 id=&quot;dimensions&quot;&gt;Dimensions&lt;/h2&gt;
&lt;p&gt;
  The dimensions of A4 paper are the solution to a simple, elegant
  problem.  Imagine designing a sheet of paper such that, when you cut
  it in half parallel to its shorter side, both halves have exactly
  the same aspect ratio as the original.  In other words, if the
  shorter side has length \( x \) and the longer side has length \( y
 , \) then

  \[
    \frac{y}{x} = \frac{x}{y / 2}
  \]

  which gives us

  \[
    \frac{y}{x} = \sqrt{2}.
  \]

  Test it out.  Suppose we have \( y/x = \sqrt{2}.  \)  We cut the
  paper in half parallel to the shorter side to get two halves, each
  with shorter side \( x&apos; = y / 2 = x \sqrt{2} / 2 = x / \sqrt{2} \)
  and longer side \( y&apos; = x.  \)  Then indeed

  \[
    \frac{y&apos;}{x&apos;}
    = \frac{x}{x / \sqrt{2}}
    = \sqrt{2}.
  \]

  In fact, we can keep cutting the halves like this and we&apos;ll keep
  getting even smaller sheets with the aspect ratio \( \sqrt{2} \)
  intact.  To summarise, when a sheet of paper has the aspect ratio \(
  \sqrt{2}, \) bisecting it parallel to the shorter side leaves us
  with two halves that preserve the aspect ratio.  A4 paper has this
  property.
&lt;/p&gt;
&lt;p&gt;
  But what are the exact dimensions of A4 and why is it called A4?
  What does 4 mean here?  Like most good answers, this one too begins
  by considering the numbers \( 0 \) and \( 1.  \)  Let me elaborate.
&lt;/p&gt;
&lt;p&gt;
  Let us say we want to make a sheet of paper that is \( 1 \,
  \mathrm{m}^2 \) in area and has the aspect-ratio-preserving property
  that we just discussed.  What should its dimensions be?  We want

  \[
    xy = 1 \, \mathrm{m}^2
  \]

  subject to the condition

  \[
    \frac{y}{x} = \sqrt{2}.
  \]

  Solving these two equations gives us

  \[
    x^2 = \frac{1}{\sqrt{2}} \, \mathrm{m}^2
  \]

  from which we obtain

  \[
    x = \frac{1}{\sqrt[4]{2}} \, \mathrm{m}, \quad
    y = \sqrt[4]{2} \, \mathrm{m}.
  \]

  Up to three decimal places, this amounts to

  \[
    x = 0.841 \, \mathrm{m}, \quad
    y = 1.189 \, \mathrm{m}.
  \]

  These are the dimensions of A0 paper.  They are precisely the
  dimensions specified by the ISO standard for it.  It is quite large
  to scribble mathematical solutions on, unless your goal is to make a
  spectacle of yourself and cause your friends and family to reassess
  your sanity.  So we need something smaller that allows us to work in
  peace, without inviting commentary or concerns from passersby.  We
  take the A0 paper of size

  \[
    84.1 \, \mathrm{cm} \times 118.9 \, \mathrm{cm}
  \]

  and bisect it to get A1 paper of size

  \[
    59.4 \, \mathrm{cm} \times 84.1 \, \mathrm{cm}.
  \]

  Then we bisect it again to get A2 paper with dimensions

  \[
    42.0 \, \mathrm{cm} \times 59.4 \, \mathrm{cm}.
  \]

  And once again to get A3 paper with dimensions

  \[
    29.7 \, \mathrm{cm} \times 42.0 \, \mathrm{cm}.
  \]

  And then once again to get A4 paper with dimensions

  \[
    21.0 \, \mathrm{cm} \times 29.7 \, \mathrm{cm}.
  \]

  There we have it.  The dimensions of A4 paper.  These numbers are
  etched in my memory like the multiplication table of \( 1.  \)  We
  can keep going further to get A5, A6, etc.  We could, in theory, go
  all the way up to A\( \infty.  \)  Hold on, I think I hear someone
  heckle.  What&apos;s that?  Oh, we can&apos;t go all the way to A\( \infty?  \)
  Something about atoms, was it?  Hmm.  Security!  Where&apos;s security?
  Ah yes, thank you, sir.  Please show this gentleman out, would you?
&lt;/p&gt;
&lt;p&gt;
  Sorry for the interruption, ladies and gentlemen.  Phew!  That
  fellow!  Atoms?  Honestly.  We, the mathematically inclined, are not
  particularly concerned with such trivial limitations.  We drink our
  tea from doughnuts.  We are not going to let the size of atoms
  dictate matters, now are we?
&lt;/p&gt;
&lt;p&gt;
  So I was saying that we can bisect our paper like this and go all
  the way to A\( \infty.  \)  That reminds me.  Last night I was at a
  bar in Hoxton and I saw an infinite number of mathematicians walk
  in.  The first one asked, &quot;Sorry to bother you, but would it be
  possible to have a sheet of A0 paper?  I just need something to
  scribble a few equations on.&quot;  The second one asked, &quot;If you happen
  to have one spare, could I please have an A1 sheet?&quot;  The third one
  said, &quot;An A2 would be perfectly fine for me, thank you.&quot;  Before the
  fourth one could ask, the bartender disappeared into the back for a
  moment and emerged with two sheets of A0 paper and said, &quot;Right.
  That should do it.  Do know your limits and split these between
  yourselves.&quot;
&lt;/p&gt;
&lt;p&gt;
  In general, a sheet of A\( n \) paper has the dimensions

  \[
    2^{-(2n + 1)/4} \, \mathrm{m} \times
    2^{-(2n - 1)/4} \, \mathrm{m}.
  \]

  If we plug in \( n = 4, \) we indeed get the dimensions of A4 paper:

  \[
    0.210 \, \mathrm{m} \times 0.297 \, \mathrm{m}.
  \]
&lt;/p&gt;
&lt;h2 id=&quot;measuring-stuff&quot;&gt;Measuring Stuff&lt;/h2&gt;
&lt;p&gt;
  Let us now return to the business of measuring things.  As I
  mentioned earlier, the dimensions of A4 are lodged firmly into my
  memory.  Getting hold of a sheet of A4 paper is rarely a challenge
  where I live.  I have accumulated a number of A4 paper stories over
  the years.  Let me share a recent one.  I was hanging out with a few
  folks of the nerd variety one afternoon when the conversation
  drifted, as it sometimes does, to a nearby computer monitor that
  happened to be turned off.  At some point, someone confidently
  declared that the screen in front of us was 27 inches.  That sounded
  plausible but we wanted to confirm it.  So I reached for my trusted
  measuring instrument: an A4 sheet of paper.  What followed was
  neither fast, nor especially precise, but it was more than adequate
  for settling the matter at hand.
&lt;/p&gt;
&lt;p&gt;
  I lined up the longer edge of the A4 sheet with the width of the
  monitor.  One length.  Then I repositioned it and measured a second
  length.  The screen was still sticking out slightly at the end.  By
  eye, drawing on an entirely unjustified confidence built from years
  of measuring things that never needed measuring, I estimated the
  remaining bit at about \( 1 \, \mathrm{cm}.  \)  That gives us a
  width of

  \[
    29.7 \, \mathrm{cm} +
    29.7 \, \mathrm{cm} +
     1.0 \, \mathrm{cm}
    =
    60.4 \, \mathrm{cm}.
  \]

  Let us round that down to \( 60 \, \mathrm{cm}.  \)  For the height,
  I switched to the shorter edge.  One full \( 21 \, \mathrm{cm} \)
  fit easily.  For the remainder, I folded the paper parallel to the
  shorter side, producing an A5-sized rectangle with dimensions \(
  14.8 \, \mathrm{cm} \times 21.0 \, \mathrm{cm}.  \)  Using the \(
  14.8 \, \mathrm{cm} \) edge, I discovered that it overshot the top
  of the screen slightly.  Again, by eye, I estimated the excess at
  around \( 2 \, \mathrm{cm}.  \)  That gives us

  \[
    21.0 \, \mathrm{cm} +
    14.8 \, \mathrm{cm}
    -2.0 \, \mathrm{cm}
    =
    33.8 \, \mathrm{cm}.
  \]

  Let us round this up to \( 34 \, \mathrm{cm}.  \)  The ratio \( 60 /
  34 \approx 1.76 \) is quite close to \( 16/9, \) a popular aspect
  ratio of modern displays.  At this point the measurements were
  looking good.  So far, the paper had not embarrassed itself.
  Invoking the wisdom of the Pythagoreans, we can now estimate the
  diagonal as

  \[
    \sqrt{(60 \, \mathrm{cm})^2 + (34 \, \mathrm{cm})^2}
    \approx 68.9 \,\mathrm{cm}.
  \]

  Finally, there is the small matter of units.  One inch is \( 2.54 \,
  \mathrm{cm}, \) another figure that has embedded itself in my head.
  Dividing \( 68.9 \) by \( 2.54 \) gives us roughly \( 27.2 \,
  \mathrm{in}.  \)  So yes.  It was indeed a \( 27 \)-inch display.  My
  elaborate exercise in showing off my A4 paper skills was now
  complete.  Nobody said anything.  A few people looked away in
  silence.  I assumed they were reflecting.  I am sure they were
  impressed deep down.  Or perhaps... no, no.  They were definitely
  impressed.  I am sure.
&lt;/p&gt;
&lt;p&gt;
  Hold on.  I think I hear another heckle.  What is that?  There are
  mobile phone apps that can measure things now?  Really?  Right.
  Security.  Where&apos;s security?
&lt;/p&gt;
<!-- ### -->
&lt;p&gt;
  &lt;a href="https://susam.net/a4-paper-stories.html"&gt;Read on website&lt;/a&gt; |
  &lt;a href=&quot;https://susam.net/tag/absurd.html&quot;&gt;#absurd&lt;/a&gt; |
  &lt;a href=&quot;https://susam.net/tag/mathematics.html&quot;&gt;#mathematics&lt;/a&gt; |
  &lt;a href=&quot;https://susam.net/tag/story.html&quot;&gt;#story&lt;/a&gt;
&lt;/p&gt;
<!-- END HTML -->
    </content>
  </entry>
  <entry>
    <title>Good Blessings</title>
    <link href="https://susam.net/good-blessings.html"/>
    <id>urn:uuid:2a6da1de-269e-4be3-825b-32caea751456</id>
    <updated>2016-12-11T00:00:00Z</updated>
    <content type="html">
<!-- BEGIN HTML -->
&lt;p&gt;
  Back in 2009, I had completed a year working for RSA Security.  I
  was then looking for more intellectually stimulating work where I
  could work on projects involving mathematics and algorithms.  While
  I had talked to senior leaders of the organisation about my
  aspirations, nothing concrete had materialised for several weeks.
  Then something interesting happened.  One fine Monday morning, as I
  walked into the office and began to settle at my desk, the head of
  our research and development division came to my desk looking for
  me.  He said, &quot;Burt is here.  He wants to talk to you.&quot;
&lt;/p&gt;
&lt;p&gt;
  There was no Burt in that office as far as I knew, so I became a
  little confused.  I was led into a conference room where I could
  meet him.  Mildly disoriented, I opened the conference room door.
  Then I saw Burt, the person I was about to meet.  As soon as I saw
  him, I immediately recognised who he was.  He was Dr Burt Kaliski,
  the Chief Scientist of RSA Laboratories.  He had flown in that
  morning to meet certain teams in our office.  During his visit, he
  had carved out some time from his schedule to meet me.
&lt;/p&gt;
&lt;p&gt;
  I had never met or talked to Dr Kaliski before.  But I was very well
  aware of his work and his accomplishments many years before joining
  RSA.  At a previous job, while implementing digital signatures for a
  banking product, I had spent a lot of time reading the RFCs for
  &lt;a href=&quot;https://www.rfc-editor.org/rfc/rfc3447&quot;&gt;PKCS #1&lt;/a&gt;,
  &lt;a href=&quot;https://www.rfc-editor.org/rfc/rfc2898&quot;&gt;PKCS #5&lt;/a&gt; and
  &lt;a href=&quot;https://www.rfc-editor.org/rfc/rfc2315&quot;&gt;PKCS #7&lt;/a&gt;,
  which were all authored by Dr Kaliski.  It was an honour to
  meet the person whose work had taught me a lot and helped me begin
  my career as a software developer in the area of information
  security.
&lt;/p&gt;
&lt;p&gt;
  He began the meeting by explaining that he happened to learn about
  my wish to work on more challenging projects.  He enquired about the
  type of projects I desired to work on.  He listened to my thoughts
  patiently.  He offered some advice and then wished me the best for
  my future.  Little did I know back then that the short 30 minute
  interaction I had with him would end up changing the trajectory of
  my career.
&lt;/p&gt;
&lt;p&gt;
  Soon after the meeting, I followed his advice, talked to several
  teams, found out what they were working on and finally decided to
  join a team that worked on a network security product.  It turned
  out to be the best decision of my career!  While working on that
  product, I learnt to design and implement efficient algorithms for
  petabytes of data.  Some parts of the project relied heavily on
  probability theory, so it was a joy to be able to take a subject
  that was a hobby until then and apply it to solve actual real-world
  problems.  Working on that product offered the intellectual
  challenges that my younger self yearned for back then.  I think the
  most interesting experience there was my work on parser generators.
  It involved writing algorithms in C++ to parse a formally specified
  language which in turn was used to generate in-memory FSMs to parse
  and analyse network packets and events.  Parsing one language and
  generating in-memory parsers for another language proved to be
  intellectually demanding as well as satisfying.  I have fond
  memories of my time there working on parser generators alongside
  remarkably skilled engineers from whom I learnt a lot.
&lt;/p&gt;
&lt;p&gt;
  All of that happened seven years ago.  A couple of months ago, while
  recounting that 30 minute meeting with Dr Kaliski, I could not
  recall if I had ever thanked him properly for his kindness and
  generosity.  Seven years ago, there was no compelling reason for him
  to meet me.  I was then just a regular software engineer who was
  hired into the company a year ago.  We had never talked before.  But
  he took the time to offer me help, suggestions and advice on how I
  could make a good career.  Unsure if I had expressed my gratitude to
  him for how he helped me sculpt my career, I wrote to him recently
  to thank him and explain how that one meeting had a large and
  positive impact on my life.
&lt;/p&gt;
&lt;p&gt;
  Dr Kaliski replied a few days later and he expressed his happiness
  to know that the steps I took in the subsequent years worked out
  well for me.  Before ending his message, he wrote a little
  heart-warming note that I am going to remember forever.  Quoting it
  verbatim here:
&lt;/p&gt;
&lt;blockquote&gt;
  &amp;ldquo;One of my goals is to be able to provide encouragement to
  others who are developing their careers, just as others have
  invested in mine, passing good blessings from one generation to
  another.&amp;rdquo;
&lt;/blockquote&gt;
&lt;!-- Quote from 11 Oct 2016 03:50  UTC --&gt;
&lt;p&gt;
  Thank you, Burt!  I will do likewise.
&lt;/p&gt;
<!-- ### -->
&lt;p&gt;
  &lt;a href="https://susam.net/good-blessings.html"&gt;Read on website&lt;/a&gt; |
  &lt;a href=&quot;https://susam.net/tag/miscellaneous.html&quot;&gt;#miscellaneous&lt;/a&gt; |
  &lt;a href=&quot;https://susam.net/tag/story.html&quot;&gt;#story&lt;/a&gt; |
  &lt;a href=&quot;https://susam.net/tag/quote.html&quot;&gt;#quote&lt;/a&gt;
&lt;/p&gt;
<!-- END HTML -->
    </content>
  </entry>
  <entry>
    <title>A Kid Who Could Read My Mind</title>
    <link href="https://susam.net/a-kid-who-could-read-my-mind.html"/>
    <id>urn:uuid:862a335a-f323-4007-9917-38133f24afc9</id>
    <updated>2009-07-03T00:00:00Z</updated>
    <content type="html">
<!-- BEGIN HTML -->
&lt;p&gt;
  Last night, I found myself in the midst of a peculiar group of
  strangers.  Among them was a mysterious kid who made an astonishing
  claim.  He possessed the ability to read minds.  With utter
  disbelief, I approached him.  He covered both my ears with his palms
  and asked me to think of something.  I thought of the number 5 and
  he immediately said aloud, &apos;5&apos;.  I was astonished.  How could the
  kid read my mind?  To ensure that he did not simply get lucky, I
  thought of another number, 7.  Again, he immediately declared, &apos;7&apos;.
  I thought of a few more numbers and he correctly announced all the
  numbers.  I was completely bewildered.  The people around were
  equally perplexed.  They felt that both of us were working together
  to hoodwink others.  An old man in the group who seemed intrigued by
  all this approached us and asked us to perform more experiments in a
  structured manner.  He proposed that the numbers be generated using
  a pseudorandom number generator of a scientific calculator and
  written down on a paper.  He asked me to silently read the numbers
  on each paper, then think of those numbers and see whether the kid
  could then read my mind.
&lt;/p&gt;
&lt;p&gt;
  While he was preparing a list of random numbers, I was trying to
  understand how on earth the kid could be reading my mind.  He could
  not be have got lucky every single time.  He seemed to have direct
  access to my mind.  However that would be a miracle, maybe not in
  future, but it is a miracle at least today in the year 2009.  I kept
  thinking, coming up with various hypotheses and discarding them.  By
  sheer luck, I thought of a contraption involving one random number
  generator (RNG) connected to two displays.  In this apparatus, the
  output of the RNG appeared immediately on the first display, but
  only after a delay of 1 second on the second display.  Now it would
  seem that the first display was predicting the output of the second
  display.  I continued thinking more in that direction.  What could
  possibly be the source of the thoughts that was accessible to both?
&lt;/p&gt;
&lt;p&gt;
  After a little thought, it occurred to me that it could be my own
  mind.  Probably the kid and the people I could see were simply
  creations of my mind.  Perhaps, I was asleep and dreaming.  I wanted
  to test the hypothesis.  If it was only a dream and my mind was
  creating all the experience, I should have been able to read the
  minds of others.  I had no clue how the experience of reading
  others&apos; minds would feel like but I went ahead to test the
  hypothesis.  I asked another person to be a volunteer.  He agreed.
  I covered his ears with my palms and asked him to think of a number
  and suddenly the number &quot;17&quot; echoed in my mind.  I was thrilled.  I
  asked him whether &quot;17&quot; was the number.  He confirmed that it was
  indeed the number he had thought of.
&lt;/p&gt;
&lt;p&gt;
  Unfortunately, I could not stay in this state of
  &lt;a href=&quot;https://en.wikipedia.org/wiki/Lucid_dream&quot;&gt;lucid dream&lt;/a&gt;
  for long.  I woke up soon after realising that I was in a lucid
  dream.  If you find lucid dreaming intriguing I recommend
  &lt;a href=&quot;https://www.imdb.com/title/tt0243017/&quot;&gt;Waking Life&lt;/a&gt; to
  you, a very thought provoking movie that shows the experience of a
  man trapped in a persistent lucid dream state.
&lt;/p&gt;
<!-- ### -->
&lt;p&gt;
  &lt;a href="https://susam.net/a-kid-who-could-read-my-mind.html"&gt;Read on website&lt;/a&gt; |
  &lt;a href=&quot;https://susam.net/tag/miscellaneous.html&quot;&gt;#miscellaneous&lt;/a&gt; |
  &lt;a href=&quot;https://susam.net/tag/story.html&quot;&gt;#story&lt;/a&gt;
&lt;/p&gt;
<!-- END HTML -->
    </content>
  </entry>
  <entry>
    <title>Combinatorics Coincidence</title>
    <link href="https://susam.net/combinatorics-coincidence.html"/>
    <id>urn:uuid:13dedd05-23b8-4c81-8eff-0109539ba000</id>
    <updated>2008-09-14T00:00:00Z</updated>
    <content type="html">
<!-- BEGIN HTML -->
&lt;h2 id=&quot;combinatorics-for-fun&quot;&gt;Combinatorics for Fun&lt;/h2&gt;
&lt;p&gt;
  At my current workplace, there are several engineers who have an
  affinity for combinatorics.  As a result, discussions about
  combinatorics problems often occur at the cafeteria.  Probability
  theory is another popular topic of discussion.  Of course, often
  combinatorics and probability theory go hand in hand.
&lt;/p&gt;
&lt;h2 id=&quot;recurrence-relation&quot;&gt;Recurrence Relation&lt;/h2&gt;
&lt;p&gt;
  At the cafeteria one day, I joined in on a conversation about
  combinatorics problems.  During the conversation, I happened to
  share the following problem:
&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;
  &lt;p&gt;
    For integers \( n \ge 1 \) and \( k \ge 1, \)

    \[
      f_k(n) =
      \begin{cases}
        n                       &amp;amp; \text{if } k = 1, \\
        \sum_{i=1}^n f_{k-1}(i) &amp;amp; \text{if } k \ge 2.
      \end{cases}
    \]

    Find a closed-form expression for \( f_k(n).  \)
  &lt;/p&gt;
&lt;/div&gt;
&lt;h2 id=&quot;nested-loops&quot;&gt;Nested Loops&lt;/h2&gt;
&lt;p&gt;
  Soon after I shared the above problem, a colleague of mine shared
  this problem with me:
&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;
  &lt;p&gt;
    Consider the following pseudocode with &lt;code&gt;k&lt;/code&gt; nested
    loops:
  &lt;/p&gt;
&lt;pre&gt;&lt;code&gt;x = 0
for c&lt;sub&gt;1&lt;/sub&gt; in 0 to (n - 1):
    for c&lt;sub&gt;2&lt;/sub&gt; in 0 to (c&lt;sub&gt;1&lt;/sub&gt; - 1):
        ...
            for c&lt;sub&gt;k&lt;/sub&gt; in 0 to (c&lt;sub&gt;k-1&lt;/sub&gt; - 1):
                x = x + 1&lt;/code&gt;&lt;/pre&gt;
  &lt;p&gt;
    What is the final value of &lt;code&gt;x&lt;/code&gt; after the outermost loop
    terminates?
  &lt;/p&gt;
&lt;/div&gt;
&lt;h2 id=&quot;coincidence&quot;&gt;Coincidence&lt;/h2&gt;
&lt;p&gt;
  With one problem each, we went back to our desks.  As I began
  solving the &lt;em&gt;nested loops&lt;/em&gt; problem shared by my colleague, I
  realised that the solution to his problem led me to
  the &lt;em&gt;recurrence relation&lt;/em&gt; in the problem I shared with him.
&lt;/p&gt;
&lt;p&gt;
  In the &lt;em&gt;nested loops&lt;/em&gt; problem, if \( k = 1, \) the final
  value of \( x \) after the loop terminates is \( x = n.  \)  This is
  also the value of \( f_1(n).  \)
&lt;/p&gt;
&lt;p&gt;
  If \( k = 2, \) the inner loop with counter \( c_2 \) runs once when
  \( c_1 = 0, \) twice when \( c_1 = 1 \) and so on.  When the loop
  terminates, \( x = 1 + 2 + \dots + n.  \)  Note that this series is
  same as \( f_2(n) = f_1(1) + f_1(2) + \dots + f_1(n).  \)
&lt;/p&gt;
&lt;p&gt;
  Extending this argument, we now see that for any \( k \ge 1, \) the
  final value of \( x \) is

  \[
    f_k(n) = f_{k-1}(1) + f_{k-1}(2) + \dots + f_{k-1}(n).
  \]

  In other words, the solution to his &lt;em&gt;nested loops&lt;/em&gt; problem is
  the solution to my &lt;em&gt;recurrence relation&lt;/em&gt; problem.  It was an
  interesting coincidence that the problems we shared with each other
  had the same solution.
&lt;/p&gt;
&lt;h2 id=&quot;closed-form-expression&quot;&gt;Closed-Form Expression&lt;/h2&gt;
&lt;p&gt;
  The closed form expression for the recurrence relation is

  \[
    f_k(n) = \binom{n + k - 1}{k}.
  \]

  It is quite easy to prove this using the principle of mathematical
  induction.  Since we know that this is also the result of
  the &lt;em&gt;nested loops&lt;/em&gt; problem, we can also arrive at this result
  by another way.
&lt;/p&gt;
&lt;p&gt;
  In the &lt;em&gt;nested loops&lt;/em&gt; problem, the following inequalities are
  always met due to the loop conditions:

  \[
    n - 1 \ge c_1 \ge c_2 \ge \dots \ge c_k \ge 0.
  \]

  The variables \( c_1, c_2, \dots, c_k \) take all possible
  arrangements of integer values that satisfy the above inequalities.
  If we find out how many such arrangements are there, we will know
  how many times the variable \( x \) is incremented.
&lt;/p&gt;
&lt;p&gt;
  Let us consider \( n - 1 \) similar balls and \( k \) similar
  sticks.  For every possible permutation of these balls and sticks,
  if we count the number of balls to the right of the \( i \)th stick
  where \( 1 \le i \le k, \) we get a number that the variable \( c_i \)
  holds in some iteration of the \( i \)th loop.  Therefore the
  variable \( c_i \) is represented as the number of balls lying on
  the right side of the \( i \)th stick.
&lt;/p&gt;
&lt;p&gt;
  The above argument holds good because the number of balls on the
  right side of the first stick does not exceed \( n - 1, \) the
  number of balls on the right side of the second stick does not
  exceed the number of balls on the right side of the first stick and
  so on.  Thus the inequalities mentioned earlier are always
  satisfied.  Also, any set of valid values for \( c_1, c_2, \dots,
  c_k \) can be represented as an arrangement of these sticks and
  balls.
&lt;/p&gt;
&lt;p&gt;
  The number of permutations of \( n - 1 \) similar balls and \( k \)
  similar sticks is

  \[
    \frac{(n + k - 1)!}{(n - 1)! \, k!} = \binom{n + k - 1}{k}.
  \]

  This closed-form expression is the solution to both the
  &lt;em&gt;recurrence relation&lt;/em&gt; problem and the &lt;em&gt;nested loops&lt;/em&gt;
  problem.
&lt;/p&gt;
<!-- ### -->
&lt;p&gt;
  &lt;a href="https://susam.net/combinatorics-coincidence.html"&gt;Read on website&lt;/a&gt; |
  &lt;a href=&quot;https://susam.net/tag/mathematics.html&quot;&gt;#mathematics&lt;/a&gt; |
  &lt;a href=&quot;https://susam.net/tag/combinatorics.html&quot;&gt;#combinatorics&lt;/a&gt; |
  &lt;a href=&quot;https://susam.net/tag/puzzle.html&quot;&gt;#puzzle&lt;/a&gt; |
  &lt;a href=&quot;https://susam.net/tag/story.html&quot;&gt;#story&lt;/a&gt;
&lt;/p&gt;
<!-- END HTML -->
    </content>
  </entry>
  <entry>
    <title>Very Remote Debugging</title>
    <link href="https://susam.net/very-remote-debugging.html"/>
    <id>urn:uuid:fa816a6c-92cc-42a0-8335-c21b4948e229</id>
    <updated>2007-09-03T00:00:00Z</updated>
    <content type="html">
<!-- BEGIN HTML -->
&lt;p&gt;
  There is a wonderful story about a legendary Lisp debugging story in
  the &lt;a href=&quot;https://gigamonkeys.com/book/lather-rinse-repeat-a-tour-of-the-repl.html&quot;&gt;second
  chapter&lt;/a&gt; of the book &lt;em&gt;Practical Common Lisp&lt;/em&gt; by Peter
  Seibel.  Quoting the story here:
&lt;/p&gt;
&lt;blockquote&gt;
  &lt;p&gt;
    An even more impressive instance of remote debugging occurred on
    NASA&apos;s 1998 Deep Space 1 mission.  A half year after the space
    craft launched, a bit of Lisp code was going to control the
    spacecraft for two days while conducting a sequence of
    experiments.  Unfortunately, a subtle race condition in the code
    had escaped detection during ground testing and was already in
    space.  When the bug manifested in the wild--100 million miles
    away from Earth--the team was able to diagnose and fix the running
    code, allowing the experiments to complete.  One of the
    programmers described it as follows:
  &lt;/p&gt;
  &lt;blockquote&gt;
    &lt;p&gt;
      Debugging a program running on a $100M piece of hardware that is
      100 million miles away is an interesting experience.  Having a
      read-eval-print loop running on the spacecraft proved invaluable
      in finding and fixing the problem.
    &lt;/p&gt;
  &lt;/blockquote&gt;
&lt;/blockquote&gt;
&lt;p&gt;
  The original source of this story is an article
  called &lt;a href=&quot;https://flownet.com/gat/jpl-lisp.html&quot;&gt;Lisping at
  JPL&lt;/a&gt; written by Ron Garret in 2002.  This story occurs in the
  section called &lt;em&gt;1994-1999 - Remote Agent&lt;/em&gt; of the article.
&lt;/p&gt;
<!-- ### -->
&lt;p&gt;
  &lt;a href="https://susam.net/very-remote-debugging.html"&gt;Read on website&lt;/a&gt; |
  &lt;a href=&quot;https://susam.net/tag/lisp.html&quot;&gt;#lisp&lt;/a&gt; |
  &lt;a href=&quot;https://susam.net/tag/programming.html&quot;&gt;#programming&lt;/a&gt; |
  &lt;a href=&quot;https://susam.net/tag/technology.html&quot;&gt;#technology&lt;/a&gt; |
  &lt;a href=&quot;https://susam.net/tag/story.html&quot;&gt;#story&lt;/a&gt; |
  &lt;a href=&quot;https://susam.net/tag/quote.html&quot;&gt;#quote&lt;/a&gt;
&lt;/p&gt;
<!-- END HTML -->
    </content>
  </entry>
</feed>
