🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c.moderated
Article #1993

Re: Good C Interview questions?

#1993
From: Sean 'Captain Napalm' Conner
Date: Thu, 15 Feb 1996 15:34
56 lines
2482 bytes
In article <4fsv3k$2vv@solutions.solon.com> miker3@ix.netcom.com (Mike Rubenstein) writes:
:sthuang@hns.com (Steven Huang) wrote:
:
:: It also *seems* that if a programmer was given a debugger early on, it
:: affects ability in some way I cannot define.  It *seems* to me that they
:: think less of a problem before starting to code.  For example, I gave a
:: CS sophomore class a dumb classic problem of encryption (Vernier, if I
:: remember correctly - I probably don't).
:: 
:: Picture a table like the following:
:: 
::   A B C D E F G ... Z
:: A A B C D E F G ... Z
:: B B C D E F G H ... A
:: C C D E F G H I ... B
:: : : : : : : : : ::: :
:: Z Z A B C D E F ... Y
:: 
:: The students were supposed to match each character in a plaintext string
:: with each character in a key string to produce the ciphertext, as an
:: exercise to string handling.  Of 21 students, none realized that the
:: table can be computed.  Many actually typed in the lookup table, one
:: even read it from a file.  I tend to blame this phenomenon on TV and
:: debuggers ;)
:
:I wonder how many students could compute this table correctly.  It's
:fairly difficult if one restricts oneself to standard C and makes no
:assumptions about the character set other than those demanded by the
:standard.
:
  What's difficult about it?

#include <ctype.h>
#include <string.h>
#include <assert.h>

char lookup(char m,char k)
{
  char *upmap = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  int   midx;
  int   kidx;

  assert(isupper(m));	/* assuming we control the horizontal,	*/
  assert(isupper(k));	/* we control the vertical		*/

  midx = (int)(strchr(upmap,m) - upmap);
  kidx = (int)(strchr(upmap,k) - upmap);

  assert((midx > -1) && (midx < 26));	/* being paranoid, should be true */
  assert((kidx > -1) && (kidx < 26));

  return (upmap [ (midx + kidx) % 26 ]);
}
  
  -spc ("Okay class, let's see how well you fare on an EBCIDIC system.
	 Muahahahahahahahahahaha!")
Technical Details
Message-ID: <4fvjqf$eo0@solutions.solon.com>
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail
References: <4fjnch$oqq@solutions.solon.com> <4fp1ks$h6r@solutions.solon.com> <4fsv3k$2vv@solutions.solon.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail
From: spc@gate.net (Sean 'Captain Napalm' Conner)
Newsgroups: comp.lang.c.moderated
Subject: Re: Good C Interview questions?
Date: 15 Feb 1996 09:34:39 -0600
Organization: CyberGate, Inc.
Sender: clc@solutions.solon.com
Approved: clc@solutions.solon.com
Message-ID: <4fvjqf$eo0@solutions.solon.com>
References: <4fjnch$oqq@solutions.solon.com> <4fp1ks$h6r@solutions.solon.com> <4fsv3k$2vv@solutions.solon.com>
NNTP-Posting-Host: solutions.solon.com