Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

Q: What is the difference between a duck? A: One leg is both the same.


comp / comp.os.linux.advocacy / Re: Need a Laugh? Watch DFS tear Feeb a new one.

Subject: Re: Need a Laugh? Watch DFS tear Feeb a new one.
From: candycanearter07
Newsgroups: comp.os.linux.advocacy
Organization: the-candyden-of-code
Date: Sun, 14 Jul 2024 15:00 UTC
References: 1 2
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: candycanearter07@candycanearter07.nomail.afraid (candycanearter07)
Newsgroups: comp.os.linux.advocacy
Subject: Re: Need a Laugh? Watch DFS tear Feeb a new one.
Date: Sun, 14 Jul 2024 15:00:04 -0000 (UTC)
Organization: the-candyden-of-code
Lines: 318
Message-ID: <slrnv97pv4.4hg.candycanearter07@candydeb.host.invalid>
References: <17e193b486847bee$317$2290655$802601b3@news.usenetexpress.com>
<6692f1bc$0$1895505$882e4bbb@reader.netnews.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 14 Jul 2024 17:00:05 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="2463086b2a28c1e7308ac84d14cff882";
logging-data="218689"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/QZdTx7Kel+B07VGrN1GKweC94Q/4DTxh/nxjB+Qb+Uw=="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:N5xJcsMtFK48cuiHFsEAA2Z2pY8=
X-Face: b{dPmN&%4|lEo,wUO\"KLEOu5N_br(N2Yuc5/qcR5i>9-!^e\.Tw9?/m0}/~:UOM:Zf]%
b+ V4R8q|QiU/R8\|G\WpC`-s?=)\fbtNc&=/a3a)r7xbRI]Vl)r<%PTriJ3pGpl_/B6!8pe\btzx
`~R! r3.0#lHRE+^Gro0[cjsban'vZ#j7,?I/tHk{s=TFJ:H?~=]`O*~3ZX`qik`b:.gVIc-[$t/e
ZrQsWJ >|l^I_[pbsIqwoz.WGA]<D
View all headers

DFS <nospam@dfs.com> wrote at 21:29 this Saturday (GMT):
> On 7/12/2024 5:15 PM, Lameass Larry Piet wrote:
>
>
>> The DooFuS wants to read a text file to determine its
>> length and then rewind and process from the beginning.
>
>
> wtf are you babbling about now, numbnut?
>
> You might be referring to my clc post 'Whaddaya think?'
>
> But it's clear you didn't understand it. I wasn't concerned with the
> 'length of the file' (whatever that means). I was counting the number
> of data points in the file so I could allocate memory, then rewind the
> file and read them in.
>
>
> idiot

Ohh

>> Holy godzilla mutherfuckers!
>>
>> Hasn't this infinite idiot ever heard of GNU flex?
>
> Why tf would anyone EVER waste their time and use such GuhNoo crapware
> just to read a set of numbers from a file? It's a few lines of simple code.
>
> AND, even though my original file format is integers separated by spaces
> (shown for compactness in the post), my code works unchanged if they're
> separated by line-feeds.
>
>
> double idiot

Does it work if the numbers are separated by alphabet chars?

>> Even a C newbie would seriously consider pre-processing
>> the input file to get it into proper shape. But not
>> this insuperable dunce.
>
> Who needs to "pre-process" a set of integers?
>
> triple idiot

How would you even pre-process that?

>> Any moron so totally inept in programming cannot ever
>> be admitted into a serious discussion of GNU/Linux.
>
> You labeled this double-time shit-code of yours "wonderfully perfect and
> highly efficient":
>
>
> /* free all strarray elements */
> for(i = 0; i < rec_count; i++) {
> free(data[i]->field1);
> free(data[i]->field2);
> free(data[i]->field3);
> free(data[i]);
> i++;
> }

To be fair, it is a fine way to free data structures like that. I know
I've used something like this before.

> Who are you to talk about 'inept programming', asshole? You were
> clearly having another one of your "C Programmer Extraordinaire" moments.
>
> http://al.howardknight.net/?STYPE=msgid&MSGI=%3Crnelct0tjg%40news3.newsguy.com%3E
>
>
>
>
>
> Here's the full population descriptive stats program (of which the file
> import is an option).
>
> It's very entertaining.
>
> compile
> $ gcc -Wall prog.c -o prog -lm
>
> use
> $ ./prog -option N|F
> where option is:
> -r generates N random numbers
> -c generates consecutive numbers 1 to N
> -o generates random numbers with outliers
> -f read in dataset from file
> N is 2+, or F is the file containing the integers
>
>===================================================================
> #include <stdlib.h>
> #include <stdio.h>
> #include <math.h>
> #include <string.h>
> #include <time.h>
> int randNbr(int low, int high) {
>     return (low + rand() / (RAND_MAX / (high - low + 1) + 1));
> }
> int compareint (const void * a, const void * b)
> {
> if (*(int*)a > *(int*)b) return 1;
> else if (*(int*)a < *(int*)b) return -1;
> else return 0;
> }

Why aren't you just using int pointer arguments here?

> int main(int argc, char *argv[])
> {
>     if(argc < 3) {
> printf("Missing argument:\n");
> printf(" * enter an option -r -c -o or -f\n");
> printf(" * enter a number greater than 2, or a file name\n");
> exit(0);
>     }
>     int i = 0,N = 0;
>     int *nums;
>     if(strcmp(argv[1],"-f") != 0) {
> N = atoi(argv[2]);
> nums = malloc(N * sizeof(int));
>     }
>     if(strcmp(argv[1],"-r") == 0) {
> srand(time(NULL));
> for(i=0;i<N;i++) { nums[i] = randNbr(1,N*3); }
>
> printf("%d Randoms between 1 and %d\n", N, 3*N);
> printf("No commas : "); for(i=0;i<N;i++) { printf("%d ",
> nums[i]); }
> printf("\nWith commas: "); for(i=0;i<N;i++) { printf("%d,",
> nums[i]); }
> qsort(nums,N,sizeof(int),compareint);
> printf("\nSorted : "); for(i=0;i<N;i++) { printf("%d ",
> nums[i]); }
> printf("\nSorted : "); for(i=0;i<N;i++) { printf("%d,",
> nums[i]); }
>     }
>     if(strcmp(argv[1],"-o") == 0) {
> srand(time(NULL));
> nums[0] = 1; nums[1] = 3;
> for(i=2;i<N-2;i++) { nums[i] = randNbr(100,N*30); }
> nums[N-2] = 1000; nums[N-1] = 2000;
>
> printf("%d Randoms with outliers\n", N);
> printf("No commas : "); for(i=0;i<N;i++) { printf("%d ",
> nums[i]); }
> printf("\nWith commas: "); for(i=0;i<N;i++) { printf("%d,",
> nums[i]); }
> qsort(nums,N,sizeof(int),compareint);
> printf("\nSorted : "); for(i=0;i<N;i++) { printf("%d ",
> nums[i]); }
> printf("\nSorted : "); for(i=0;i<N;i++) { printf("%d,",
> nums[i]); }
>     }
>     if(strcmp(argv[1],"-c") == 0) {
> for(i=0;i<N;i++) { nums[i] = i + 1; }
>
> printf("%d Consecutive\n", N);
> printf("No commas : "); for(i=0;i<N;i++) { printf("%d ",
> nums[i]); }
> printf("\nWith commas : "); for(i=0;i<N;i++) { printf("%d,",
> nums[i]); }
>     }
>     if(strcmp(argv[1],"-f") == 0) {
> nums = malloc(2 * sizeof(int));
> FILE* datafile = fopen(argv[2], "r");
> while(fscanf(datafile, "%d", &nums[N++]) == 1){
> nums = realloc(nums, (N+1) * sizeof(int));
> }
> fclose (datafile);
> N--;
> printf("%d from file", N);
> printf(" : "); for(i=0;i<N;i++) { printf("%d ", nums[i]); }
> qsort(nums,N,sizeof(int),compareint);
> printf("\nNo commas : "); for(i=0;i<N;i++) { printf("%d ",
> nums[i]); }
> printf("\nWith commas : "); for(i=0;i<N;i++) { printf("%d,",
> nums[i]); }
>
>     }
>     double dmin = nums[0], dmax = nums[N-1];
>     double sumN=0.0, median=0.0, Q1=0.0, Q2=0.0, Q3=0.0, IQR=0.0;
>     double sqrdiffmean = 0.0, cubediffmean = 0.0, quaddiffmean = 0.0;
>     double meanabsdev = 0.0, rootmeansqr = 0.0;
>     char temp[15]="";
>     for(i=0;i<N;i++) {sumN += nums[i];}
>     double mean = sumN / (double)N;
>     for(i = 0; i < N; i++)
>     {
> double diff = nums[i] - mean;
> sqrdiffmean += diff * diff;
> cubediffmean += diff * diff * diff;
> quaddiffmean += diff * diff * diff * diff;
> meanabsdev += fabs(diff);
> rootmeansqr += nums[i] * nums[i];
>     }
>     double stddev = sqrt(sqrdiffmean/N);
>     double kurtosis = quaddiffmean / (N * pow(sqrt(sqrdiffmean/N),4));
>     if(N % 2 == 0) {
> Q2 = median = (nums[(N/2)-1] + nums[N/2]) / 2.0;
> i = N/2;
> if(i % 2 == 0) {
> Q1 = (nums[(i/2)-1] + nums[i/2]) / 2.0;
> Q3 = (nums[i + ((i-1)/2)] + nums[i+(i/2)]) / 2.0;
> }
> else {
> Q1 = nums[(i-1)/2];
> Q3 = nums[i + ((i-1)/2)];
> }
>     }
>     if(N % 2 != 0) {
> Q2 = median = nums[(N-1)/2];
> i = (N-1)/2;
> if(i % 2 == 0) {
> Q1 = (nums[(i/2)-1] + nums[i/2]) / 2.0;
> Q3 = (nums[i + (i/2)] + nums[i + (i/2) + 1]) / 2.0;
> }
> else {
> Q1 = nums[(i-1)/2];
> Q3 = nums[i + ((i+1)/2)];
> }
>     }
>     int occur = 0;
>     char mode[250] = "";
>     if(strcmp(argv[2],"-c") != 0) {
> int *modecnt = calloc(dmax + 1, sizeof(int));
> for(i = 0; i < N; i++) {
> modecnt[nums[i]]++;
> if(modecnt[nums[i]] > occur) {
> occur = modecnt[nums[i]];
> }
> }
> if (occur > 1) {
> for(i = 0; i <= dmax; i++) {
> if(modecnt[i] == occur) {
> sprintf(temp,"%d ",i);
> strncat(mode,temp,strlen(temp));
> }
> }
> }
> free(modecnt);
>     }
>     IQR = Q3 - Q1;
>     char outliers[200]="";
>     if (N > 3) {
> double lo = Q1 - (1.5 * IQR);
> double hi = Q3 + (1.5 * IQR);
> if (dmin >= lo && dmax <= hi) {
> strcat(outliers,"none (using IQR * 1.5 rule)");
> }
> if (dmin < lo || dmax > hi) {
> for(i = 0; i < N; i++) {
> double val = (double)nums[i];
> if(val < lo || val > hi) {
> sprintf(temp,"%.0f ",val);
> printf("%d\n",(int)strlen(temp));
> strncat(outliers, temp, strlen(temp));
> }
> }
> strcat(outliers," (using IQR * 1.5 rule)");
> }
> outliers[strlen(outliers)] = '\0';
>     }
>     printf("\n--------------------------------------------------------------\n");
>     printf("Minimum : %.0f\n", dmin);
>     printf("Maximum : %.0f\n", dmax);
>     printf("Range : %.0f\n", dmax - dmin);
>     printf("Size N : %d\n" , N);
>     printf("Sum N : %.0f\n", sumN);
>     printf("Mean μ : %.2f\n", mean);
>     printf("Median : %.1f\n", median);
>     if(occur > 1) {
>     printf("Mode(s) : %s (%d occurrences ea)\n", mode,occur);}
>     else {
>     printf("Mode(s) : na (no repeating values)\n");}
>     printf("Std Dev σ : %.6f\n", stddev);
>     printf("Variance σ^2 : %.6f\n", sqrdiffmean/N);
>     printf("Mid Range : %.1f\n", (dmax + dmin)/2);
>     printf("Quartiles");
>     if(N > 3) {printf(" Q1: %.1f\n", Q1);}
>     if(N < 4) {printf(" Q1: na\n");}
>     printf(" Q2: %.1f (median)\n", Q2);
>     if(N > 3) {printf(" Q3: %.1f\n", Q3);}
>     if(N < 4) {printf(" Q3: na\n");}
>     printf("IQR : %.1f (interquartile range)\n", IQR);
>     if(N > 3) {printf("Outliers : %s\n", outliers);}
>     if(N < 4) {printf("Outliers : na\n");}
>     printf("Sum Squares SS : %.6f\n", sqrdiffmean);
>     printf("MAD : %.6f (mean absolute deviation)\n",
> meanabsdev / N);
>     printf("Root Mean Sqr : %.6f\n", sqrt(rootmeansqr / N));
>     printf("Std Error Mean : %.6f\n", stddev / sqrt(N));
>     printf("Skewness γ1 : %.6f\n", cubediffmean / (N *
> pow(sqrt(sqrdiffmean/N),3)));
>     printf("Kurtosis β2 : %.6f\n", kurtosis);
>     printf("Kurtosis Excess α4 : %.6f\n", kurtosis - 3);
>     printf("CV : %.8f (coefficient of variation\n",
> sqrt(sqrdiffmean/N) / mean);
>     printf("RSD : %.6f%% (relative std deviation)\n",
> 100 * (sqrt(sqrdiffmean/N) / mean));
>     printf("--------------------------------------------------------------\n");
>     printf("Check results up to N=9999 against\n");
>     printf("https://www.calculatorsoup.com/calculators/statistics/descriptivestatistics.php");
>     printf("\n\n");
>     free(nums);
>     return 0;
> }
>===============================================================================
>
> pwned

looks pretty good!
--
user <candycane> is generated from /dev/urandom

SubjectRepliesAuthor
o Need a Laugh? Check the DooFuS Posts on Comp.Lang.C

By: Lester Thorpe on Fri, 12 Jul 2024

27Lester Thorpe

rocksolid light 0.9.8
clearnet tor