Sponsored Content
Top Forums Shell Programming and Scripting README: Factorial quick chart with sed & bc: Post 302766965 by rveri on Wednesday 6th of February 2013 02:08:07 AM
Old 02-06-2013
README: Factorial quick chart with sed & bc:

Hi all,
While doing some checks I found a kind of interesting arithmetic factorial chart with sed, sharing this may be simple but thought to share,



Code:
# n=20;for i in `seq $n`;do printf "`seq $i|xargs|sed 's/ /*/g'`= ";echo "`seq $i|xargs|sed 's/ /*/g'`"| bc;done
1= 1
1*2= 2
1*2*3= 6
1*2*3*4= 24
1*2*3*4*5= 120
1*2*3*4*5*6= 720
1*2*3*4*5*6*7= 5040
1*2*3*4*5*6*7*8= 40320
1*2*3*4*5*6*7*8*9= 362880
1*2*3*4*5*6*7*8*9*10= 3628800
1*2*3*4*5*6*7*8*9*10*11= 39916800
1*2*3*4*5*6*7*8*9*10*11*12= 479001600
1*2*3*4*5*6*7*8*9*10*11*12*13= 6227020800
1*2*3*4*5*6*7*8*9*10*11*12*13*14= 87178291200
1*2*3*4*5*6*7*8*9*10*11*12*13*14*15= 1307674368000
1*2*3*4*5*6*7*8*9*10*11*12*13*14*15*16= 20922789888000
1*2*3*4*5*6*7*8*9*10*11*12*13*14*15*16*17= 355687428096000
1*2*3*4*5*6*7*8*9*10*11*12*13*14*15*16*17*18= 6402373705728000
1*2*3*4*5*6*7*8*9*10*11*12*13*14*15*16*17*18*19= 121645100408832000
1*2*3*4*5*6*7*8*9*10*11*12*13*14*15*16*17*18*19*20= 2432902008176640000
# n=20;for i in `seq $n -1 1`;do printf "`seq $i|xargs|sed 's/ /*/g'`= ";echo "`seq $i|xargs|sed 's/ /*/g'`"| bc;done
1*2*3*4*5*6*7*8*9*10*11*12*13*14*15*16*17*18*19*20= 2432902008176640000
1*2*3*4*5*6*7*8*9*10*11*12*13*14*15*16*17*18*19= 121645100408832000
1*2*3*4*5*6*7*8*9*10*11*12*13*14*15*16*17*18= 6402373705728000
1*2*3*4*5*6*7*8*9*10*11*12*13*14*15*16*17= 355687428096000
1*2*3*4*5*6*7*8*9*10*11*12*13*14*15*16= 20922789888000
1*2*3*4*5*6*7*8*9*10*11*12*13*14*15= 1307674368000
1*2*3*4*5*6*7*8*9*10*11*12*13*14= 87178291200
1*2*3*4*5*6*7*8*9*10*11*12*13= 6227020800
1*2*3*4*5*6*7*8*9*10*11*12= 479001600
1*2*3*4*5*6*7*8*9*10*11= 39916800
1*2*3*4*5*6*7*8*9*10= 3628800
1*2*3*4*5*6*7*8*9= 362880
1*2*3*4*5*6*7*8= 40320
1*2*3*4*5*6*7= 5040
1*2*3*4*5*6= 720
1*2*3*4*5= 120
1*2*3*4= 24
1*2*3= 6
1*2= 2
1= 1
#

Just replace the value of n , to the desired factorial and it ll construct the chart. Below is an example of factorial 20 's chart:
Code:
n=20;for i in `seq $n`;do printf "`seq $i|xargs|sed 's/ /*/g'`= ";echo "`seq $i|xargs|sed 's/ /*/g'`"| bc;done


Enjoy!. Have fun!.

Last edited by rveri; 02-06-2013 at 03:13 AM..
These 2 Users Gave Thanks to rveri For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

a quick SED question

I have a line EXTDIR=`echo $i | sed 's/\-tar.gz//'` which looks for files ending in -tar.gz, i would like to increase the functionality so that it looks for .tar.gz files as well as -tar.gz. Do i put the - in square brackets with a dot ? like this EXTDIR=`echo $i | sed 's/\tar.gz//'` ... (1 Reply)
Discussion started by: hcclnoodles
1 Replies

2. Shell Programming and Scripting

quick sed question

hey, Im just wondering is there away to get sed to read from a variable eg it doesn't seem to work, i really need to be able to recursively change the same data set... (2 Replies)
Discussion started by: vbm
2 Replies

3. Shell Programming and Scripting

quick sed help

what's the code for delete everything before sssss asdf become: (3 Replies)
Discussion started by: katrvu
3 Replies

4. Shell Programming and Scripting

I can't figure this out? Quick help with sed

I am trying to delete everything in the parenthesis(including the parenthesis) in this text: Wind: from the WNW (290 degrees) at 6 MPH (5 KT) Pressure (altimeter): 29.82 in. Hg (1009 hPa) Temperature: 80.1 F (26.7 C) Dew Point: 72.0 F (22.2 C) Relative Humidity: 76% Trying to make it look... (3 Replies)
Discussion started by: pmoore4321
3 Replies

5. Shell Programming and Scripting

sed & areas respectively sed & pyramiding

Hello everyone, i wonder if someone could give me an advice regarding the following problem using sed. Given ist a structure as shown below: <aaa>text1<b>text2</b>text3<c>text4</c>text5</aaa> Now I want to change the outer tag from "aaa" to "new" and replace all tags inside the outer tags... (4 Replies)
Discussion started by: Donaldinho
4 Replies

6. AIX

README: Install tripwire on AIX

We had a SAS70 audit at our site a few months back and part of the end result was that I had to install tripwire to monitor our application binaries. We were able to compile tripwire for our AIX 5.3 server but after a few months I was asked to install it on other systems. I could have and did just... (1 Reply)
Discussion started by: juredd1
1 Replies

7. Programming

Quick question about '_&'

I've seen in other programmers code the use of '_&' as a line separator. I am trying to find in my C++ reference manual some pages dedicated to an explanation of the use of this '_&' but I don't know what it is called. I only know it is a "line separator" or "line break" of some sort which is... (0 Replies)
Discussion started by: sepoto
0 Replies

8. Shell Programming and Scripting

Factorial of any number using functions

how to write the code for factorial of any number using functions and arguments????? (7 Replies)
Discussion started by: kullu
7 Replies

9. Shell Programming and Scripting

Quick Sed Question

Just want to know why when I do the following in sed, the required is not extracted. echo "ab01cde234" | sed 's/*$//' result: ab01cde (Which is correct) echo "ab01cde234" |sed 's/.*\(*\)$/\1/' result: blank (was expecting 234) or echo "ab01cde234" |sed 's/.*\(\)*$/\1/' result: blank... (6 Replies)
Discussion started by: eo29
6 Replies

10. Shell Programming and Scripting

awk Help: quick and easy question may be: How to use &&

Hi Guru's. I am trying to use to check if $5 is greater than 80 & if not 100, then to print $0 : awk '{ if ($5>80) && if ($5 != 100) print $0} But getting error: >bdf1|sed 's/%//g'|awk '{ if ($5>80) && if ($5 != 100) print $0}' syntax error The source line is 1. The error... (6 Replies)
Discussion started by: rveri
6 Replies
Bio::Factory::SequenceFactoryI(3pm)			User Contributed Perl Documentation		       Bio::Factory::SequenceFactoryI(3pm)

NAME
Bio::Factory::SequenceFactoryI - This interface allows for generic building of sequences in factories which create sequences (like SeqIO) SYNOPSIS
# do not use this object directly it is an interface # get a Bio::Factory::SequenceFactoryI object like use Bio::Seq::SeqFactory; my $seqbuilder = Bio::Seq::SeqFactory->new('-type' => 'Bio::PrimarySeq'); my $seq = $seqbuilder->create(-seq => 'ACTGAT', -display_id => 'exampleseq'); print "seq is a ", ref($seq), " "; DESCRIPTION
A generic way to build Sequence objects via a pluggable factory. This reduces the amount of code that looks like if( $type eq 'Bio::PrimarySeq' ) { ... } elsif( $type eq 'Bio::Seq::RichSeq' ) { ... } FEEDBACK
Mailing Lists User feedback is an integral part of the evolution of this and other Bioperl modules. Send your comments and suggestions preferably to the Bioperl mailing list. Your participation is much appreciated. bioperl-l@bioperl.org - General discussion http://bioperl.org/wiki/Mailing_lists - About the mailing lists Support Please direct usage questions or support issues to the mailing list: bioperl-l@bioperl.org rather than to the module maintainer directly. Many experienced and reponsive experts will be able look at the problem and quickly address it. Please include a thorough description of the problem with code and data examples if at all possible. Reporting Bugs Report bugs to the Bioperl bug tracking system to help us keep track of the bugs and their resolution. Bug reports can be submitted via the web: https://redmine.open-bio.org/projects/bioperl/ AUTHOR - Jason Stajich Email jason-at-bioperl.org APPENDIX
The rest of the documentation details each of the object methods. Internal methods are usually preceded with a _ create Title : create Usage : my $seq = $seqbuilder->create(-seq => 'CAGT', -id => 'name'); Function: Instantiates new Bio::PrimarySeqI (or one of its child classes) This object allows us to genericize the instantiation of sequence objects. Returns : Bio::PrimarySeqI Args : initialization parameters specific to the type of sequence object we want. Typically -seq => $str, -display_id => $name perl v5.14.2 2012-03-02 Bio::Factory::SequenceFactoryI(3pm)
All times are GMT -4. The time now is 05:44 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy