Re: Find "py.exe" & copy it to "Python" (flat, no extension).

Liste des GroupesRevenir à ol advocacy 
Sujet : Re: Find "py.exe" & copy it to "Python" (flat, no extension).
De : nospam (at) *nospam* dfs.com (DFS)
Groupes : comp.os.linux.advocacy
Date : 27. Jun 2024, 19:55:22
Autres entêtes
Message-ID : <667da789$1$7076$882e4bbb@reader.netnews.com>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
User-Agent : Betterbird (Windows)
On 6/26/2024 12:36 PM, rbowman wrote:

I have better things to do with my life
than taking on an army of 'fixers'.  DFS is bad enough.
Somewhat new C challenge!
* determine the mode of a set of random, positive ints *
My code is below.  To make the challenge easier, it generates and sorts the random numbers for you.
$ ./prog N  (to run it)
Refer to my solution whenever you want, but preferably after you've written yours.
For extra credit, determine/print the mode(s) using only one pass thru the dataset. I didn't do that - I looped it twice.
Enjoy!
====================================================================
//this program determines the mode of a set of integers
//this code is hereby donated to the public domain
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
//comparator function used with qsort
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;
}
int main(int argc, char *argv[])
{
//vars
int N = atoi(argv[1]);
int *nums  = malloc(N * sizeof(int));
int i = 0;

//------------------------------------------------------------------
//generate random numbers
//------------------------------------------------------------------
int low = 1, high = N*3;
srand(time(NULL));
for(i=0;i<N;i++) {
nums[i] = (low + rand() / (RAND_MAX / (high - low + 1) + 1));
}

printf("%d randoms between 1 and %d\n", N, 3*N);
for(i=0;i<N;i++) { printf("%d ", nums[i]); }
qsort(nums,N,sizeof(int),compareint);
printf("\nSorted\n");
for(i=0;i<N;i++) { printf("%d ", nums[i]); }

//------------------------------------------------------------------
//determine mode
//------------------------------------------------------------------
int maxoccur = 0, dmax = nums[N-1];
int *modecnt = calloc(dmax + 1, sizeof(int));

//get count of each value in dataset
for(i = 0; i < N; i++)   {
modecnt[nums[i]]++;
if(modecnt[nums[i]] > maxoccur) {
maxoccur = modecnt[nums[i]];
}
}

//print each value that occurs the most often
if (maxoccur > 1) {
printf("\n\nmode: ");
for(i = 0; i <= dmax; i++) {
if(modecnt[i] == maxoccur) {
printf("%d ",i);
}
}
printf("(%d occurrences ea.)", maxoccur);
}

//no repeating values
if (maxoccur == 1) {
printf("\nmode: na (no repeating values)");
}

free(modecnt);
free(nums);

printf("\n");
return 0;
}
====================================================================

Date Sujet#  Auteur
8 May 24 * Find "py.exe" & copy it to "Python" (flat, no extension).216Relf
8 May 24 `* Re: Find "py.exe" & copy it to "Python" (flat, no extension).215Joel
8 May 24  `* Re: Find "py.exe" & copy it to "Python" (flat, no extension).214Lawrence D'Oliveiro
8 May 24   +* Re: Find "py.exe" & copy it to "Python" (flat, no extension).33rbowman
8 May 24   i+* Re: Find "py.exe" & copy it to "Python" (flat, no extension).31Lawrence D'Oliveiro
8 May 24   ii`* Re: Find "py.exe" & copy it to "Python" (flat, no extension).30rbowman
8 May 24   ii `* Re: Find "py.exe" & copy it to "Python" (flat, no extension).29Lawrence D'Oliveiro
9 May 24   ii  `* Re: Find "py.exe" & copy it to "Python" (flat, no extension).28rbowman
9 May 24   ii   `* Re: Find "py.exe" & copy it to "Python" (flat, no extension).27Lawrence D'Oliveiro
9 May 24   ii    `* Re: Find "py.exe" & copy it to "Python" (flat, no extension).26rbowman
9 May 24   ii     `* Re: Find "py.exe" & copy it to "Python" (flat, no extension).25Lawrence D'Oliveiro
9 May 24   ii      +* Re: Find "py.exe" & copy it to "Python" (flat, no extension).2rbowman
9 May 24   ii      i`- Re: Find "py.exe" & copy it to "Python" (flat, no extension).1Lawrence D'Oliveiro
10 May 24   ii      `* Re: Find "py.exe" & copy it to "Python" (flat, no extension).22Stéphane CARPENTIER
10 May 24   ii       +* Re: Find "py.exe" & copy it to "Python" (flat, no extension).4rbowman
10 May 24   ii       i`* Re: Find "py.exe" & copy it to "Python" (flat, no extension).3Lawrence D'Oliveiro
11 May 24   ii       i `* Re: Find "py.exe" & copy it to "Python" (flat, no extension).2rbowman
11 May 24   ii       i  `- Re: Find "py.exe" & copy it to "Python" (flat, no extension).1Lawrence D'Oliveiro
10 May 24   ii       `* Re: Find "py.exe" & copy it to "Python" (flat, no extension).17Farley Flud
10 May 24   ii        `* Re: Find "py.exe" & copy it to "Python" (flat, no extension).16Stéphane CARPENTIER
10 May 24   ii         `* Re: Find "py.exe" & copy it to "Python" (flat, no extension).15Farley Flud
11 May 24   ii          +* Re: Find "py.exe" & copy it to "Python" (flat, no extension).13Stéphane CARPENTIER
11 May 24   ii          i+* Re: Find "py.exe" & copy it to "Python" (flat, no extension).7Farley Flud
11 May 24   ii          ii+- Re: Find "py.exe" & copy it to "Python" (flat, no extension).1Joel
11 May 24   ii          ii+- Re: Find "py.exe" & copy it to "Python" (flat, no extension).1rbowman
12 May 24   ii          ii+* Re: Find "py.exe" & copy it to "Python" (flat, no extension).3Stéphane CARPENTIER
12 May 24   ii          iii+- Re: Find "py.exe" & copy it to "Python" (flat, no extension).1Stéphane CARPENTIER
13 May 24   ii          iii`- Re: Find "py.exe" & copy it to "Python" (flat, no extension).1Chris Ahlstrom
12 May 24   ii          ii`- Re: Find "py.exe" & copy it to "Python" (flat, no extension).1Chris Ahlstrom
11 May 24   ii          i`* Re: Find "py.exe" & copy it to "Python" (flat, no extension).5rbowman
11 May 24   ii          i `* Re: Find "py.exe" & copy it to "Python" (flat, no extension).4Stéphane CARPENTIER
12 May 24   ii          i  +* Re: Find "py.exe" & copy it to "Python" (flat, no extension).2rbowman
12 May 24   ii          i  i`- Re: Find "py.exe" & copy it to "Python" (flat, no extension).1Lawrence D'Oliveiro
12 May 24   ii          i  `- Re: Find "py.exe" & copy it to "Python" (flat, no extension).1Chris Ahlstrom
12 May 24   ii          `- Re: Find "py.exe" & copy it to "Python" (flat, no extension).1DFS
8 May 24   i`- I MANUALLY uninstalled Python 3.6.1Relf
8 May 24   +* Re: Find "py.exe" & copy it to "Python" (flat, no extension).22Farley Flud
8 May 24   i+* Re: Find "py.exe" & copy it to "Python" (flat, no extension).4rbowman
8 May 24   ii+* Re: Find "py.exe" & copy it to "Python" (flat, no extension).2Farley Flud
9 May 24   iii`- Re: Find "py.exe" & copy it to "Python" (flat, no extension).1rbowman
8 May 24   ii`- Re: Find "py.exe" & copy it to "Python" (flat, no extension).1candycanearter07
10 May 24   i`* Re: Find "py.exe" & copy it to "Python" (flat, no extension).17Stéphane CARPENTIER
10 May 24   i +* Re: Find "py.exe" & copy it to "Python" (flat, no extension).14rbowman
10 May 24   i i+* Re: Find "py.exe" & copy it to "Python" (flat, no extension).7Stéphane CARPENTIER
10 May 24   i ii+- Re: Find "py.exe" & copy it to "Python" (flat, no extension).1Lawrence D'Oliveiro
10 May 24   i ii`* Re: Find "py.exe" & copy it to "Python" (flat, no extension).5rbowman
11 May 24   i ii +- Re: Find "py.exe" & copy it to "Python" (flat, no extension).1Lawrence D'Oliveiro
11 May 24   i ii `* Re: Find "py.exe" & copy it to "Python" (flat, no extension).3Stéphane CARPENTIER
12 May 24   i ii  `* Re: Find "py.exe" & copy it to "Python" (flat, no extension).2Lawrence D'Oliveiro
12 May 24   i ii   `- Re: Find "py.exe" & copy it to "Python" (flat, no extension).1Stéphane CARPENTIER
10 May 24   i i+* Re: Find "py.exe" & copy it to "Python" (flat, no extension).5Lawrence D'Oliveiro
11 May 24   i ii`* Re: Find "py.exe" & copy it to "Python" (flat, no extension).4rbowman
11 May 24   i ii `* Re: Find "py.exe" & copy it to "Python" (flat, no extension).3Lawrence D'Oliveiro
11 May 24   i ii  `* Re: Find "py.exe" & copy it to "Python" (flat, no extension).2rbowman
11 May 24   i ii   `- Re: Find "py.exe" & copy it to "Python" (flat, no extension).1Lawrence D'Oliveiro
15 May 24   i i`- Re: Find "py.exe" & copy it to "Python" (flat, no extension).1Sebastian
10 May 24   i `* Re: Find "py.exe" & copy it to "Python" (flat, no extension).2Lawrence D'Oliveiro
11 May 24   i  `- Re: Find "py.exe" & copy it to "Python" (flat, no extension).1Stéphane CARPENTIER
8 May 24   `* Re: Find "py.exe" & copy it to "Python" (flat, no extension).158DFS
8 May 24    `* Re: Find "py.exe" & copy it to "Python" (flat, no extension).157Lawrence D'Oliveiro
9 May 24     +* Re: Find "py.exe" & copy it to "Python" (flat, no extension).151rbowman
9 May 24     i`* Re: Find "py.exe" & copy it to "Python" (flat, no extension).150Lawrence D'Oliveiro
9 May 24     i `* Re: Find "py.exe" & copy it to "Python" (flat, no extension).149rbowman
9 May 24     i  `* Re: Find "py.exe" & copy it to "Python" (flat, no extension).148Lawrence D'Oliveiro
9 May 24     i   `* Re: Find "py.exe" & copy it to "Python" (flat, no extension).147rbowman
9 May 24     i    `* Re: Find "py.exe" & copy it to "Python" (flat, no extension).146Lawrence D'Oliveiro
9 May 24     i     `* Re: Find "py.exe" & copy it to "Python" (flat, no extension).145rbowman
9 May 24     i      +* Re: Find "py.exe" & copy it to "Python" (flat, no extension).135DFS
10 May 24     i      i+* Re: Find "py.exe" & copy it to "Python" (flat, no extension).133Lawrence D'Oliveiro
10 May 24     i      ii`* Re: Find "py.exe" & copy it to "Python" (flat, no extension).132rbowman
10 May 24     i      ii +- Re: Find "py.exe" & copy it to "Python" (flat, no extension).1Lawrence D'Oliveiro
15 May 24     i      ii `* Re: Find "py.exe" & copy it to "Python" (flat, no extension).130Sebastian
15 May 24     i      ii  +* Re: Find "py.exe" & copy it to "Python" (flat, no extension).4Lawrence D'Oliveiro
15 May 24     i      ii  i+- USENET isn't indexed.1Relf
16 May 24     i      ii  i`* Re: Find "py.exe" & copy it to "Python" (flat, no extension).2Sebastian
16 May 24     i      ii  i `- Re: Find "py.exe" & copy it to "Python" (flat, no extension).1Andrzej Matuch
15 May 24     i      ii  `* Re: Find "py.exe" & copy it to "Python" (flat, no extension).125Chris Ahlstrom
15 May 24     i      ii   +- Re: Find "py.exe" & copy it to "Python" (flat, no extension).1Chris Ahlstrom
15 May 24     i      ii   `* Re: Find "py.exe" & copy it to "Python" (flat, no extension).123Andrzej Matuch
16 May 24     i      ii    +* Re: Find "py.exe" & copy it to "Python" (flat, no extension).97Sebastian
16 May 24     i      ii    i`* Re: Find "py.exe" & copy it to "Python" (flat, no extension).96Lawrence D'Oliveiro
16 May 24     i      ii    i `* Re: Find "py.exe" & copy it to "Python" (flat, no extension).95rbowman
17 May 24     i      ii    i  `* Re: Find "py.exe" & copy it to "Python" (flat, no extension).94Lawrence D'Oliveiro
17 May 24     i      ii    i   +- Re: Find "py.exe" & copy it to "Python" (flat, no extension).1rbowman
17 May 24     i      ii    i   +* Re: Find "py.exe" & copy it to "Python" (flat, no extension).2rbowman
19 May 24     i      ii    i   i`- Re: Find "py.exe" & copy it to "Python" (flat, no extension).1RonB
19 May 24     i      ii    i   `* Re: Find "py.exe" & copy it to "Python" (flat, no extension).90Sebastian
28 May 24     i      ii    i    `* Re: Find "py.exe" & copy it to "Python" (flat, no extension).89Lawrence D'Oliveiro
28 May 24     i      ii    i     +- Re: Find "py.exe" & copy it to "Python" (flat, no extension).1Joel
28 May 24     i      ii    i     +- Re: Find "py.exe" & copy it to "Python" (flat, no extension).1Joel
29 May 24     i      ii    i     `* Re: Find "py.exe" & copy it to "Python" (flat, no extension).86Lawrence D'Oliveiro
29 May 24     i      ii    i      +* Re: Find "py.exe" & copy it to "Python" (flat, no extension).2RonB
29 May 24     i      ii    i      i`- Re: Find "py.exe" & copy it to "Python" (flat, no extension).1Joel
29 May 24     i      ii    i      +- Re: Find "py.exe" & copy it to "Python" (flat, no extension).1Joel
29 May 24     i      ii    i      +- Re: Find "py.exe" & copy it to "Python" (flat, no extension).1Joel
3 Jun 24     i      ii    i      `* Re: Find "py.exe" & copy it to "Python" (flat, no extension).81Lawrence D'Oliveiro
3 Jun 24     i      ii    i       +* Re: Find "py.exe" & copy it to "Python" (flat, no extension).79Joel Crump
25 Jun 24     i      ii    i       i`* Re: Find "py.exe" & copy it to "Python" (flat, no extension).78Lawrence D'Oliveiro
25 Jun 24     i      ii    i       i `* Re: Find "py.exe" & copy it to "Python" (flat, no extension).77Joel
25 Jun 24     i      ii    i       i  +- Re: Find "py.exe" & copy it to "Python" (flat, no extension).1rbowman
25 Jun 24     i      ii    i       i  `* Re: Find "py.exe" & copy it to "Python" (flat, no extension).75Lawrence D'Oliveiro
3 Jun 24     i      ii    i       `- Re: Find "py.exe" & copy it to "Python" (flat, no extension).1RonB
16 May 24     i      ii    +* Re: Find "py.exe" & copy it to "Python" (flat, no extension).17Lawrence D'Oliveiro
16 May 24     i      ii    +* Re: Find "py.exe" & copy it to "Python" (flat, no extension).4Chris Ahlstrom
17 May 24     i      ii    `* Re: Find "py.exe" & copy it to "Python" (flat, no extension).4RonB
10 May 24     i      i`- Re: Find "py.exe" & copy it to "Python" (flat, no extension).1rbowman
10 May 24     i      +* Re: Find "py.exe" & copy it to "Python" (flat, no extension).8Lawrence D'Oliveiro
10 May 24     i      `- Re: Find "py.exe" & copy it to "Python" (flat, no extension).1Chris Ahlstrom
9 May 24     +- Re: Find "py.exe" & copy it to "Python" (flat, no extension).1Lawrence D'Oliveiro
9 May 24     `* Re: Find "py.exe" & copy it to "Python" (flat, no extension).4candycanearter07

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal