1         C/C++ Programs Developed by Joe Churchwell

1.1      Ethernet Package

This is a C++ program, I developed personally, used to test out methods to communicate using Ethernet to a client device. It defines an “EtherServer” class and creates an instantiation of the class in the main function.

Code Files

epackage.h

Generic header file for the project

EtherServer.h

Header file that defines the EtherServer class object

EtherServer.cpp

Code file that implements the functions defined in the EtherServer header

EthernetPackage.cpp

Main code file

 

1.2      Buddy Share

Here is a simple C program used to calculate the detour distance between two different points. This will give you a general idea regarding my coding style.

Problem Statement: Given four latitude / longitude pairs, where driver one is traveling from point A to point B and driver two is traveling from point C to D, write a function to calculate the shorter of the detour distances the drivers would need to take to pick up and drop off the other driver. This simple implementation does not take streets into consideration.

Code Files

buddyshare.h

Header file to support main.c

main.c

File with main function and support functions

 

1.3      All Lotto Number Combinations

Program created to generate all Mega Millions or Power Ball lottery numbers. I created this because I saw a website that actually charged for all the generated numbers and that is not something to charge for since it is really easy to generate them yourself. This is a brute force implementation that actually finds all possible combinations fast (<100 ms) on a modern computer. However, it would take a lot longer to store all the generated numbers to disk.

Code Files

all_lotto_numbers.cpp

Main file to calculate all possible lottery number combinations

 

1.4      N Coins

The following program was created find the smallest positive integer n such that it is not possible to use exactly n US coins to make exactly one dollar. I was also able to verify this solution using Excel’s solver tool with some clever VBA scripting. Oh, and I am really good at VBA especially for Excel.

Code Files

n_coins.c

Main file for n_coins and its support functions

 

1.5      Alien User Name

This is a c program to determine a valid alien user name (ref: https://www.hackerrank.com/challenges/alien-username)

This is code which does not use regex.

Code Files

alien_user_name.c

Main file that includes main and support functions

 

1.6      Hacker Rank “Pairs” Problem

This is a hash table solution for the “Pairs” programming problem on HackerRank.com. Too bad the website doesn’t take time (complexity) into account for ranking hackers. ;-)

(ref: https://www.hackerrank.com/challenges/pairs)

 

#include <stdio.h>

#include <string.h>

#include <math.h>

#include <stdlib.h>

#include <assert.h>

 

#define MAX_INT (2147483648 / 8)

 

// Bit operation functions

void SetBit( char * A,  int k ){ A[k/8] |= 1 << (k%8);}

int TestBit( char * A,  int k ){ return ( (A[k/8] & (1 << (k%8) )) != 0 ) ;}  

 

int main() {

    int res = 0;

    int _a_size;

    register int _a_i;

    int _k;

    int _a_item;

    unsigned char *hashmap;

       

    // Allocate just enough memory to cover everything in the constraints

    hashmap = (char *)malloc(MAX_INT); 

    //memset(hashmap, 0, MAX_INT); // Make sure the values are zero to start with

       

    scanf("%d %d", &_a_size,&_k);

    int _a[_a_size];

    for(_a_i = 0; _a_i < _a_size; _a_i++) {        

        scanf("%d", &_a_item);       

        _a[_a_i] = _a_item;

        SetBit(hashmap, _a_item);

        if(_a_item <= _k){// The difference will be below or equal to 0

            if(TestBit(hashmap, _a_item+_k)) res++; // Only check the upper part

        }else if(_a_item >= MAX_INT-_k){ // The difference will be above the max value

            if(TestBit(hashmap, _a_item-_k)) res++; // Only check the lower part       

        }else{ // Check lower and upper bounds

            if(TestBit(hashmap, _a_item-_k)) res++; 

            if(TestBit(hashmap, _a_item+_k)) res++;

        }                            

    }

   printf("%d\n",res); 

   free(hashmap); // Clean up and clear out the memory

   return 0;

}