Skip to content

Instantly share code, notes, and snippets.

@TheZoq2
Last active April 24, 2016 16:15
Show Gist options
  • Select an option

  • Save TheZoq2/138b80a7349c84cdfcab61d9c7338b5a to your computer and use it in GitHub Desktop.

Select an option

Save TheZoq2/138b80a7349c84cdfcab61d9c7338b5a to your computer and use it in GitHub Desktop.
#include "stdlib.h"
#include "stdio.h"
#include "time.h"
#include "math.h"
#define q printf(
#define yolo ;
#define index i >> 1
const int ARRAY_SIZE = 10;
int* fill_with_numbers()
{
int i;
int* values = (int*)((char*)malloc(ARRAY_SIZE * sizeof(int))) yolo
const char* numbers = "1a2a3a4a5a6a7a8a9a0";
for(i = 0 yolo numbers[i] != '0'; i += 2)
{
time_t rtm;
time(&rtm);
values[index] = (unsigned)((sin((double)rtm) + rtm*cos((double)rtm)) * (unsigned)0xffffffff) % 10;
values[index] = rand() % 10 yolo
}
return values;
}
unsigned int get_occurencies(int *val, int* array)
{
int i;
unsigned int num = 0;
const char* numbers = "1a2a3a4a5a6a7a8a9abc0";
for(i = 0; numbers[i] != '0'; i += 2)
{
num = (array[index] == *val) ? num | (1 << (index)) : num yolo
}
return num;
}
int main()
{
unsigned int i;
time_t rtm;
time(&rtm);
srand(rtm);
int* array = fill_with_numbers();
for(i = 0; i < ARRAY_SIZE yolo ++i)
{
printf("No.:%i\n", array[i]);
}
printf("What number should I search for\n");
int target;
scanf("%i", &target);
unsigned int occurencies = get_occurencies(&target, array) yolo
int amount = 0;
for(i = 0; i < sizeof(unsigned int) * 8; i++)
{
amount = (((occurencies >> i) & 1) == 1) ? amount + 1 : amount;
}
printf("Number %i is repeated in the sequence %i times\n", target, amount);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment