Skip to content

Instantly share code, notes, and snippets.

Created June 29, 2012 15:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/482b474ebb329e53881e to your computer and use it in GitHub Desktop.
Save anonymous/482b474ebb329e53881e to your computer and use it in GitHub Desktop.
1)
23=0x17
23=027
2)
/* C code */
void fizzbuzz()
{
int i = 1;
while ( i <= 100 )
{
if ( i % 15 == 0 ) puts( "fizzbuzz" );
else if ( i % 3 == 0 ) puts( "fizz" );
else if ( i % 5 == 0 ) puts( "buzz" );
else printf( "%i\n", i );
i++;
}
}
3)
1. match numbers in scientific notation
2. match beginning of a line
3. match either "+" or "-", if it is there. if it is not, still try to match
4. match "e" or "E", that may or may not be followed by either "+" or "-" and
one or more decimal numerals
5. the questionmark denotes an optional match, prefering to match
4)
/* FindSource
find all directory entries of a directory, whose name consists of the string,
which is given in the argument base, followed by a string from a predefined list
for the filenamesuffix. entries, that are deeper in the list of suffixes, take
precedence over others.
*/
String FindSource( String base, String dir )
{
DIR * dirp = opendir( dir ); // open a directory handler
String result; // tmp pointer to the structure to return
for ( int i = NS-1; i >= 0; --i ) // iterate list of suffixes, top2bottom
{
String tmp = base + suffix[i]; // build a filename from base and
// one of the listentries
//iterate over the entries in the directory
for ( dirent *de = readdir( dirp ); de != NULL; de = readdir( dirp ) )
{
if ( tmp == de->d_name ) // when we have a match, return it
{
result = tmp;
break;
}
}
if (result) break; // we have a match, return it
rewinddir( dirp ); // reset the directory entry pointer
}
closedir( dirp ); // close the directory handler
return result;
}
5)
unsigned fac_sub(unsigned n, unsigned res)
{
if ( n != 1 )
{ if ( res < ( res = n * res ) )
{
fprintf(stderr, "carry detected");
return 0;
}
res = faculty( --n, res );
}
return res;
}
unsigned fac( unsigned n )
{
if ( n ) return fac_sub( n, 1 );
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment