-
Posts
29 -
Joined
-
Last visited
GreyHat64's Achievements
-
Vessel Username: GreyHat64 Videos: https://www.vessel.com/videos/LCoY5zfFf https://www.vessel.com/videos/JYZEYDYx0
-
If I won, I'd be using the processor for content creation and visualization.
-
Disregard this entry.
-
1 Million Subscribers - Thank you all! And a giveaway!
GreyHat64 replied to nicklmg's topic in LTT Releases
Very nice 1 million sub video. It's amazing to think that when I first started, the WAN Show was yet unnamed and in your garage, and now you've gone fully professional with a company of seven. Congratulations, I look forward to your future content and success.- 22,217 replies
-
- 1 million
- subscribers
-
(and 8 more)
Tagged with:
-
Intel - "Talk to the Product Marketing Engineer" Live Chat & Giveaway
GreyHat64 replied to LinusTech's topic in LTT Releases
Thanks to Darrin Lynch for joining us today. -
Thanks again. All of my segfaults are fixed now, but the code is still not quite working. I'll be investigating it further from this point. This may be a stupid question, but what IDE or debugger is that? I've been using GDB and Valgrind.
-
Thanks for pointing out the misplaced free statements. That was part of the issue. Just to address your other points:1. There is no multiplication in the initialization of *primes because it is used as a dynamically growing array later in the code. 2. I can't just iterate down from sqrtConstant because that could give me composite factors that would have to be factored, creating some nasty recursion. 3. I used a long for sqrtConstant because it's guaranteed to be a 32-bit signed integer, while an int could be either 16-bit or 32-bit. 16-bits would be too small for sqrtConstant. Noted and fixed. Thanks!Now here's the new code: /* Program to compute the greatest prime factor of CONSTANT. Primes up to the * sqrt of CONSTANT are found using the sieve of Eratosthenes. Primes are then * used for trial division in descending order to find the greatest prime * factor. */#include <stdio.h>#include <stdlib.h>#include <math.h>#define CONSTANT 600851475143.0int main(void){ enum boolean { FALSE, TRUE }; long sqrtConstant = floor(sqrt(CONSTANT)); char *sieve = malloc((sqrtConstant+1) * sizeof(char)); /* Boolean array */ double *primes = malloc(sizeof(double)); /* Primes up to sqrt of const */ double *temp; int i = 0; /* Greatest index of primes */ long n; if (sieve == NULL || primes == NULL) { printf("Error allocating memory!\n"); return 1; }/* if (sieve == NULL) { printf("Error allocating memory! (sieve)\n"); return 1; } if (primes == NULL) { printf("Error allocating memory! (primes)\n"); return 1; }*/ for (n = 0; n <= sqrtConstant; n++) { /* Initialize the sieve */ if (n < 2) { sieve[n] = FALSE; } else { sieve[n] = TRUE; } } for (n = 2; n <= sqrtConstant; n++) { /* Sieve of Eratosthenes */ if (sieve[n] == TRUE) { long m; for (m = n * n; m <= sqrtConstant; m += n) { sieve[m] = FALSE; } } } for (n = 0; n <= sqrtConstant; n++) { /* Convert sieve to array of primes */ if (sieve[n] == TRUE) { primes[i] = n; temp = realloc(primes, ((i++)+2) * sizeof(double)); if (temp !=NULL) { primes = temp; } else { free(sieve); free(primes); printf("Error allocating memory!\n"); return 1; } } } free(temp); free(sieve); while (primes[i-1] != floor(primes[i-1])) { /* Determine greatest prime factor*/ /*segfault*/ i--; } printf("%.f\n", primes[i]); free(primes); return 0;}
-
I'm working on Project Euler as a coding exercise. The third problem asks what the greatest prime factor of a large arbitrary number is. Here's my code: /* ANSI C program to compute the greatest prime factor of CONSTANT. Primes up to the * sqrt of CONSTANT are found using the sieve of Eratosthenes. Primes are then * used for trial division in descending order to find the greatest prime * factor. */#include <stdio.h>#include <stdlib.h>#include <math.h>#define CONSTANT 600851475143.0int main(void){ enum boolean { FALSE, TRUE }; long sqrtConstant = floor(sqrt(CONSTANT)); char *sieve = malloc((sqrtConstant+1) * sizeof(char)); /* Boolean array */ double *primes = malloc(sizeof(double)); /* Primes up to sqrt of const */ double *temp; int i = 0; /* Greatest index of primes */ long n; if (sieve == NULL || primes == NULL) { printf("Error allocating memory!\n"); return 1; }/* if (sieve == NULL) { printf("Error allocating memory! (sieve)\n"); return 1; } if (primes == NULL) { printf("Error allocating memory! (primes)\n"); return 1; }*/ for (n = 0; n <= sqrtConstant; n++) { /* Initialize the sieve */ if (n < 2) { sieve[n] = FALSE; } else { sieve[n] = TRUE; } } for (n = 2; n <= sqrtConstant; n++) { /* Sieve of Eratosthenes */ if ((sieve[n] = TRUE)) { long m; for (m = n * n; m <= sqrtConstant; m += n) { sieve[m] = FALSE; } } } for (n = 0; n <= sqrtConstant; n++) { /* Convert sieve to array of primes */ if ((sieve[n] = TRUE)) { /* Segfault */ primes[i] = n; temp = realloc(primes, ((i++)+2) * sizeof(double)); if (temp !=NULL) { primes = temp; } else { free(primes); printf("Error allocating memory!\n"); return 1; } free(sieve); free(temp); } } while (primes[n] != floor(primes[n])) { /* Determine greatest prime factor*/ i--; } printf("%.f\n", primes[i]); free(primes); return 0;}I'm getting segfaults of all different sorts from my sieve array. Initially I was getting a stack overflow because the sieve was an array stored in the stack. It shouldn't have caused a stack overflow on my machine though, because it's only 775,147 bytes in size, smaller than my 8 MB stack limit. Either way, I decided to move the sieve into the heap by using a pointer instead of an array. Since then, I've been dealing with access and write related segfaults with the sieve. I can't figure out what the underlying issue is. Also, general criticism of my code would be appreciated.
-
I'd have to say that the build quality is the thing I like the most about the One.
-
My storage setup is a Crucial M4 128GB SSD as my boot drive and a Seagate Barracuda 1TB drive for games and video editing. I use the Crucial M4 because it's a low cost, reliable SSD with decent speed, and I use a Barracuda because it's a low cost 7200 RPM drive with 64MB of cache. I'd love to upgrade to a WD Red drive setup because I have many times filled my 1TB drive with raw video, and I want a redundant way to archive my videos.
-
My Steam library's a bit small. Could definitely use some games. :D https://twitter.com/greyhat2600
-
It does have SATA ports, I believe SATA II.
-
I'm thinking of finally setting up a small storage server for backups, torrents, etc. I have an old Dell with a Pentium 4 630 that I'm thinking of using, but I'm also very open to building a server or buying a prebuilt if it fits my budget better. I'm trying to do this for as little money as possible, while not skimping on features or performance. I'm thinking of a RAID 1 array of two 1 TB or 2 TB drives on the motherboard, as a RAID card is overkill and out of the price range. Thoughts and suggestions?