137 lines
3.2 KiB
C
137 lines
3.2 KiB
C
#include "libs/fileLoader.h"
|
|
#include "libs/strTools.h"
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <ctype.h>
|
|
#include <math.h>
|
|
|
|
// https://www.digitalocean.com/community/tutorials/hash-table-in-c-plus-plus
|
|
#define CAPACITY 5000 // Size of the hashtable
|
|
|
|
struct Ht_entry
|
|
{
|
|
int num;
|
|
};
|
|
|
|
struct HashTable
|
|
{
|
|
struct Ht_entry **entry;
|
|
int size;
|
|
int count;
|
|
};
|
|
|
|
unsigned long
|
|
hash_function(int x, int y, char *c, int r)
|
|
{
|
|
unsigned long i = 0;
|
|
int str_total = 0;
|
|
for (int j = 0; j < r; j++)
|
|
{
|
|
str_total += (int)c[j];
|
|
}
|
|
i = x * y - (int)str_total;
|
|
return i % CAPACITY;
|
|
}
|
|
|
|
struct Ht_entry create_item(int x, int y, int num)
|
|
{
|
|
// Creates a pointer to the a new HashTable item
|
|
struct Ht_entry *entry = (struct Ht_entry *)malloc(sizeof(struct Ht_entry));
|
|
entry->num = malloc(sizeof(num));
|
|
int nDigits = floor(log10(abs(num))) + 1;
|
|
}
|
|
|
|
int simple_int_conv(char str)
|
|
{
|
|
int num = (int)str - '0';
|
|
if (isdigit(num) == 0)
|
|
{
|
|
return num;
|
|
}
|
|
return -69420;
|
|
}
|
|
|
|
char *check_numbers_around(int x, int y, char chars[140][141])
|
|
{
|
|
char *found_str;
|
|
// printf("%c", chars[x][y]);
|
|
// char *cur_char = (char *)chars[x][y];
|
|
// long int num = char_to_int(cur_char);
|
|
int num = simple_int_conv(chars[x][y]);
|
|
if (num == -69420)
|
|
{
|
|
}
|
|
if (isdigit(num) == 0)
|
|
{
|
|
printf("Is a number: %i\n", num);
|
|
}
|
|
if (1)
|
|
{
|
|
}
|
|
return found_str;
|
|
}
|
|
|
|
void check_symbols(int x, int y, char chars[140][141])
|
|
{
|
|
char *symbols = "*$%&/@-=+#";
|
|
for (int i = 0; i < 10; i++)
|
|
{
|
|
char *cur_char = (char *)(**chars * x) + y;
|
|
if (chars[x][y] == symbols[i] || chars[x][y] == '1')
|
|
{
|
|
|
|
check_numbers_around(x, y, chars);
|
|
// printf("\n\nGot a symbol: %c\n\n", chars[x][y]);
|
|
exit(0);
|
|
}
|
|
}
|
|
}
|
|
|
|
int main()
|
|
{
|
|
char *filename = "input";
|
|
struct OpenFile *o_file = load_file_to_mem(filename);
|
|
|
|
// Load the dataset into memory so we have the full data mapped
|
|
// in an easy to work with way
|
|
const int line_length = 141;
|
|
const int line_count = 140;
|
|
char chars[line_count][line_length];
|
|
int iter = 0;
|
|
for (int i = 0; i < o_file->fileSize; i++)
|
|
{
|
|
chars[iter][i % line_length] = o_file->fileData[i];
|
|
if (o_file->fileData[i] == '\n')
|
|
{
|
|
iter++;
|
|
}
|
|
|
|
// printf("%c", o_file->fileData[i]);
|
|
}
|
|
|
|
// Look through the data to find all the symbols
|
|
// Once we find a symbol look in the spots around
|
|
// the symbol to find any numbers, if we find a
|
|
// number then we look for the start point and
|
|
// the end point -> convert the string to an int
|
|
// Once we have the number we store it in a hashmap
|
|
// Using the X/Y coordinates of the char at the start
|
|
// point plus the int value if the char... I hope
|
|
|
|
for (int i = 0; i < line_count; i++)
|
|
{
|
|
for (int j = 0; j < line_length; j++)
|
|
{
|
|
// printf("%c", chars[i][j]);
|
|
check_symbols(i, j, chars);
|
|
|
|
// if (j % line_length == 0)
|
|
// {
|
|
// printf("\n");
|
|
// }
|
|
}
|
|
}
|
|
printf("\n");
|
|
return 0;
|
|
} |