help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: how to print all 3 char length string made whitespace {0..9} {a..z}


From: Mike Jonkmans
Subject: Re: how to print all 3 char length string made whitespace {0..9} {a..z}
Date: Thu, 6 Aug 2020 11:05:40 +0200

On Thu, Aug 06, 2020 at 12:46:08AM -0300, Marco Ippolito wrote:
> On 02/08/2020 18:10, Mike Jonkmans wrote:
> > 
> > Are you lookiung for this?
> >     echo {{a..z},\ ,{0..9}}{{a..z},\ ,{0..9}}{{a..z},\ ,{0..9}}
> 
> I was going to recommend this:
> 
> e=({a..z} ' ' {0..9}); l=${#e[@]}; for ((i=0; i<l; i++)); do for ((j=0; j<l;
> j++)); do for ((y=0; y<l; y++)); do printf "${e[i]}${e[j]}${e[y]} "; done;
> done; done
> 
> to make the space complexity, or memory footprint, of it depend linearly
> rather than exponentially (even if just to the 3rd power), on the input,
> allowing more characters in the set to be permuted (e.g. Chinese characters)
> without segfaulting on malloc.
> 
> Marco Ippolito
> maroloccio@gmail.com

Hmm, my echo should have been be a printf "%s\n".

Both solutions seem to work.

The for-solution does take 4x longer to run though (when piped to wc -c).
When printed to the terminal, the difference in runtime is rather large.
At my desktop it is running 10 minutes (versus 0.2 seconds).
Calling printf repeatedly - 50653 times - makes the difference.

Kind of a memory-time tradeoff.

Regards, Mike Jonkmans

-- 
Mike Jonkmans <bashbug@jonkmans.nl>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]