Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.os.linux.advocacy > #412891
| From | owl <owl@rooftop.invalid> |
|---|---|
| Newsgroups | comp.os.linux.advocacy |
| Subject | Re: Snit hitting the glue bag early today |
| Date | 2017-05-04 19:49 +0000 |
| Organization | O.W.L. |
| Message-ID | <z80b3.y88abhy@rooftop.invalid> (permalink) |
| References | (8 earlier) <oea874$j9$2@dont-email.me> <acv03.abhuu4@rooftop.invalid> <oeclcq$tll$3@dont-email.me> <uzv003.aui@rooftop.invalid> <oefa57$1lg$2@dont-email.me> |
DFS <nospam@dfs.com> wrote:
>
> python repeat.py data.txt + 25
> 01 5 +++++
> 02 10 ++++++++++
> 03 15 +++++++++++++++
> 04 30 +++++++++++++++
> +++++++++++++++
> 05 2 ++
> 06 100 +++++++++++++++
> +++++++++++++++
> +++++++++++++++
> +++++++++++++++
> +++++++++++++++
> +++++++++++++++
> ++++++++++
> 07 21 +++++++++++++++
> ++++++
> 08 0
> 09 7 +++++++
> 10 20 +++++++++++++++
> +++++
> =========================================================================
>
> import sys
> for line in open(sys.argv[1],'r').readlines():
> data = line.rstrip()
> barchr = ''.join(sys.argv[2])
> barlen = int(data[-3:])
> maxlen = int(sys.argv[3])
> spacer = ' '
> print (data + spacer + (barchr * barlen))[:maxlen]
> if (len(data) + len(spacer) + barlen) > maxlen:
> blank = ''.join(' ') * int(len(data))
> remaining = barlen - maxlen + (len(data) + len(spacer))
> while remaining > 0:
> print (blank + spacer + (barchr * remaining))[:maxlen]
> remaining = remaining - maxlen + (len(data) + len(spacer))
>
> =========================================================================
>
> bash == severely pwned
> C == severely pwned
>
In your dreams. I see you got the python a bit faster, but C still
delivers an epic smackdown.
Python 0.010s
C 0.001s
Python:
anon@lowtide:~/code/repeat$ time ./repeat2.py data3 + 70
00 5 +++++
01 2 ++
08 5 +++++
09 137 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++
10 30 ++++++++++++++++++++++++++++++
11 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
12 21 +++++++++++++++++++++
13 21 +++++++++++++++++++++
14 7 +++++++
15 20 ++++++++++++++++++++
16 27 +++++++++++++++++++++++++++
17 33 +++++++++++++++++++++++++++++++++
18 26 ++++++++++++++++++++++++++
19 48 ++++++++++++++++++++++++++++++++++++++++++++++++
20 13 +++++++++++++
21 1 +
22 2 ++
real 0m0.010s
user 0m0.008s
sys 0m0.000s
anon@lowtide:~/code/repeat$
C:
anon@lowtide:~/code/repeat$ time ./rep3 data3 x 70
00 5 xxxxx
01 2 xx
08 5 xxxxx
09 137 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxx
10 30 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
11 52 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
12 21 xxxxxxxxxxxxxxxxxxxxx
13 21 xxxxxxxxxxxxxxxxxxxxx
14 7 xxxxxxx
15 20 xxxxxxxxxxxxxxxxxxxx
16 27 xxxxxxxxxxxxxxxxxxxxxxxxxxx
17 33 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
18 26 xxxxxxxxxxxxxxxxxxxxxxxxxx
19 48 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
20 13 xxxxxxxxxxxxx
21 1 x
22 2 xx
real 0m0.001s
user 0m0.000s
sys 0m0.000s
anon@lowtide:~/code/repeat$
------------------- rep3.c -----------------------
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define MAXLINES 400
#define MAXCHARS 100
#define MAXINTS 100
#define BUFMAX 10
int main(int argc, char *argv[])
{
int c,i,j,n,p,k;
int linecount=0;
FILE *fp;
char *filename;
char *mark=NULL;
char lines[MAXLINES][MAXCHARS]={{0}};
int nums[MAXINTS];
char buf[BUFMAX]={0};
int limit=0;
int markwidth=1;
int datawidth=0;
int barwidth=0;
int barlimit=0;
char *sep=" ";
int sepwidth=0;
int numsremaining=0;
if(argc<3)
{
fprintf(stderr,"usage: %s <filename> <mark> [limit]\n",argv[0]);
exit(1);
}
if(argc==4)
{
limit=atoi(argv[3]);
}
sepwidth=strlen(sep);
filename=argv[1];
mark=argv[2];
markwidth=strlen(mark);
fp=fopen(filename,"r+");
if(fp==NULL)
{
fprintf(stderr,"fp==NULL\n");
exit(1);
}
while((c=fgetc(fp))!=EOF)
{
if(c=='\n')
{
lines[i][j++]='\0';
linecount++;
if(linecount>=MAXLINES)
{
fprintf(stderr,"too many lines\n");
fclose(fp);
exit(1);
}
i++;
j=0;
}
else
{
lines[i][j++]=c;
}
}
for(i=0;i<linecount;i++)
{
for(j=0;lines[i][j]!='\0';j++)
{
n=0;
for(p=0;p<BUFMAX;p++)
{
buf[p]='\0';
}
while(lines[i][j]!='\0')
{
j++;
}
while(!isspace(lines[i][--j]))
{
;
}
while(lines[i][++j]!='\0')
{
if(isdigit(lines[i][j]))
{
buf[n++]=lines[i][j];
}
else
{
buf[n]='\0';
}
}
nums[i]=atoi(buf);
}
}
datawidth=strlen(lines[0]);
if(limit<=datawidth+sepwidth)
{
limit=datawidth+sepwidth+1;
}
barlimit=limit-datawidth-sepwidth;
if(limit==datawidth+sepwidth+1)
{
for(i=0;i<linecount;i++)
{
printf("%s%s",lines[i],sep);
for(j=0;j<nums[i];j++)
{
printf("%s",mark);
}
printf("\n");
}
}
else
{
for(i=0;i<linecount;i++)
{
barwidth=markwidth*nums[i];
numsremaining=nums[i];
printf("%s%s",lines[i],sep);
if(barwidth>barlimit)
{
for(j=0;j<barlimit/markwidth;j++)
{
printf("%s",mark);
numsremaining--;
}
printf("\n");
while(numsremaining)
{
for(k=0;k<datawidth;k++)
{
putchar(' ');
}
printf(sep);
for(j=0;j<barlimit/markwidth;j++)
{
if(numsremaining)
{
printf("%s",mark);
numsremaining--;
}
}
printf("\n");
}
}
else
{
for(j=0;j<nums[i];j++)
{
printf("%s",mark);
}
printf("\n");
}
}
}
fclose(fp);
return 0;
}
--------------------------------------------------
Back to comp.os.linux.advocacy | Previous | Next — Previous in thread | Next in thread | Find similar
Re: Snit hitting the glue bag early today DFS <nospam@dfs.com> - 2017-05-01 18:35 -0400
Re: Snit hitting the glue bag early today owl <owl@rooftop.invalid> - 2017-05-02 02:23 +0000
Re: Snit hitting the glue bag early today DFS <nospam@dfs.com> - 2017-05-02 11:26 -0400
Re: Snit hitting the glue bag early today owl <owl@rooftop.invalid> - 2017-05-02 22:12 +0000
Re: Snit hitting the glue bag early today DFS <nospam@dfs.com> - 2017-05-03 09:22 -0400
Re: Snit hitting the glue bag early today owl <owl@rooftop.invalid> - 2017-05-03 14:07 +0000
Re: Snit hitting the glue bag early today DFS <nospam@dfs.com> - 2017-05-04 09:29 -0400
Re: Snit hitting the glue bag early today Sandman <mr@sandman.net> - 2017-05-04 16:42 +0000
Re: Snit hitting the glue bag early today owl <owl@rooftop.invalid> - 2017-05-04 20:06 +0000
Re: Snit hitting the glue bag early today owl <owl@rooftop.invalid> - 2017-05-04 20:12 +0000
Re: Snit hitting the glue bag early today chrisv <chrisv@nospam.invalid> - 2017-05-05 06:52 -0500
Re: Snit hitting the glue bag early today Marek Novotny <marek.novotny@marspolar.com> - 2017-05-05 10:32 -0500
Re: Snit hitting the glue bag early today DFS <nospam@dfs.com> - 2017-05-05 13:22 -0400
Re: Snit hitting the glue bag early today DFS <nospam@dfs.com> - 2017-05-05 13:01 -0400
Re: Snit hitting the glue bag early today Steve Carroll <fretwizzer@gmail.com> - 2017-05-04 13:16 -0700
Re: Snit hitting the glue bag early today Sandman <mr@sandman.net> - 2017-05-04 21:36 +0000
Re: Snit hitting the glue bag early today DFS <nospam@dfs.com> - 2017-05-06 09:44 -0400
Re: Snit hitting the glue bag early today owl <owl@rooftop.invalid> - 2017-05-04 19:49 +0000
Re: Snit hitting the glue bag early today DFS <nospam@dfs.com> - 2017-05-04 19:28 -0400
Re: Snit hitting the glue bag early today owl <owl@rooftop.invalid> - 2017-05-05 02:56 +0000
Re: Snit hitting the glue bag early today DFS <nospam@dfs.com> - 2017-05-04 23:40 -0400
Re: Snit hitting the glue bag early today owl <owl@rooftop.invalid> - 2017-05-05 06:18 +0000
Re: Snit hitting the glue bag early today owl <owl@rooftop.invalid> - 2017-05-05 06:34 +0000
Re: Snit hitting the glue bag early today Sandman <mr@sandman.net> - 2017-05-05 07:07 +0000
Re: Snit hitting the glue bag early today owl <owl@rooftop.invalid> - 2017-05-05 07:29 +0000
Re: Snit hitting the glue bag early today owl <owl@rooftop.invalid> - 2017-05-05 16:48 +0000
Re: Snit hitting the glue bag early today owl <owl@rooftop.invalid> - 2017-05-05 20:49 +0000
Re: Snit hitting the glue bag early today DFS <nospam@dfs.com> - 2017-05-05 13:02 -0400
Re: Snit hitting the glue bag early today Sandman <mr@sandman.net> - 2017-05-05 19:12 +0000
Re: Snit hitting the glue bag early today Snit <usenet@gallopinginsanity.com> - 2017-05-05 13:45 -0700
Re: Snit hitting the glue bag early today DFS <nospam@dfs.com> - 2017-05-05 17:09 -0400
Re: Snit hitting the glue bag early today Sandman <mr@sandman.net> - 2017-05-05 21:41 +0000
Re: Snit hitting the glue bag early today DFS <nospam@dfs.com> - 2017-05-05 13:00 -0400
Re: Snit hitting the glue bag early today owl <owl@rooftop.invalid> - 2017-05-05 20:14 +0000
Re: Snit hitting the glue bag early today Snit <usenet@gallopinginsanity.com> - 2017-05-05 13:44 -0700
Re: Snit hitting the glue bag early today DFS <nospam@dfs.com> - 2017-05-05 23:51 -0400
Re: Snit hitting the glue bag early today owl <owl@rooftop.invalid> - 2017-05-06 04:48 +0000
Re: Snit hitting the glue bag early today DFS <nospam@dfs.com> - 2017-05-06 10:06 -0400
Re: Snit hitting the glue bag early today owl <owl@rooftop.invalid> - 2017-05-06 15:50 +0000
Re: Snit hitting the glue bag early today Chris Ahlstrom <OFeem1987@teleworm.us> - 2017-05-05 05:28 -0400
Re: Snit hitting the glue bag early today DFS <nospam@dfs.com> - 2017-05-05 13:02 -0400
csiph-web