text:
Generate fractals from bit patterns in ASCII
Overview
Write a program that prints out simple fractal patterns given a bit pattern encoding the fractal, plus the per-generation scale factor of the fractal and number of generations.
Explanation
Here is an ASCII representation of the Sierpinski Carpet:
Generation 0:
#

Generation 1:
# # #
#   #
# # #

Generation 2:
# # # # # # # # #
#   # #   # #   #
# # # # # # # # #
# # #       # # #
#   #       #   #
# # #       # # #
# # # # # # # # #
#   # #   # #   #
# # # # # # # # #

Generation n+1 of the ASCII Sierpinski Carpet is made up of a 3x3 grid containing 8 copies of generation n, with the central element of the grid missing.
So, because it is defined using a 3x3 grid and gets 3 times bigger in width and height each generation, we can say it has a scale factor of 3.
We could define a bit pattern for the Sierpinski carpet by numbering the elements in the 3x3 grid from 0 to 8, top-to-bottom, left-to-right, and setting the corresponding bit of an integer if generation n+1 contains a copy of generation n at that grid position:
bit:       place value:   bit pattern:   bit value:

0 1 2      1    2    4    1 1 1          1    2    4
3 4 5      8   16   32    1 0 1          8    0   32
6 7 8      64 128  256    1 1 1          64 128  256

integer value = 1 + 2 + 4 + 8 + 32 + 64 + 128 + 256 = 495

For a scale factor of 2, the bit pattern would be arranged like this:
0 1
2 3

and so on.
Your task is to write a program that accepts a bit pattern in this form, a scale factor (e.g. 3 for the Sierpinski Carpet) and a generation number and outputs an ASCII fractal.
Input
Your program should accept 3 integers in the following order: a bit pattern, a scale factor (ranging from 2 to 5, inclusive) and a generation count (ranging from 0 to 5, inclusive).
You do not need to perform any input validation on these values and it's perfectly fine if the program works for values larger than the ranges specified.
The inputs can be passed in any form (tuples, comma/space-separated list, etc)
Output
The program should output a fractal made up of the # character followed by a space in positions where the fractal is defined, double-spaces where it is not, and a newline character at the end of each line, either printing them out or returning a string from a function.
Examples
Input:
495,3,3

Output (Sierpinski Carpet generation 3):
# # # # # # # # # # # # # # # # # # # # # # # # # # #
#   # #   # #   # #   # #   # #   # #   # #   # #   #
# # # # # # # # # # # # # # # # # # # # # # # # # # #
# # #       # # # # # #       # # # # # #       # # #
#   #       #   # #   #       #   # #   #       #   #
# # #       # # # # # #       # # # # # #       # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # #
#   # #   # #   # #   # #   # #   # #   # #   # #   #
# # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # #                   # # # # # # # # #
#   # #   # #   #                   #   # #   # #   #
# # # # # # # # #                   # # # # # # # # #
# # #       # # #                   # # #       # # #
#   #       #   #                   #   #       #   #
# # #       # # #                   # # #       # # #
# # # # # # # # #                   # # # # # # # # #
#   # #   # #   #                   #   # #   # #   #
# # # # # # # # #                   # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # #
#   # #   # #   # #   # #   # #   # #   # #   # #   #
# # # # # # # # # # # # # # # # # # # # # # # # # # #
# # #       # # # # # #       # # # # # #       # # #
#   #       #   # #   #       #   # #   #       #   #
# # #       # # # # # #       # # # # # #       # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # #
#   # #   # #   # #   # #   # #   # #   # #   # #   #
# # # # # # # # # # # # # # # # # # # # # # # # # # #

Input:
7,2,5

Output (Sierpinski Triangle):
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#   #   #   #   #   #   #   #   #   #   #   #   #   #   #   #
# #     # #     # #     # #     # #     # #     # #     # #
#       #       #       #       #       #       #       #
# # # #         # # # #         # # # #         # # # #
#   #           #   #           #   #           #   #
# #             # #             # #             # #
#               #               #               #
# # # # # # # #                 # # # # # # # #
#   #   #   #                   #   #   #   #
# #     # #                     # #     # #
#       #                       #       #
# # # #                         # # # #
#   #                           #   #
# #                             # #
#                               #
# # # # # # # # # # # # # # # #
#   #   #   #   #   #   #   #
# #     # #     # #     # #
#       #       #       #
# # # #         # # # #
#   #           #   #
# #             # #
#               #
# # # # # # # #
#   #   #   #
# #     # #
#       #
# # # #
#   #
# #
#

Input:
325,3,3

Output (Cantor Dust):
#   #       #   #                   #   #       #   #

#   #       #   #                   #   #       #   #

#   #       #   #                   #   #       #   #

#   #       #   #                   #   #       #   #

#   #       #   #                   #   #       #   #

#   #       #   #                   #   #       #   #

#   #       #   #                   #   #       #   #

#   #       #   #                   #   #       #   #

Input
186,3,3

Output (Vicsek fractal):
                          #
                        # # #
                          #
                    #     #     #
                  # # # # # # # # #
                    #     #     #
                          #
                        # # #
                          #
        #                 #                 #
      # # #             # # #             # # #
        #                 #                 #
  #     #     #     #     #     #     #     #     #
# # # # # # # # # # # # # # # # # # # # # # # # # # #
  #     #     #     #     #     #     #     #     #
        #                 #                 #
      # # #             # # #             # # #
        #                 #                 #
                          #
                        # # #
                          #
                    #     #     #
                  # # # # # # # # #
                    #     #     #
                          #
                        # # #
                          #

Input:
279,3,3

Output (example of an asymmetrical fractal):
# # # # # # # # # # # # # # # # # # # # # # # # # # #
  #     #     #     #     #     #     #     #     #
    #     #     #     #     #     #     #     #     #
      # # #             # # #             # # #
        #                 #                 #
          #                 #                 #
            # # #             # # #             # # #
              #                 #                 #
                #                 #                 #
                  # # # # # # # # #
                    #     #     #
                      #     #     #
                        # # #
                          #
                            #
                              # # #
                                #
                                  #
                                    # # # # # # # # #
                                      #     #     #
                                        #     #     #
                                          # # #
                                            #
                                              #
                                                # # #
                                                  #
                                                    #

etc.
Notes:

This is code-golf so the shortest answer in bytes wins
Your program can be either a stand-alone or a function that is called with the 3 input parameters and returns (or prints) a string
Generation 0 is defined as # (a # followed by a space) even for a bit pattern of 0.
A trailing newline on the last line is optional but permitted, as is any amount of trailing white-space on each line.

+1, I liked this in sandbox and I like it more here, with the symbol changed from "##" to "# ". I see the one trailing space at end of line is included in your examples, is it required? . Per the last rule I would assume it's optional, but the fact that you require a trailing space for generation 0 makes me wonder. Also I think you should indicate the max whitespace and newlines (you have it plural) allowed. As an extreme example I could always start with an array of 5^6=15625 lines of 2*5^6 spaces then substitute the #s. In most input cases that's an enormous amount of unused whitespace

@steveverrill I don't require the trailing space when outputting generation 0, however the trailing space is part of its definition, which subsequent generations are defined in terms of. The plural of newlines was a typo, fixed.

Could you post the expected output for something less symmetric, such as 279,3,3?

@aditsu sure, see edited question

APL (Dyalog Unicode), 37 bytesSBCS
'# '{⊃⍪/,/⍺\⍤1⊂⍉⍪⍉⍵}⍣⎕⍨(2⍴⎕)⍴⌽⎕⊤⍨99⍴2
                              ⎕       ⍝ input the bit pattern
                               ⊤⍨99⍴2 ⍝ decode 99 binary digits from it
                                      ⍝  (53 is the limit for floating point)
                             ⌽        ⍝ reverse, least significant bit goes first
                          ⎕           ⍝ input the scale factor
                       (2⍴ )          ⍝ twice, to use as dimensions of a matrix
                            ⍴         ⍝ reshape bit pattern into such a matrix
                     ⎕                ⍝ input the number of generations
'# '{              }⍣ ⍨               ⍝ apply that many times, starting from '# '
               ⍉⍪⍉⍵                   ⍝ make sure the argument is a matrix
              ⊂                       ⍝ enclose
          ⍺\⍤1                        ⍝ expand using rows of bit-pattern matrix
                                      ⍝  (1 for identical copy, 0 for zeroed out)
     ⊃⍪/,/                            ⍝ concat all horizontally and vertically

Try it online!

Common Lisp, 248 242 bytes
(lambda(n r g &aux(s(expt r g)))(labels((f(g x y s)(or(= g 0)(#2=multiple-value-bind(q x)(floor x s)(#2#(p y)(floor y s)(if(logbitp(+ q(* p r))n)(f(1- g)x y(/ s r))))))))(#3=dotimes(y s)(#3#(x s)(princ(if(f g x y(/ s r))"# ""  ")))(terpri))))

Ungolfed
(defun fractal (n r g &aux (s (expt r g)))
  (labels((f(g x y s)
            (or(= g 0)
               (multiple-value-bind (px x) (truncate x s)
                 (multiple-value-bind (py y) (truncate y s)
                   (and
                    (logbitp (+ px (* py r)) n)
                    (f (1- g) x y (/ s r))))))))
    (fresh-line)
    (dotimes(y s)
      (dotimes(x s)
        (princ
         (if (f g x y(/ s r))
             "# "
             "  ")))
      (terpri))))

Explanation

Input:

N is the encoded pattern
R is the size of the pattern
G is the generation

The output is an implicit square matrix of length S=RG
We iterate over each row y, column x (nested dotimes) and compute whether each cell should be drawn (raycasting-like approach). This is done by recursively looking inside the fractal with the f auxiliary function.
If the fractal at position (x,y) shall be drawn, print "# ", or else print "  ". Of course we also print newlines at the end of each row.

For example, Sierpinsky's triangle is represented by S=7 and R=2. At generation 3 the square size is 23=8. For each cell (x,y), the following happen:

f is called with x, y, g bound to 3 and s bound to 4 (8/2)
We truncate x by s, in order to know if x belongs to the left or right side of the implicit matrix. truncate returns both the quotient and the remainder, which are bound respectively to px and x (we reuse the same symbol x, but this not a problem).
The same goes for y which gives py and new y.
In this example, px and py can be either 0 or 1 (because the pattern is a square of length 2). They identify where is (x,y) in the fractal's pattern: when the bit at position py.R + px of N is 0, x and y represent a position where nothing should be drawn.
Otherwise, we must "zoom" into the corresponding part of the fractal and we call f recursively with the new bindings for x and y. Those are now the relative position inside the inner fractal. We pass G-1 for the generation and s/2 to represent the half-length of the fractal.
The base case of the recursion is encountered when G is zero, in which case the current (x,y) position should be drawn.

Example
(fractal 186 3 3)

                          #
                        # # #
                          #
                    #     #     #
                  # # # # # # # # #
                    #     #     #
                          #
                        # # #
                          #
        #                 #                 #
      # # #             # # #             # # #
        #                 #                 #
  #     #     #     #     #     #     #     #     #
# # # # # # # # # # # # # # # # # # # # # # # # # # #
  #     #     #     #     #     #     #     #     #
        #                 #                 #
      # # #             # # #             # # #
        #                 #                 #
                          #
                        # # #
                          #
                    #     #     #
                  # # # # # # # # #
                    #     #     #
                          #
                        # # #
                          #

Computing the 8th generation of the Sierpinski Carpet using (fractal 495 3 8) takes 24.7 seconds and generates an output text file of 83 MB. I wrote a slightly modifed version which outputs an image. For the same parameters, the GIF file weights 1.5MB (same computation time):

Vicsek (click to see original size):

+1 for what looks like a concise program in a horribly verbose language. 8 nested ) in a row!

@steveverrill I never win code golfs... but still, I think the syntax pays off for larger programs. And honestly, I almost do not see parenthesis anymore, just a nice tree.

That gif image actually crashes my phone's web browser... Great golfing with a more unusual language

@HiGuy Thanks. Does CodeGolf has a badge for making other people's browser crash? It should :-)

Pyth, 38 bytes
VJ^UQvwjdm@" #".A@L_.[0^Q2jvz2+V*RQNdJ

Try it online: Regular Input / Test Suite
Explanation follows later.

1+ I am still waiting for the output of 186 3 5 (online interpreter), but apart from that I am truly impressed by how short this is.

@coredump I don't think you'll get such a big output using the online interpreter. If you want to test it, you would have to download the Pyth compiler. It takes about 10 seconds on my laptop.

Ruby,154
Score is for the function only. Presented ungolfed below in test program. The only golfing I'm claiming at the moment is removal of comments and indents. I will golf later. At the moment, I'm having fun playing with the program.
The function takes six arguments, but on the initial call only the first 3 are provided per the spec. This causes the three remaining arguments to be set to default values, and in particular the string a where the output is stored is created and initialized to lines of spaces terminated by newlines. As a side effect the global variable $w is also created, indicating the number of symbols per line.
When the function calls itself recursively, it provides all six arguments, including the string a and the x and y coordinates of the top left corner of the next recursion
The rest of the program is pretty straightforward, as indicated in the comments.
#function
f=->b,s,g,x=0,y=0,a=(' '*(-1+2*$w=s**g)+'
')*$w{                                         #accept arguments, if x,y,a are not provided create them. $w = number of symbols per row
  v=s**g/s                                     #v=width of blocks for this recursion depth
  if g==0
    a[2*y*$w+2*x]=?#                           #if g==0 plot a #
  else                                         #else iterate s*s times through the bits of b, and recurse as necessary
    (s*s).times{|i|b>>i&1>0&&f.call(b,s,g-1,x+i%s*v,y+i/s*v,a)}
  end
  a
}

#test program (requires 3 input numbers separated by newlines)
b=gets.to_i
s=gets.to_i
g=gets.to_i
#get return value and output to stdout
puts f.call(b,s,g)

Output
Here's a set of fractals loosely based on the form of the letters of the word GOLF. More realistic letters could be achieved with larger bitmaps. As the last example shows, the most interesting fractals are discovered by accident.
63775,4,2 (G)

# # # # # # # # # # # # # # # #
#       #       #       #
#     # #     # #     # #     #
# # # # # # # # # # # # # # # #
# # # #
#
#     #
# # # #
# # # #                 # # # #
#                       #
#     #                 #     #
# # # #                 # # # #
# # # # # # # # # # # # # # # #
#       #       #       #
#     # #     # #     # #     #
# # # # # # # # # # # # # # # #

495,3,3 (O, sierpinski carpet)

# # # # # # # # # # # # # # # # # # # # # # # # # # #
#   # #   # #   # #   # #   # #   # #   # #   # #   #
# # # # # # # # # # # # # # # # # # # # # # # # # # #
# # #       # # # # # #       # # # # # #       # # #
#   #       #   # #   #       #   # #   #       #   #
# # #       # # # # # #       # # # # # #       # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # #
#   # #   # #   # #   # #   # #   # #   # #   # #   #
# # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # #                   # # # # # # # # #
#   # #   # #   #                   #   # #   # #   #
# # # # # # # # #                   # # # # # # # # #
# # #       # # #                   # # #       # # #
#   #       #   #                   #   #       #   #
# # #       # # #                   # # #       # # #
# # # # # # # # #                   # # # # # # # # #
#   # #   # #   #                   #   # #   # #   #
# # # # # # # # #                   # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # #
#   # #   # #   # #   # #   # #   # #   # #   # #   #
# # # # # # # # # # # # # # # # # # # # # # # # # # #
# # #       # # # # # #       # # # # # #       # # #
#   #       #   # #   #       #   # #   #       #   #
# # #       # # # # # #       # # # # # #       # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # #
#   # #   # #   # #   # #   # #   # #   # #   # #   #
# # # # # # # # # # # # # # # # # # # # # # # # # # #

457,3,3 (L)

#
#
# # #
#
#
# # #
#     #     #
#     #     #
# # # # # # # # #
#
#
# # #
#
#
# # #
#     #     #
#     #     #
# # # # # # # # #
#                 #                 #
#                 #                 #
# # #             # # #             # # #
#                 #                 #
#                 #                 #
# # #             # # #             # # #
#     #     #     #     #     #     #     #     #
#     #     #     #     #     #     #     #     #
# # # # # # # # # # # # # # # # # # # # # # # # # # #

7967,4,2 (F)

# # # # # # # # # # # # # # # #
#       #       #       #
# # # # # # # # # # # # # # # #
#       #       #       #
# # # #
#
# # # #
#
# # # # # # # # # # # # # # # #
#       #       #       #
# # # # # # # # # # # # # # # #
#       #       #       #
# # # #
#
# # # #
#

1879,3,3 (skull and crossbones discovered by accident)

# # # # # # # # # # # # # # # # # # # # # # # # # # #
  #     #     #     #     #     #     #     #     #
#   # #   # #   # #   # #   # #   # #   # #   # #   #
      # # #             # # #             # # #
        #                 #                 #
      #   #             #   #             #   #
# # #       # # # # # #       # # # # # #       # # #
  #           #     #           #     #           #
#   #       #   # #   #       #   # #   #       #   #
                  # # # # # # # # #
                    #     #     #
                  #   # #   # #   #
                        # # #
                          #
                        #   #
                  # # #       # # #
                    #           #
                  #   #       #   #
# # # # # # # # #                   # # # # # # # # #
  #     #     #                       #     #     #
#   # #   # #   #                   #   # #   # #   #
      # # #                               # # #
        #                                   #
      #   #                               #   #
# # #       # # #                   # # #       # # #
  #           #                       #           #
#   #       #   #                   #   #       #   #

CJam, 45
3aaq~@2b2$_*0e[W%@/a*{ffff*:.+:.+}/' ff+Sf*N*

Implementation of my first idea. Try it online
Basically, it starts with a 1*1 matrix containing 3 (the difference between '#' and ' '), then repeatedly multiplies each number in the matrix with the bit pattern (0/1 matrix), and combines the resulting matrices into one bigger matrix. At the end, it adds a space to each number, and joins with spaces and newlines.
2nd idea, 49
q~@2bW%2$/z@@m*_,\_m*:z@f{3@@f{\~@==*}~' +}/Sf*N*

Try it online
This generates all the coordinates of the output matrix as arrays of <generation count> pairs of numbers smaller than the scale factor (all such combinations), then for each pair of numbers it gets the corresponding bit from the pattern, and for each coordinate array it multiplies the bits and multiplies by 3. The final processing is the same.
There's probably room for more golfing.

C, 316 bytes
main(a,_,b,s,g,i,w,o,z,x,y)char**_,*o;{b=atoi(_[1]);s=atoi(_[2]);g=atoi(_[3]);w=1;for(i=0;i<g;++i){w*=s;}o=malloc(w*w);for(i=0;i<w*w;++i)o[i]=35;z=w/s;while(z){for(y=0;y<w;++y)for(x=0;x<w;++x)if(!((b>>((y/z)%s*s+(x/z)%s))&1))o[y*w+x]=32;z/=s;}for(y=0;y<w;++y){for(x=0;x<w;++x)printf("%c ",o[y*w+x]);printf("\n");}}

Un-golfed:
#include <stdio.h>

int main(int argc, char *argv[])
{
    int bitpattern;
    int scale;
    int generation;

    bitpattern = atoi(argv[1]);
    scale = atoi(argv[2]);
    generation = atoi(argv[3]);

    int i;
    int width = 1;
    for (i=0; i<generation; ++i) {width*=scale;}

    char *out=malloc(width*width);

    for (i=0; i<width*width; ++i) out[i]='#';

    int blocksize = width/scale;
    for (i=0; i<generation; ++i) {
        int x,y;
        for (y=0; y<width; ++y) {
            for (x=0; x<width; ++x) {
                int localX = x/blocksize;
                localX %= scale;
                int localY = y/blocksize;
                localY %= scale;
                int localPos = localY*scale+localX;
                if (!((bitpattern>>localPos)&1))out[y*width+x]=' ';
            }
        }
        blocksize/=scale;
    }

    int x,y;
    for (y=0; y<width; ++y) {
        for (x=0; x<width; ++x)
            printf("%c ",out[y*width+x]);
        printf("\n");
    }
    return 0;
}

According to the bullet points at the end of the spec a function is allowed instead of a program. Change it to a function and just pass the three input parameters to it - that would get rid of all that atoi stuff and save you about 40 bytes.

200 bytes

Scala 293 299
(e:Int,s:Int,g:Int)=>{def b(x:Int,y:Int)=(1<<x*s+y&e)>0;def f(n:Int):Seq[Seq[Char]]=if(n<1)Seq(Seq('#'))else if(n<2)Seq.tabulate(s,s)((i,j)=>if(b(i,j))'#'else' ')else{val k=f(n-1);val t=k.size;Seq.tabulate(t*s,t*s)((i,j)=>if(b(i/t,j/t))k(i%t)(j%t)else' ')};f(g).map(_.mkString(" ")).mkString(" \n")}

ungolfed:
//create an anonymous function
(encoded: Int, size: Int, generation: Int) => {

  // method will return true if coords (x,y) should be drawn as '#'
  def isBlackInPattern(x: Int, y: Int): Boolean = (1 << x * size + y & encoded) > 0

  // recurse until generation is 1
  def fillRecursively(gen: Int): Seq[Seq[Char]] = {

    // this is just to satisfy OP requirements.
    // if the stopping condition were generation = 1,
    // I could have spared this line...
    if(gen < 1) Seq(Seq('#'))

    //actual stopping condition (generation 1).
    // fill a matrix of characters with spaces
    // and hashes acording to the pattern.
    else if(gen < 2) Seq.tabulate(size, size)((i, j) =>
      if (isBlackInPattern(i,j)) '#'
      else ' '
    )

    // recurse, and use previously created fractals to fill
    // the current generation according to the `isBlackInPattern` condition
    else {
      val previousGeneration = fillRecursively(gen-1)
      val previousSize = previousGeneration.size
      // create the current matrix and fill it
      Seq.tabulate(previousSize*size,previousSize*size)((i,j)=>
        if(isBlackInPattern(i/previousSize,j/previousSize))
          previousGeneration(i%t)(j%t)
        else ' '
      )
    }
  }
  // call to recursive function and format matrix of characters to string
  fillRecursively(generation).map(_.mkString(" ")).mkString(" \n")
}

examples:
val f = (e:Int,s:Int,g:Int)=>{def b(x:Int,y:Int)=(1<<x*s+y&e)>0;def f(n:Int):Seq[Seq[Char]]=if(n<1)Seq(Seq('#'))else if(n<2)Seq.tabulate(s,s)((i,j)=>if(b(i,j))'#'else' ')else{val k=f(n-1);val t=k.size;Seq.tabulate(t*s,t*s)((i,j)=>if(b(i/t,j/t))k(i%t)(j%t)else' ')};f(g).map(_.mkString(" ")).mkString(" \n")}
f: (Int, Int, Int) => String = <function3>

scala> println(f(495,3,3))
# # # # # # # # # # # # # # # # # # # # # # # # # # #
#   # #   # #   # #   # #   # #   # #   # #   # #   #
# # # # # # # # # # # # # # # # # # # # # # # # # # #
# # #       # # # # # #       # # # # # #       # # #
#   #       #   # #   #       #   # #   #       #   #
# # #       # # # # # #       # # # # # #       # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # #
#   # #   # #   # #   # #   # #   # #   # #   # #   #
# # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # #                   # # # # # # # # #
#   # #   # #   #                   #   # #   # #   #
# # # # # # # # #                   # # # # # # # # #
# # #       # # #                   # # #       # # #
#   #       #   #                   #   #       #   #
# # #       # # #                   # # #       # # #
# # # # # # # # #                   # # # # # # # # #
#   # #   # #   #                   #   # #   # #   #
# # # # # # # # #                   # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # #
#   # #   # #   # #   # #   # #   # #   # #   # #   #
# # # # # # # # # # # # # # # # # # # # # # # # # # #
# # #       # # # # # #       # # # # # #       # # #
#   #       #   # #   #       #   # #   #       #   #
# # #       # # # # # #       # # # # # #       # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # #
#   # #   # #   # #   # #   # #   # #   # #   # #   #
# # # # # # # # # # # # # # # # # # # # # # # # # # #

scala> println(f(7,2,5))
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#   #   #   #   #   #   #   #   #   #   #   #   #   #   #   #
# #     # #     # #     # #     # #     # #     # #     # #
#       #       #       #       #       #       #       #
# # # #         # # # #         # # # #         # # # #
#   #           #   #           #   #           #   #
# #             # #             # #             # #
#               #               #               #
# # # # # # # #                 # # # # # # # #
#   #   #   #                   #   #   #   #
# #     # #                     # #     # #
#       #                       #       #
# # # #                         # # # #
#   #                           #   #
# #                             # #
#                               #
# # # # # # # # # # # # # # # #
#   #   #   #   #   #   #   #
# #     # #     # #     # #
#       #       #       #
# # # #         # # # #
#   #           #   #
# #             # #
#               #
# # # # # # # #
#   #   #   #
# #     # #
#       #
# # # #
#   #
# #
#

scala> println(f(18157905,5,2))
#       #                               #       #
  #   #                                   #   #
    #                                       #
  #   #                                   #   #
#       #                               #       #
          #       #           #       #
            #   #               #   #
              #                   #
            #   #               #   #
          #       #           #       #
                    #       #
                      #   #
                        #
                      #   #
                    #       #
          #       #           #       #
            #   #               #   #
              #                   #
            #   #               #   #
          #       #           #       #
#       #                               #       #
  #   #                                   #   #
    #                                       #
  #   #                                   #   #
#       #                               #       #

first cut, probably can be golfed a bit further...

You are missing a space between each of your #'s. Besides being required by the spec, it really enhances the appearance of your output.

@steveverrill your'e right. I didn't noticed that at first. I edited with a quick fix. thanks :)

Matlab, 115 bytes
The Kronecker kron product makes everything much easier:
function f(p,f,g);z=nan(f);z(:)=de2bi(p,f*f);x=3;for k=1:g;x=kron(x,z);end;disp([reshape([x;0*x],f^g,2*f^g)+32,''])

# # # # # # # # # # # # # # # # # # # # # # # # # # #
#   # #   # #   # #   # #   # #   # #   # #   # #   #
# # # # # # # # # # # # # # # # # # # # # # # # # # #
# # #       # # # # # #       # # # # # #       # # #
#   #       #   # #   #       #   # #   #       #   #
# # #       # # # # # #       # # # # # #       # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # #
#   # #   # #   # #   # #   # #   # #   # #   # #   #
# # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # #                   # # # # # # # # #
#   # #   # #   #                   #   # #   # #   #
# # # # # # # # #                   # # # # # # # # #
# # #       # # #                   # # #       # # #
#   #       #   #                   #   #       #   #
# # #       # # #                   # # #       # # #
# # # # # # # # #                   # # # # # # # # #
#   # #   # #   #                   #   # #   # #   #
# # # # # # # # #                   # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # #
#   # #   # #   # #   # #   # #   # #   # #   # #   #
# # # # # # # # # # # # # # # # # # # # # # # # # # #
# # #       # # # # # #       # # # # # #       # # #
#   #       #   # #   #       #   # #   #       #   #
# # #       # # # # # #       # # # # # #       # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # #
#   # #   # #   # #   # #   # #   # #   # #   # #   #
# # # # # # # # # # # # # # # # # # # # # # # # # # #

Though de2bi only works if you have the Communications Systems Toolbox. Doesn't work without it. It would need dec2bin.

It seems this toolbox is included in my standard student version, so I think this is acceptable. (Note that de2bi does not the same as dec2bin.)

C, 158 bytes
f(p,s,g,h,i,j,c){for(j=1;g--;j*=s);for(h=j;h;){h--;for(i=j;i;){i--;for(c=35,g=j/s;g;g/=s)c=!((p>>((h/g)%s*s+(i/g)%s))&1)?32:c;printf("%c ",c);}printf("\n");}}

K5, 70 bytes
It's a start:
{,/'("  ";"# ")$[z;(z-1){,/'+,/'+x@y}[(0*t;t)]/t:(2#y)#|(25#2)\x;,,1]}

In action:
{,/'("  ";"# ")$[z;(z-1){,/'+,/'+x@y}[(0*t;t)]/t:(2#y)#|(25#2)\x;,,1]}[186;3]'!4
(,"# "
 ("  #   "
  "# # # "
  "  #   ")
 ("        #         "
  "      # # #       "
  "        #         "
  "  #     #     #   "
  "# # # # # # # # # "
  "  #     #     #   "
  "        #         "
  "      # # #       "
  "        #         ")
 ("                          #                           "
  "                        # # #                         "
  "                          #                           "
  "                    #     #     #                     "
  "                  # # # # # # # # #                   "
  "                    #     #     #                     "
  "                          #                           "
  "                        # # #                         "
  "                          #                           "
  "        #                 #                 #         "
  "      # # #             # # #             # # #       "
  "        #                 #                 #         "
  "  #     #     #     #     #     #     #     #     #   "
  "# # # # # # # # # # # # # # # # # # # # # # # # # # # "
  "  #     #     #     #     #     #     #     #     #   "
  "        #                 #                 #         "
  "      # # #             # # #             # # #       "
  "        #                 #                 #         "
  "                          #                           "
  "                        # # #                         "
  "                          #                           "
  "                    #     #     #                     "
  "                  # # # # # # # # #                   "
  "                    #     #     #                     "
  "                          #                           "
  "                        # # #                         "
  "                          #                           "))


text:
Empty a Swimming Pool . . . With Only a Red Solo Cup
You have a swimming pool that is filled to the brim with water. You need to empty it, but you can't think of an efficient method. So you decide to use your red solo cup. You will repeatedly fill the cup all the way and dump it outside the pool.
Challenge
How long will it take to empty the pool?
Input
[shape of pool] [dimensions] [shape of cup] [dimensions] [speed]

shape of pool will be one of these strings: circle, triangle, or rectangle. Note that these actually refer to the 3-dimensional shapes: cylinder, triangular prism, and rectangular prism.
dimensions will be different depending on the shape.

circle: [radius] [height]. Volume = π r2 h
triangle: [base] [height] [length]. Volume = 1/2(bh) * length
rectangle: [width] [length] [height] Volume = lwh

shape of cup and dimensions work the same way. The cup can also be either a circle, triangle, or rectangle.
speed is the amount of time it takes to empty one cup full of water in seconds.

Output
The number of seconds it takes to empty the swimming pool. This can be rounded to the nearest second.
Notes

There will be no units in the input. All distance units are assumed to be the same (a shape won't have a height in inches and a width in feet).
Use 3.14 for pi.
Input will be made up of strings and floating-point numbers.
It will never rain. No water will ever be added.
You have a very steady hand. You will fill the cup exactly to the brim every time, and you will never spill any.
Once you get near the end, it will get hard to scoop up a full cup of water. You do not need to worry about this. You're very strong, so you can tilt the pool onto its side (without using up any more time).
Anytime you make a calculation, it's okay to round to the nearest hundredth. Your final answer will not need to be exact.

Test Cases
Input: triangle 10 12.25 3 circle 5 2.2 5
Output: 10
Even though there is less than 172.7 left on the last scoop, it still takes the whole five seconds to empty it.
Input: triangle 5 87.3 20001 rectangle 5.14 2 105.623 0.2
Output: 804.2

You should round to the nearest hundredth after each calculation.
The final calculation is rounded up from 804.05567 to 804.2. This is because that last little bit of water must be emptied.

Rules

You can write a full program or function.
Input should be taken from stdin or function parameters. Output should be printed through stdout or returned.
The input format can be rearranged, as long as you specify that in the submission. You can also shorten the strings "circle", "triangle", and "rectangle."
Libraries and built-in functions that involve volume or area are not allowed.

Scoring
This is code-golf. Submission with least number of bytes wins.

You'd have problems at the end, once the level of water in the bottom of the pool was lower than the height of the cup.  At that point it would get harder and harder to get a full cup.  Should this issue be ignored?

Yes @DarrelHoffman, let's pretend you're really strong and can tilt the pool onto it's side (without using up any more time).

JavaScript ES6, 100 78 82 81 74 bytes
Thanks to @UndefinedFunction for helping golf off 4 bytes
(a,z,d,f=([a,g,k,p])=>g*k*(a[6]?p/-~!a[8]:3.14*g))=>Math.ceil(f(a)/f(z))*d

Usage:
t(["triangle",10,12.25,3],["circle",5,2.2],5);

Rather than .5*v, couldn't you do v/2?

@AlexA. oh yeah... completely forgot about that

@vihan What happens if the pool volume is an exact multiple of the cup volume, like in t(["triangle", [10, 12.25, 3]], ["triangle", [10, 12.25, 3]], 5)? I get 10 but shouldn't the answer be 5? EDIT: just beaten by edc65, same problem.

Have a look at my solution, I can't post it because it's way too similar to yours... f=(p,c,s,v=([s,a,b,c])=>s<'r'?a*a*b*3.14:a*b*c/(s<'t'?1:2))=>Math.ceil(v(p)/v(c))*s

@edc65 I think this should work now. -~ had issues with the decimal numbers and would result in rounding up an extra step. I've had to add a<'t'?1:2 because (1+(a>'t')) doesn't work for some reason.

Looks good, +1. You can save 2 bytes by changing a<'r'?3.14*g*g*k:g*k*p/(a<'t'?1:2)) into g*k*(a<'r'?3.14*g:p/(a<'t'?1:2))), which will reduce it to 79 bytes!

Also, this could likely be shortened by testing for string length to determine what shape it is. For example, a[6] ? a[8] ? /* rectangle */ : /* triangle */ : /* circle */ }  See my answer for an example of this. I think this could shave off another two (a score of 77!), but haven't tested for sure yet.

Impressive! Could you get rid of the parentheses in f=([a,g,k,p]), or would that mess something up?

@ETHproductions No unfortunately, property shorthands must be enclosed because they are considered an "expression", therefore needing parenthesis

@vihan Bummer. Well, if you changed -~(f(a)/f(z)*d) to -~(f(a)/f(z))*d, would the output be perfectly legal? I'm still not an expert on the order of operations, so I don't know if this would actually work...

Starting again at doing wrong... I give up.

@edc65 really? I've rolled the edit back and I'll debug it in the morning. I've been testing with the examples in the questions.

CJam, 46 bytes
{rc:Xr~r~@'c={\_**3.14*}{r~**X't=)/}?}2*/m]r~*

Explanation:
{                                    }2*       e# Repeat two times:
 rc:X                                          e#   Read a token, take first char, assign to X
     r~r~                                      e#   Read and eval two tokens
         @'c={         }            ?          e#   If the char was 'c':
              \_*                              e#     Square the first token (radius)
                 *                             e#     Multiply by the second one (height)
                  3.14*                        e#     Multiply by 3.14
                        {          }           e#   Else:
                         r~                    e#     Read and eval a token
                           **                  e#     Multiply the three together
                             X't=)/            e#     Divide by 2 if X == 't'
                                               e# Now the two volumes are on the stack
                                        /m]    e# ceil(pool_volume / cup_volume)
                                           r~* e# Read and evaluate token (time) and multiply

Try it online.

Julia, 122 116 95 89 79 bytes
f(p,P,c,C,s)=(V(a,x)=prod(x)*(a<'d'?3.14x[1]:a>'s'?.5:1);ceil(V(p,P)/V(c,C))*s)

This assumes that only the first letter of the shape names will be given. Otherwise the solution is 6 bytes longer.
Ungolfed + explanation:
function f(p::Char, P::Array, c::Char, C::Array, s)
    # p - Pool shape (first character only)
    # P - Pool dimensions
    # c - Cup shape (first character only)
    # C - Cup dimensions
    # s - Speed

    # Define a function to compute volume
    function V(a::Char, x::Array)
        prod(x) * (a < 'd' ? 3.14x[1] : a > 's' ? 0.5 : 1)
    end

    # Return the ceiling of the number of cups in the pool
    # times the number of seconds per cup
    ceil(V(p, P) / V(c, C)) * s
end

Saved 21 bytes thanks to edc65 and 10 thanks to UndefinedFunction!

Don't you have a ceil in Julia, to use instead of floor, cutting all the check about integer result?

@edc65 How did I not see that?! Thanks, that saved 21 bytes!

Would it be possible to replace a>'s'?prod(x)/2:prod(x) with prod(x)/(a>'s'?2:1) ? (possibly even without the parentheses, I don't have a juilia ide on hand, and haven't been able to test this)

Or potentially even replacing a<'d'?3.14x[1]^2*x[2]:a>'s'?prod(x)/2:prod(x) with prod(x)*(a<'d'?3.14x[1]:a>'s'?.5:1) ? (Again, untested)

@UndefinedFunction Yep, that works! Thanks, that shaved off 10 bytes!

Python 3, 340 304 bytes
def l(Y,Z):r=Z[1]*3.14*(Z[0]**2)if Y[0]in'c'else Z[0]*Z[1]*Z[2];return r/2 if Y[0]is't'else r
def q(i):import re,math;M,L,F,C=map,list,float,math.ceil;p,d,c,g,s=re.match("(\w)\s([\d .]+)\s(\w)\s([\d .]+)\s([\d.]+)",i).groups();k=lambda j:L(M(F,j.split(' ')));d,g=k(d),k(g);return C(C(l(p,d)/l(c,g))*F(s))

Usage:
q(i)

Where i is the string of information.
Examples:

q("t 10 12.25 3 c 5 2.2 5")
q("t 5 87.3 20001 r 5.14 2 105.623 0.2")

Note: The names of the shapes have been shortened to their first letters, respectively.

You can save one byte by replacing "0.5" with ".5".

The parentheses in "(Z[0]**2)" are unnecessary. Replacing "(Z[0]**2)" with "Z[0]**2" should save 2 characters without affecting the function's results. Additionally, the space in "/2 if" (from "return r/2 if Y[0] ...) can be removed, saving one character.

I've tried this and it affected the results. @Potatomato

The changes I have proposed seem to work fine (http://repl.it/BBNh/1 shows that the same values are returned).

Javascript (ES6), 91
Taking input as strings for the shapes, arrays of numbers for the dimensions, and a single number for the speed:
(a,b,c,d,e)=>(1+(v=(y,x)=>x[0]*x[1]*(y[6]?x[2]/(y[8]?1:2):x[0]*3.14))(a,b)/v(c,d)-1e-9|0)*e

This defines an anonymous function, so to use add g= before it. Then, it can be called like alert(g("triangle", [10, 12.25, 3], "circle", [5, 2.2], 5))
Explanation:
(a,b,c,d,e)=>    //define function
                   //a = pool shape, b = pool dimensions
                   //c = cup shape, d = cup dimensions
                   //e = speed

( 1+     //part of the rounding up below

  (v=(y,x)=>       //define volume function

      x[0] * x[1] *     //multiply first 2 values of dimension by:

          (y[6] ?
               x[2] /     //if rectangle or triangle, the 3rd dimension
                   (y[8] ? 1 : 2)     //but if triangle divide by 2
                :
               x[0] * 3.14     //or if circle the radius * pi
          )    //(implicit return)

  )(a,b) / v(c,d)     //call the volume function for the pool/cup, and divide

         -1e-9 |0    //but round up the result

) * e     //and multiply by e
//(implicit return)

My original solution took a single string, and was 111 bytes long:
s=>(1+(v=x=>s[i++]*s[i++]*(s[x][6]?s[i++]/(s[x][8]?1:2):s[i-2]*3.14))((i=1)-1,s=s.split` `)/v(i++)-1e-9|0)*s[i]

This also defines an anonymous function, so to use add f= before it.
Then, it can be called like alert(f("triangle 5 87.3 20001 rectangle 5.14 2 105.623 0.2"))

F#, 217 186 184 160 bytes
Damn indentation requirements!
let e(p,P,c,C,s)=
 let V(s:string)d=
  match(s.[0],d)with
  |('c',[x;y])->3.14*x*x*y
  |('t',[x;y;z])->((x*y)/2.)*z
  |('r',[x;y;z])->x*y*z
 ceil(V p P/V c C)*s

Usage:
e("triangle",[5.;87.3;20001.],"rectangle",[5.14;2.;105.623],0.2);;

Update
Thanks to Alex for remarking on single space indentation, which F# seems to support
Managed to knock a load more off by changing from array to list types in the match statement

If you can use a single space or tab for indentation, you can get this down to 186 bytes. But what you have now is actually 211, not 217.

@AlexA.A single space works, I'll update - thanks! Why is/was it 211, not 217, when I put it in notepad, it's showing as 217 chars, and saving it to a file shows 217 too (Sorry, first golf, so could be wrong on how to calculate size)

I was counting bytes using this handy tool. Windows uses two-byte line breaks so that may explain the discrepancy.

@AlexA. Ahh, thanks, that makes sense! This version should be 180 then I guess.

Rather than x**2. can you do x*x? That sould save 2 bytes.

K5 (oK), 123 bytes
v:{((({y*3.14*x*x};{z*(x*y)%2};{x*y*z})@"ctr"?s)..:'t#1_x;(1+t:2+~"c"=s:**x)_x)};f:{{(.**|r)*_(~w=_w)+w:x%*r:v y}.v[" "\x]}

Python 2.7 306 Bytes
import math as z,re
t,m,r,w=float,map,reduce,[e.split() for e in re.split(' (?=[a-z])| (?=\d+(?:\.\d+)?$)',raw_input())]
def f(S,D):i=r(lambda x,y:x*y,D);return((i,i*.5)[S[0]=='t'],3.14*i*D[0])[S[0]=="c"]
print z.ceil(r(lambda x,y:x/y,m(lambda q:f(q[0],q[1:]),m(lambda x:[x[0]]+m(t,x[1:]),w[:-1]))))*t(*w[-1])

Takes input from stdin.
Testing it-
$ python pool.py
triangle 10 12.25 3 circle 5 2.2 5
10.0
$ python pool.py
triangle 5 87.3 20001 rectangle 5.14 2 105.623 0.2
804.2

Python 2, 222 146 139 119 103 93 bytes
Fairly straightforward implementation. Thanks to Sp3000 for the -(-n//1) trick for ceiling, which should work in all cases (i.e. haven't found an issue with it yet).
u=lambda q,k,l,m=1:k*l*[3.14*k,m][q>'c']*-~(q<'t')/2.
f=lambda a,b,c,d,s:-u(a,*c)//u(b,*d)*-s

Input should be formatted like so:
f(shape1, shape2, dimensions1, dimensions2, speed)
"Where shape1 and shape2 are one of 'c','r','t', dimensions1 is a list of the dimensions
 of the first shape, dimensions 2 is a list of the dimensions for the second shape, and
 speed is the speed of emptying in seconds."

Usage:
>>> f('t', 'r', [5, 87.3, 20001], [5.14, 2, 105.623], 0.2)
804.2
>>> f('t', 'c', [10, 12.25, 3], [5, 2.2], 5)
10.0

Ungolfed:
import math

def volume(shape, dimensions):
    out = dimensions[0] * dimensions[1]
    if shape == 'c':
        out *= 3.14 * dimensions[0]
    else:
        out *= dimensions[2]
    if shape == 't':
        out /= 2.0
    return out

def do(shape1, shape2, dimensions1, dimensions2, speed):
    volume1 = volume(shape1, dimensions1)
    volume2 = volume(shape2, dimensions2)
    return math.ceil(volume1 / volume2) * speed

Original solution, 222 bytes
This was made when the rules still needed you to input the whole word rather than a letter. I used the fact that hash(s)%5 mapped them to circle -> 2, triangle -> 3, rectangle -> 1, however if I just take one letter as input, I think I can get this shorter.
from math import*
u=lambda p,q:[[p[0]*p[1]*p[-1],3.14*p[0]**2*p[1]][1<q<3],0.5*p[0]*p[1]*p[-1]][q>2]
def f(*l):k=hash(l[0])%5;d=4-(1<k<3);v=l[1:d];r=hash(l[d])%5;g=4-(1<r<3);h=l[1+d:d+g];s=l[-1];print ceil(u(v,k)/u(h,r))*s

Usage:
>>> f('triangle',10,12.25,3,'circle',5,2.2,5)
10.0
>>> f('triangle',5,87.3,20001,'rectangle',5.14,2,105.623,0.2)
804.2

Well, if you want to cheat.. ;)

@Cyphase How is it cheating? All I did was rearrange input, which is the same as what a lot of people did here..

(Oh hey, didn't see that it was you.) I was just kidding :). I'm going to try it with customized input as well.

Python 2/3, 252 249 bytes
import re,math;i=[float(x)if re.match('[\d.]+',x)else x for x in re.sys.stdin.readline().split()]
for o in[0,[4,3][i[0]<'d']]:
 w=i[o+1]*i[o+2]*i[o+3]
 if i[o]<'d':w*=3.14*i[o+1]/i[o+3]
 if i[o]>'s':w*=.5
 a=a/w if o else w
print(math.ceil(a)*i[-1])

Usage Examples:
$ echo 'triangle 10 12.25 3 circle 5 2.2 5' | python stack_codegolf_54454.py
10.0
$ echo 'triangle 5 87.3 20001 rectangle 5.14 2 105.623 0.2' | python stack_codegolf_54454.py
804.2

The Python 2 only and Python 3 only versions are only different in how they receive input; raw_input() for Python 2 and input() for Python 3, as opposed to re.sys.stdin.readline() for the Python2/3 version.
Python 2, 240 237 bytes
import re,math;i=[float(x)if re.match('[\d.]+',x)else x for x in raw_input().split()]
for o in[0,[4,3][i[0]<'d']]:
 w=i[o+1]*i[o+2]*i[o+3]
 if i[o]<'d':w*=3.14*i[o+1]/i[o+3]
 if i[o]>'s':w*=.5
 a=a/w if o else w
print(math.ceil(a)*i[-1])

Python 3, 236 233 bytes
import re,math;i=[float(x)if re.match('[\d.]+',x)else x for x in input().split()]
for o in[0,[4,3][i[0]<'d']]:
 w=i[o+1]*i[o+2]*i[o+3]
 if i[o]<'d':w*=3.14*i[o+1]/i[o+3]
 if i[o]>'s':w*=.5
 a=a/w if o else w
print(math.ceil(a)*i[-1])

Changes:
Changed for o in[0,3if i[0]<'d'else 4]: to for o in[0,[4,3][i[0]<'d']]:. Thanks to Vioz for the inspiration :).

No, wait, never mind. That won't work, since the for loop is over [0, 3 if i[0] < 'd' else 4]. It's late (early?) :P.

Oh, I missed it :P Nevermind.

But I can use that technique in the for statement :).

Pyth - 40 39 36 35 34 bytes
Uses simple method, mapping over both containers and then reducing by division.
*h/Fmc*Ftd@,/JChd58c.318@d1Jc2PQeQ

Takes input comma separated from stdin, with the first letter of each shape like: "t", 10, 12.25, 3, "c", 5, 2.2, 5.
Test Suite.

This is SO SHORT! Awesome job! :)

source: Stack Exchange

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/

sort: votes


text:
Laplace transform of a polynomial
Your goal is to write a program that will print out the Laplace transform of a polynomial function with integer coefficients \$f(x)\$. The Laplace transform of \$f(x)\$ is defined as \$\int_0^\infty f(x) e^{-sx} dx\$.
The standard input for the polynomial function will be
a+bx+cx^2+dx^3+...

If the coefficient is zero, that term is omitted. It can be taken in from any standard type of input.
This is valid input: 1+x^2-5x^4+20x^5
These aren't:
0
1+0x
1+x^1
x^0+x

You may output from any standard type of output, in any readable order. Trailing newline is permitted.
No using built in evaluation functions.
Examples:
Input: 1
Output: 1/s

Input: 3-x
Output: 3/s-1/s^2

This is code golf, so the shortest entry in bytes wins.

Will the polynomial always have integer coefficients?

@AlexA. Yes. Edited into the question.

The Laplace transform of 1 is 1/s, not -1/s.

Also, does the output have to follow the same conventions as the input, i.e., 0/s and 1/s^1 are not allowed?

@Dennis It can be any form.

It's probably obvious, but what exactly does this mean: "evaluation functions"? I'm assuming I can't use any (built-in) laplace(f(x))-function, but what about integral(f(x))?

Is 1+2*x valid input (note the *)

@Stewie Not valid for both questions.

CJam, 57 bytes
l_"+-":Pf&sN+\PSerS/.{'^-'x/2We]"11".e|:~~:Em!*"/s^"E)+@}

Try it online in the CJam interpreter.

Perl, 129 bytes
Regex-based solution:
sub f{@_[0]<2?1:@_[0]*f(@_[0]-1)}$_=<>;s/(\d*)x\^?(\d*)/f($2?$2:1)*($1?$1:1).'^'.($2?$2+1:2)/eg;s/(?<!\^)(\d+)/$1.'\/s'/eg;print

Multiline:
sub f{@_[0]<2?1:@_[0]*f(@_[0]-1)} # define factorial subroutine
$_=<>; # read input
# do the laplace transform for all non-constant terms, without dividing by s:
s/(\d*)x\^?(\d*)/f($2?$2:1)*($1?$1:1).'^'.($2?$2+1:2)/eg;
s/(?<!\^)(\d+)/$1.'\/s'/eg; # divide non-exponents by s
print

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/