Last active
April 12, 2019 21:03
-
-
Save donjajo/6d52c09717d250c338b8e425eed9bd8f to your computer and use it in GitHub Desktop.
Revisions
-
donjajo revised this gist
Apr 12, 2019 . No changes.There are no files selected for viewing
-
donjajo revised this gist
Apr 12, 2019 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -7,7 +7,6 @@ void main() { int numbers[] = { 1, 2, 2, 4, 4, 1, 5, 6, 5 }; int length = sizeof( numbers ) / sizeof( numbers[ 0 ] ); int lucky = 0; for( int i = 0; i < length; i++ ) { int *n_a = pop_array( i, numbers, length ); -
donjajo revised this gist
Apr 12, 2019 . 1 changed file with 20 additions and 14 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4,20 +4,20 @@ _Bool in_array(); int *pop_array(); void main() { int numbers[] = { 1, 2, 2, 4, 4, 1, 5, 6, 5 }; int length = sizeof( numbers ) / sizeof( numbers[ 0 ] ); int lucky = 0; int *n_a = pop_array( 1, numbers, length ); for( int i = 0; i < length; i++ ) { int *n_a = pop_array( i, numbers, length ); if( !in_array( numbers[ i ], n_a, (length-1) ) ) { lucky = numbers[ i ]; } free( n_a ); } printf( "Lucky number is %d", lucky ); } @@ -33,13 +33,19 @@ _Bool in_array( int value, int *a, int length ) { } int *pop_array( int index, int a[], int length ) { int *new_array = malloc( sizeof( int ) * (length ) ); int i = 0; int p_i = 0; while( i < length ) { if( i == index ) { *(new_array+i) = a[i+1]; i++; continue; } *(new_array+p_i) = a[i]; i++; p_i++; } return new_array; -
donjajo revised this gist
Apr 11, 2019 . 1 changed file with 37 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,11 +1,46 @@ #include <stdio.h> #include <stdlib.h> _Bool in_array(); int *pop_array(); void main() { int numbers[] = { 1, 2, 2, 4, 4, 1, 5 }; int length = sizeof( numbers ) / sizeof( numbers[ 0 ] ); int lucky = 0; for( int i = 0; i <= length; i++ ) { int *n_a = pop_array( i, numbers, length ); // printf( "Item: %d in array: %d\n", numbers[ i ], in_array( numbers[ i ], n_a, length ) ); // if( !in_array( numbers[ i ], n_a, length ) ) { // lucky = numbers[ i ]; // } // free( n_a ); } printf( "Lucky number is %d", lucky ); } _Bool in_array( int value, int *a, int length ) { for( int i = 0; i < length; i++ ) { if( value == *( a+i ) ) return 1; } return 0; } int *pop_array( int index, int a[], int length ) { int *new_array = ( int *) malloc( sizeof( int ) * length ); for( int i = 0; i < length; i++ ) { printf( "%d,%d\n", i,a[i] ); if( i == index ) continue; *(new_array+i) = a[i]; } return new_array; } -
donjajo created this gist
Apr 11, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,11 @@ int *pop_array( int index, int a[], int length ) { int *new_array = malloc( sizeof( int ) * length ); for( int i = 0; i < length; i++ ) { if( i == index ) continue; *(new_array+i) = a[i]; } return new_array; }