From d9b05de8b76e6189f91385f9a59ff958dba53d0f Mon Sep 17 00:00:00 2001 From: Daniel Olsen Date: Tue, 24 Nov 2020 23:16:49 +0100 Subject: [PATCH] start case3 --- Commissions/flis/IMT/Case3/.envrc | 1 + Commissions/flis/IMT/Case3/case3 | Bin 0 -> 18736 bytes Commissions/flis/IMT/Case3/case3.c | 80 +++++++++++++++++++++++++++ Commissions/flis/IMT/Case3/shell.nix | 5 ++ 4 files changed, 86 insertions(+) create mode 100644 Commissions/flis/IMT/Case3/.envrc create mode 100755 Commissions/flis/IMT/Case3/case3 create mode 100644 Commissions/flis/IMT/Case3/case3.c create mode 100644 Commissions/flis/IMT/Case3/shell.nix diff --git a/Commissions/flis/IMT/Case3/.envrc b/Commissions/flis/IMT/Case3/.envrc new file mode 100644 index 0000000..17d6464 --- /dev/null +++ b/Commissions/flis/IMT/Case3/.envrc @@ -0,0 +1 @@ +use_nix \ No newline at end of file diff --git a/Commissions/flis/IMT/Case3/case3 b/Commissions/flis/IMT/Case3/case3 new file mode 100755 index 0000000000000000000000000000000000000000..9d7d7a1eaa5c80b62e15d3ae38172094af5577b2 GIT binary patch literal 18736 zcmeHPZ)_aLb)UVXB+8VICrYtsD~`@KRm(~5_*XP3S<)W=NK1#3Sxa)9#?JZvEbq>| z+dJJKiee2{4lPHF!jwQ!R3BQvMZf4n0vJINBt>9Twk#P1+{(>|s)*gHMT}5YohWT; z2zBl2@6FER?JbW%(;^=V+yiglyx+X{X6Ehe?#%2Ce}8oRkVn%5lSdp7BGD5+%O*GYn`OZE;`2*jNAR>}*=Y#{==olty9RgAgQj;eAl zXse&wZ`(1ypxXV4;%rAE*Lfd8~4d;lu}} z1f>n7U<7oj$^20%3BjE0eg}3c)Jo%5GYDdnDS#h!hmH7=O#O!AjHD#8BYp121a82OaQ+eYKc$0E zY^$UE@EUmc8hHB}_|Y}+EGip7o|^^$)T>X+8n~dCQ)v4|B$6+rt}cjA@B%G?U52NzJOUB6nn3C`Gc-v?UIYj|~k+dP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AV0m5B23PkV+Mn&T4=DS9 zvd^=j;tFQ>;zgG|j}sP^Vz=rC?1t@Grg68ke4ck*rWGR)ud~|H>iRDrgX}r}7ffRbdbCJ?;sC*W8^hJ zYCJFG|7YRWXPNmAV1rrdiapOC7qKUWi1lo#Dl`5TGN|wHY2tY%|GyCazaZSd*pAQR zU&EG~$o4!Ry+{jaAiBPs#P-a8giNQs&~;nA%Vq(atsJ>r2L2ui^2O!zxHF*axg6Ga zoeuF2$RJFqvzlQ02UZX}!S>953YgPQ)d}VBniE9Y?~*@)T+cp0H)ascC!OTh#R6bm z`@dE8S*J15ZhQY4_6K`x!!ehEOBA0~_U`zd>$UCUE&~>sKcwtk)fBg}yi0UO9;*j; z{K(JBwO>^ec{O3UtvYT1dDJBC4}AZn`wRCSBvVM!Wpce)aSIYI6`6JFpslgT JW#AIUe*=IHsT}|S literal 0 HcmV?d00001 diff --git a/Commissions/flis/IMT/Case3/case3.c b/Commissions/flis/IMT/Case3/case3.c new file mode 100644 index 0000000..bc5f736 --- /dev/null +++ b/Commissions/flis/IMT/Case3/case3.c @@ -0,0 +1,80 @@ +#include +#include +#include +#include + + +struct Node { + struct Node* children[10]; + bool isEnd; +}; + +struct Node* newNode(void) { + struct Node *nNode = NULL; + nNode = (struct Node *) malloc(sizeof(struct Node)); + if (nNode) { + nNode->isEnd = false; + for (int i = 0; i < 10; i++) { + nNode->children[i] = NULL; + } + } + return nNode; +} + +int numbers[] = {113, 11354, 77777, 255044}; + +int main(void) { + struct Node* root = newNode(); + printf("%p\n", root); + + int n_numbers = sizeof(numbers)/sizeof(int); + + for (int i = 0; i < n_numbers; i++) { // Go through all the phone numbers in the global list + struct Node* pointer = root; // Create a pointer that points to whatever part of the trie we're working on + char number[9]; // A number has 8 + \0 chars + snprintf(number, 9, "%i", numbers[i]); // Convert int to string + int len_number = strlen(number); + for (int j = 0; j < len_number - 1; j++) { // loop over chars in the phone number + if (j == len_number - 1) { // if we are at the last iteration + if (pointer->isEnd == true) { // Check if we've seen the number before + printf("Duplicate Number found at element %i, number %s", i, number); + break; + } + else { // if we're at the last iteration, and isEnd isnt true, its either a new number OR we found a prefix + bool continues = false; + for (int k = 0; k < 10; k++) { + if( pointer->children[k] != NULL) { + continues = true; + }; + }; + if (continues == true) { + printf("FOUND PREFIX IN NUMBER\n"); + printf("%s and %s", number, number); + while (pointer->isEnd != true) { // follow the first paths you can find + for (int k = 0; k < 10; k++) { + if( pointer->children[k] != NULL) { + pointer = pointer->children[k]; + printf("%c", k + '0'); + break; + }; + }; + }; + printf("\n"); + return 0; + }; + }; + pointer->isEnd = true; + } + else if (pointer->isEnd == true) { // if we've already seen a shorter number with this prefix + printf("Found prefix!"); + for (int k = 0; k < j; k++) { + printf("%c", number[k]); + } + printf("\n"); + }; + int index = number[j+1] - '0'; + pointer->children[index] = newNode(); + pointer = pointer->children[index]; + }; + }; +} \ No newline at end of file diff --git a/Commissions/flis/IMT/Case3/shell.nix b/Commissions/flis/IMT/Case3/shell.nix new file mode 100644 index 0000000..d364c29 --- /dev/null +++ b/Commissions/flis/IMT/Case3/shell.nix @@ -0,0 +1,5 @@ +with import {}; +stdenv.mkDerivation { + name = "c-shell"; + buildInputs = [ gcc gnumake ]; +}