// Arup Guha
// 11/14/2023
// Code to double check original hash function locations for Exam 2.

#include <stdio.h>

// Adds digits of value and returns the result mod n.
int hashfunction(int value, int n) {
    int res = 0;
    while (value > 0) {
        res = (res + value%10)%n;
        value = value/10;
    }
    return res;
}

// Multiplies digits of value and returns the result mod n.
int hashfunction2(int value, int n) {
    int res = 1;
    while (value > 0) {
        res = (res * (value%10))%n;
        value = value/10;
    }
    return res;
}


int main() {

    // Try out section 1 code.
    int vals[9] = {47312, 86297, 123456, 676, 11112335, 567, 999999, 887, 23642};
    for (int i=0; i<9; i++)
        printf("%d\n", hashfunction(vals[i], 13));
    printf("\n\n");

    // Try out section 2 code.
    int vals2[9] = {234, 69, 34, 525, 72, 2323, 33, 117511,  22222};
    for (int i=0; i<9; i++)
        printf("%d\n", hashfunction2(vals2[i], 13));
    return 0;
}
