text:
Output an image of your source code (not-quite-a-Quine)
Code golf: Print an image of the source code.
Requirements

Must output the image of the source code itself, not a version stored elsewhere and retrieved at run time.
Code must be legible enough to copy out by hand and reproduce the results.

Any image format is applicable.
Bonuses

-10% of your score if you allow more than one output format.
-15% if your code is also a 'true' quine. i.e. it does not read its source code but the source code is embedded (see here for an example)
-30% if your code is a strict quine - i.e the image of the code is embedded in the program (Piet solutions, I'm looking at you.).

Does it have to be legible?

@TimSeguine, the image should allow someone to copy it by hand and reproduce tt exactly.

"Must output the code image itself, not a stored version from elsewhere." Is it allowed and/or required to read the source code file?

+1 Tim's question, because normally reading the source file is forbidden for quines.

I have just implemented a solution in whitespace. The resulting image looks quite boring.

Here is an interesting image quine written in Piet: http://mamememo.blogspot.be/2009/10/piet-quine.html

@Howard Indeed.

What I'm getting from the answers is $0 or the equivalent ought to be forbidden just as the source file is.

What i was trying to prevent is someone writing minimal code manually printing the screen and say 'renaming it's or re-outputting it.

So if I have -15% and -30% is it score * (1 - 0.15) * (1 - 0.30) or score * (1 - 0.15 - 0.30)?

@TheGuywithTheHat add each separately, so the former.

My PostScript CV does this.

Have a look here!!! http://en.wikipedia.org/wiki/Tupper%27s_self-referential_formula

I assume you must output just the code, and not just print screen and output

@sagiksp nope

@Pureferret It was worth a shot haha

Sh, X & ImageMagick 18.9:
 import -window root a.jpg

This should work in any shell that has ImageMagick.
To print only the code prepend clear && this comes out at 26.1
clear && import -window root a.jpg

Sample output:

Tested on my computer, it works.

@Ace, could I be cheeky and ask you to edit the image into my answer?

Didn't work for me on the Linux console. You may want to add X to the requirements.

Not a strict quine. (Doesn't programmatically generate its own source code.)

@nitro agreed, but the only strict prime would have an image as the input as well.

Well, you're calling the question "an image based quine", and says that the objective is to print the source code to a image instead of as text. Imo, it doesn't make sense to arbitrarily remove the conventional quine criterion that the output should be generated, just because the output target is an image instead of text. (Note btw that I left the same comment on most of the answers.)

@nitro I may have misused the term 'Quine' but the first line of my post only mentions outputting an image of the source code. I'm editing now to clarify my original intent, and also to benefit true/strict quines.

Just curious, I see bitcoin and litecoin wallets; It's ~3 years later now, any serious gains? :D

Why did you accept this?

@MDXF shortest answer.

shell
By "Print an image of the source code", I assume that actually printing an image on paper would be acceptable.
#!/bin/sh
lpr $0

Piet, 24399.76

This was not made by me.

Could you community wiki this answer? That has become our standard policy for externally-sourced answers. This is really cool, though!

It's the lower of the two. -30% and -15%

PHP - 487 × 0.9 × 0.85 = 372.555 (2000×99px)
<?php $y="imagecolorallocate";$l=[
'<?php $y="imagecolorallocate";$l=[',
'];$i=imagecreate(2e3,99);$y($i,99,99,99);$w=$y($i,$j=0,0,0);$z=function($_)use(&$j,$i,$w){imagestring($i,4,9,$j+=15,$_,$w);};$z($l[0]);foreach($l as$m)$z(chr(39).$m.chr(39).",");$z($l[1]);$argv[1]($i,"o");',
];$i=imagecreate(2e3,99);$y($i,99,99,99);$w=$y($i,$j=0,0,0);$z=function($_)use(&$j,$i,$w){imagestring($i,4,9,$j+=15,$_,$w);};$z($l[0]);foreach($l as$m)$z(chr(39).$m.chr(39).",");$z($l[1]);$argv[1]($i,"o");

If warnings are fine: PHP - 479 × 0.9 × 0.85 = 366.435
<?php $y=imagecolorallocate;$l=[
'<?php $y=imagecolorallocate;$l=[',
'];$i=imagecreate(2e3,99);$y($i,99,99,99);$w=$y($i,$j=0,0,0);$z=function($_)use(&$j,$i,$w){imagestring($i,4,9,$j+=15,$_,$w);};$z($l[0]);foreach($l as$m)$z(chr(39).$m.chr(39).",");$z($l[1]);$argv[1]($i,o);',
];$i=imagecreate(2e3,99);$y($i,99,99,99);$w=$y($i,$j=0,0,0);$z=function($_)use(&$j,$i,$w){imagestring($i,4,9,$j+=15,$_,$w);};$z($l[0]);foreach($l as$m)$z(chr(39).$m.chr(39).",");$z($l[1]);$argv[1]($i,o);

You provide the output function to use as the first command line argument:
php timwolla.php imagepng

Solution with warnings:

I think this is the first actual quine and not just a script reads its own source code, or just takes a screenshot of itself.

Two questions, can you use a different notation for your decimals? It's mildly confusing.  Also why is the image so small? It's difficult to read (admittedly I'm on my phone)

@Pureferret just zoom it in. It's actually quite readable despite being pixelized.

@Pureferret Just changed them, I never remember it being different in english…

Whitespace, 125

Outputs an image file in the pbm format.
If you're testing this code, please copy it by clicking on "Edit", and copying everything between the
 tags.
Output:
P1 1 1 0

copies by hand, squinting at screen to see subtle differences between spaces and tabs.... runs program.... hard drive explodes

@JonathanVanMatre You must have copied it wrong. Whitespace can only manipulate registers and RAM. :)

This answer doesn't meet requirement 2. The image isn't readable enough to reproduce the source code.

@user2357112 But you cannot prove that. That's the loophole I'm exploiting here.

Yes I can, using information theory. A fully-rigorous justification would be beyond the scope of a 600-character comment, but the gist of it is that your image is identical to an image of code that doesn't work.

Pardon the French, but BS! The rules state that the code must be legible. Writing code in Whitespace doesn't negate that. This is your program shown in Sublime Text, when selected: http://i.imgur.com/A2ZaQwI.png This is legible. Whatever your program outputs isn't. And besides, you haven't explained whether what your program outputs is actually your source code or just literally an empty image.

At present this doesn't pass rule two. A loop hole would be embedding a the number of spaces tabs etc in text, like  S S S    T    T S or similar. That you could reproduce.

@Pureferret Sorry for doing that, but this wasn't meant to be a serious answer. You do not have to consider it.

Mathematica, 37 31 chars

(#2[#1[#0[#1,#2]]]&)[Defer,Rasterize]

(Rasterize[#1[#0[#1]]]&)[Defer]

Inspired by an answer in mathematica.stackexchange.com.

Explain it...what are the #n for? Maybe we can figure it out.

At least it works without FrontEnd. (Tried with Export["/tmp/out.png",%] after running this command)

@Pureferret #n means nth argument of a pure function (created at the & point). The whole expression expands to Rasterize[Defer[#0[Defer,Rasterize]]], where #0 is recursive call of the original pure function. In a way, this isn't a strict quine, but it doesn't need any frontend to work, and is IMO a nice solution.

I admire the use of Defer[] and Rasterize[] as both the commands and the object of the commands. I've never seen recursion presented this way before.

AppleScript, 68 37
Alright, if you can call ImageMagick in zsh then this too is valid. I'm still hacking at something more elegant and of-the-quine-spirit for my own satisfaction, but for pure golfiness, here we are:
New version
do shell script "screencapture q.jpg"

Old version
tell application "System Events" to keystroke "#" using command down

I imagine this will still be beaten, but verbose old AppleScript does an admirable imitation of succinctness for this one.

do shell script "screencapture -c"

I think a quine, by definition, produces its source code as its only output, but not sure if that should apply to this question. http://www.nyx.net/~gthompso/quine.htm

Yeah, I am actually trying to figure out how to get it to select only the code area of its own window, but I figured I'd go ahead and throw this up to plant my flag in AppleScript territory.

I'm considering this as valid and was expecting something of this sort.

Not a strict quine. (Doesn't programmatically generate its own source code.)

Technically, none of these can be strict quines except the Piet answer, because none of these languages take images as source code. But I'm still determined to make a more stricter-er version of mine.  :)

Mathematica, 83
SelectionMove[InputNotebook[],Previous,Cell];Rasterize@NotebookRead@SelectedCells[]

Not a strict quine. (Doesn't programmatically generate its own source code.)

Doesn't work without frontend (in math or MathKernel), even with `<<JavaGraphics`` imported.

HTML5/Javascript : 615
<canvas id='i' width=500 height=5000></canvas>

Demo : http://jsfiddle.net/E2738/2/
One can right click on the image and save its as a PNG

it ends with <//script>

at end of line 11 in the fiddle change +wrapText+"<//script>"; to +wrapText+"<\/script>";

@Charles Thanks for pointing that out. Fixed.

Javascript + JQuery 153 148
Regular

(function f(){
  c=$('<canvas/>')[0];
  a=c.getContext('2d');
  l=('('+f+')()').split('\n');
  for(i=0;i<l.length;i++)
    a.fillText(l[i],5,12*(i+1));
  $('body').append('')
})()

Golfed

function f(){c=$('<canvas>')[0];c.width=750;a=c.getContext('2d');a.fillText(f+'f()',5,9);$('body').append('')}f()

Not a strict quine. (Doesn't programmatically generate its own source code.)

$ ? are you using jQuery as well??

@ClydeLobo Yup, seems he is. Wait, you can do Javascript without JQuery? Who'd have thought!

@ClydeLobo Yes I am. But libraries should be allowed. Its really no different from a C program using stdio.h xD. Writing the program without jQuery is easy though. Just replace $('<canvas/>')[0] with document.createElement('canvas') and $('body').append with document.write. jQuery saved me bytes.

Java, 570 - 10% - 15% = 427.5
("filepath" included), 554 - 10% - 15% = 415.5 ("filepath" not included)
Thanks to Andreas for removing BufferedImage in java.awt.image.BufferedImage
import java.awt.image.*;class Q{public static void main(String[]a)throws Exception{BufferedImage i=new BufferedImage(3500,12,1);String s="import java.awt.image.*;class Q{public static void main(String[]a)throws Exception{BufferedImage i=new BufferedImage(3500,12,1);String s=%s%s%s;char q=34;i.getGraphics().drawString(String.format(s,q,s,q,q,q,q,q),0,9);javax.imageio.ImageIO.write(i,%spng%s,new java.io.File(%sfilepath%s));}}";char q=34;i.getGraphics().drawString(String.format(s,q,s,q,q,q,q,q),0,9);javax.imageio.ImageIO.write(i,"png",new java.io.File("filepath"));}}

Output:
To view properly, see this link: https://i.stack.imgur.com/RRSDw.png
This works just like a regular quine, except it outputs to an image. The current format is png, but the format can easily be changed by replacing all instances of png in the program with whatever format you want.
Unlike a few answers here, this is a true quine; no reading of the program file.

you can get rid of another 24 characters if you replace both "java.awt.image.BufferedImage" with "java.awt.image.*"

zsh, 57 × 0.9 = 51.3
Pass it the output filename as an argument.
convert -annotate +0+10 "$(<$0)" -size 320x14 xc:white $1

Produces:

is that zsh or imagemagick?

@Kaya: Well, both. The language is zsh (or bash, but it’s not Posix), and the library/tool is ImageMagick (or GraphicsMagick, if you prefer) – like PHP with GD or Ruby with RMagick.

@Pureferret: Added.

Not a strict quine. (Doesn't programmatically generate its own source code.)

C99 (using SDL & SDL_ttf), 414 354 346 - 15% = 294.1
#include<SDL_ttf.h>
#define Q(P)char*q=#P;P
Q(
i=5;main(){for(SDL_Surface*s=SDL_SetVideoMode(2048,80,SDL_Init(SDL_INIT_VIDEO),TTF_Init());i--;SDL_SaveBMP(s,"q.bmp"))SDL_BlitSurface(TTF_RenderText_Blended(TTF_OpenFont("q.ttf",9),(char*[]){"#include<SDL_ttf.h>","#define Q(P)char*q=#P;P","Q(",q,")"}[i],(SDL_Color){~0}),0,s,&(SDL_Rect){0,16*i});}
)

This is pretty ugly without more line breaks, but unfortunately they need to be absent. The text-rendering function doesn't grok control characters at all, so any line breaks in the code have to be rendered manually in the output.
Here's the same code but with some extra line breaks thrown in for legibility:
#include<SDL_ttf.h>
#define Q(P)char*q=#P;P
Q(
i=5;main(){for(SDL_Surface*s=SDL_SetVideoMode(2048,80,
SDL_Init(SDL_INIT_VIDEO),TTF_Init());i--;SDL_SaveBMP(s,"q.bmp"))
SDL_BlitSurface(TTF_RenderText_Blended(TTF_OpenFont("q.ttf",9),
(char*[]){"#include<SDL_ttf.h>","#define Q(P)char*q=#P;P","Q(",q,")"}[i],
(SDL_Color){~0}),0,s,&(SDL_Rect){0,16*i});}
)

Sadly, this doesn't also add line breaks to the graphical output:

The output is still legible, though with 9-point output and the red font color, it's a bit squinty. You can improve it at the cost of a character by replacing the 9 with 12. (Note that the dimension of the resulting image is hardcoded to 2048x80. To accommodate the differences in various fonts, a fair bit of excess has been added to the right margin and the leading, enough so that a size-12 font should still fit comfortably. If you wish to increase it further, however, the dimensions will probably need to be altered as well.)
The command to build the program is:
gcc -Wall -o imgquine imgquine.c -lSDL_ttf `sdl-config --cflags --libs`

The program assumes that there is a font file called q.ttf in the current directory when run. I took care of this beforehand by running the following command (which should work on most modern Linuxes):
ln -s `fc-match --format='%{file}' sans` ./q.ttf

(Feel free to import your own favorite TrueType font instead.)
After running the program, the image output will be created in the current directory, in a file named q.bmp. Unfortunately Windows bitmap files are the only output format that this program provides. Adding more output formats would require linking in more libraries.
Note that this program takes advantage of C99's syntax for introducing non-simple literal values, thus significantly reducing the number of variables that need to be defined. This is something that more C golfers should take advantage of.

C# - 498 - 15% = 423.3
This can probably be golfed more. I've never done quines or this kind of graphics in C# before:
using System;using System.Drawing;class Q{static void Main(){var b = new Bitmap(3050, 20);var g=Graphics.FromImage(b);string f="using System;using System.Drawing;class Q{{static void Main(){{var b = new Bitmap(3050, 20);var g=Graphics.FromImage(b);string f={0}{1}{0},e={3}{0}{2}{0};g.DrawString(String.Format(f,(char)34,f,e,'@'),SystemFonts.MenuFont,Brushes.Black,0,0);b.Save(e);}}}}",e=@"D:\p.png";g.DrawString(String.Format(f,(char)34,f,e,'@'),SystemFonts.MenuFont,Brushes.Black,0,0);b.Save(e);}}

Output:

Adding a different format support would be easy. Not sure if it's worth it, though.

Ruby, 104 characters
require "RMagick"
include Magick
Draw.new.annotate(i=Image.new(999,99),0,0,0,9,File.read($0))
i.display

Example output, per request: i.imgur.com/jMC594C.png

Do you have an example output?

@Pureferret see edit

Not a strict quine. (Doesn't programmatically generate its own source code.)

Python: 255 238 -10% -15% = 195.075 182.07
import sys,PIL.ImageDraw as D;i=D.Image.new('L',(2000,20));r="import sys,PIL.ImageDraw as D;i=D.Image.new('L',(2000,20));r=%r;D.Draw(i).text((0,0),r%%r,fill=255);i.save(sys.argv[1])";D.Draw(i).text((0,0),r%r,fill=255);i.save(sys.argv[1])

Usage:
python imgquine.py quine.jpg

This is a true quine that draws the output to the file specified on the commandline. The file format is set simply by changing the filename extension (e.g. quine.jpg for a JPEG and quine.png for a PNG).
Example output (2000x20 image):

You could save some chars by using 2e3 instead of 2000.

@Kaya: No, I can't, unfortunately: 2e3 is a float, and Image.new demands ints.

oh bother, I assumed it would be coerced.

authors: Влад Панасюк

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


text:
POSIX reg. exp to test the divisibility by 9
Write the shortest POSIX-form regular expression that matches only non-negative integers divisible by 9. The non-negative integer should be given in base 10.

Is this too similar to the regex challenge to check divisibility by 7? I am inclined to think yes, but I am not going to flag it.

You can do it just like you do for 3. 9 has a similar rule; any integer divisible by 9 has digits summing to another multiple of 9. It makes the state machine more complex, but the same principle applies.

Are there a free Linux program to make the conversion from finite state machine to reg. exp.?

this seem to be a bit code-bowling...

202,071 bytes
Obviously, the solution is too large to be included in this post.
I use JFLAP to draw the DFA, then generate regex from it. The output is then processed in a text editor to replace (0+9) with [09] and + with |.
Here is the whole gist, with some testing code in Java.

source: Stack Exchange

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

sort: votes


text:
Build an ice puzzle generator + solver
In Twitch Plays Pokémon, one of the most annoying obstacles one can face is an ice puzzle, where you must travel from one place to another by sliding all the way in one direction until you either hit a wall or a boulder.
Your task is to build a program that will generate a random difficult ice puzzle.
Your program will accept three numbers, M, N, and P, as input (with 10 <= M <= 30, 15 <= N <= 40, and 0 <= P < 65536):
12 18

and will output:

An M by N grid consisting of . and O, representing ice and a boulder respectively.
A position marker representing where the puzzle is entered from. This position marker consists of a letter L, R, T, or B, representing left, right, top, and bottom, followed by a number representing the position (from the left or top) on that side to be entered from.
A similar position marker representing where the puzzle is exited out of.
The shortest solution to the puzzle, consisting of a sequence of L, R, U, and D respectively.

Example output:
..O...O...........
............O.....
..O...............
.......O..........
..................
...........O......
O..O...........O..
..........O.......
..O..........O....
........O.........
O....O.........O..
............O.....
R 4
B 5
LDLDRULD
(Note that this output is actually invalid because it is not actually long enough.)

For an input M and N, the solution to the puzzle must have at least min(M, N) steps and move at least 2 (M + N) total spaces. (For reference, the above puzzle moves a total of 12 steps, moving 69 spaces.) Your puzzle generator must generate a different M by N puzzle with a different solution path (i.e. a different sequence of steps for each solution) for each seed P.

Note that the requirement of a different solution path is to avoid solutions that try to systematically generate rock paths, like Claudiu's solution here. If there are two or three pairs of identical solutions due to quirks in randomness, that will be okay, as long as the program is not intentionally trying to systematically generate puzzles with the same sequence of moves.

The shortest code to do the above wins.

I cannot understand the objective: "you must travel from one place to another by sliding all the way in one direction until you either hit a wall or a boulder."  Is it good to hit walls or boulders?  Where do you aim to go from the start?  If you hit a boulder does the game end?  What happens when you hit a wall?  Is it just me or are the directions unclear?

it means that you cant change direction until you are stopped by either a wall or a boulder

You slide until you hit a boulder, and then turn left and right and do the same thing until you reach the place you want to go, basically.

 followed by a number representing the position (from the left or top) on that side to be entered from. 0-index or 1-index? Does it matter?

The shortest solution must have at least min(M,N) steps? Or the outputted solution? You could arbitrarily increase any solution by repeating the final steps until you meet this minimum. So you could generate the simplest puzzles and just bounce around in free space to make a solution. But it might also be very difficult to show that the best solution is long enough.

@intx13: The outputted solution must be the shortest solution to the puzzle. I'll update the description to reflect that.

@shelvacu: It's 1-index in the example, but if 0-index is easier for you, then go for it.

Oh, old memories of Pokémon Gold and Silver here. Find the exit, get HM07 and go to Blackthorn City.

Indeed, the Ice Path inspired this puzzle.

This reminds me of the ice levels in Chip's Challenge.

Can we choose the input format? e.g. can I take input from stdin as the string [12, 18, 314]?

Why not use > and < (or any character) for the enter and the exit? The puzzles will be easier to read.

@n.1: the entrance & exit are actually off the grid. that being said there'll never be a rock right in front of it so it could be counted as a blank spot, and can use <>v^ to point the direction in case of ambiguity (i.e. entrance on a corner).

Actually your sample output is invalid - the shortest path is LDLDRULD which is only 8 steps long

Oh, really? Thanks for telling me, I hand-crafted that puzzle and yet didn't notice.

Python, 672 548 characters, more interesting puzzles
Although going strictly by the rules, my other Python program beats this one, I decided to write one that would generate more interesting puzzles anyway. Here it is:
R=range;import random as J;X=J.randint
x=(0,1,-1,0);y=x[2:]+x
g=lambda r,c:(0<=r<H)+(0<=c<W)>1and f[r][c]or x[(r,c)in(A,E)]
l=lambda r,c:g(r+y[d],c+x[d])<1and(r,c)or l(r+y[d],c+x[d])
H,W,P=input();J.seed(P)
while 1:
 A=(-1,X(0,W));E=(H,X(0,W));f=[[X(0,7)for _ in R(W)]for _ in R(H)]
 q=[(A,'')];n=z={}
 while q and n!=E:
    n,O=q.pop()
    for d in R(4):
     N=l(*n)
     if g(n[0]+y[d],n[1]+x[d])and N not in z:q[:0]=[(N,O+"URLD"[d])];z[N]=1
 if(n==E)*len(O)>min(H,W):print"\n".join(''.join('O.'[c>0]for c in T)for T in f),"\nT",A[1],"\nB",E[1],"\n",O;break

Indentation levels are space, tab, tab+space.
Samples:
$ echo [10,15,0] | python ice2.py
.....OO........
...............
...O....O.OO..O
...........O...
..O....O.......
.......O....O..
....O..........
.............O.
..............O
...............
T 1
B 10
DLURDRURULDRD

It uses P as a seed, so each P will generate the same puzzle, and each different P is exceedingly likely to be different:
$ echo [10,15,1] | python ice2.py
.OOO.O.........
...O......O.O.O
.......O.......
..O..........OO
.....O.........
.............O.
.O.............
.O............O
O....O.........
......O........
T 14
B 8
DLDRDLURULD

It works reasonably fast up to sizes of M=25,N=40 but past that it gets really slow. It should theoretically work for M=30, N=40 if you let it run long enough. I've manually written in the trail here since it is hard to follow - the program just outputs the puzzle.
$ echo [25,40,0] | python ice2.py
                   *
...................dO....urrrO..O..O....
....O.....O........dO....u..dO..........
..........O.....O..d....Ou.Odrrrrrrrrrrr
...........O.......d.O..Ou..O.....OOllld
.O....O.OO.........drrrrrrO....Olllud..O
O......O...O.O.....O............dO.ud...
O........OO..........O.........Od..ud..O
.........O......................d..ud...
....O.....O.O....O.....O........d..ud.O.
.....O..O...................O...d..udO..
.........O.........O..O.........d..ud...
.......O.O...O..O.OO....O...OOlldOOld...
........Olllllllllu....OO.OO..dOO...O...
.O.O....Od........u......O....d..O...O..
..O....O.d........u..O........d..O..O...
....O....d..O.....uO.....O....d.........
.........d........u...........d.........
.........d....O...u.O..O.....Od.O.......
........Od...O....u...........d.........
.O.....OuxrrrrO...u...OOOO..O.d.........
........udO..dO.O.u...........d.........
O..O.O..ud...d..urrO..........d.O...O...
........ud...d..u.O.O........Od..O...O..
..OO....ud..Od..u......OllllludO.....O..
..O....OldO..dOOlllllllld...Old...O..O..
             *
T 19
B 13
DRURDRDLDLULDLDLULDLURULDLURD

Explanation:
The program loops, generating a random start position on the top, a random end position on the bottom, and a random grid with a 12.5% chance for a boulder on any given spot. It then solves the puzzle with a breadth-first-search and if the solution exists and is bigger than min(H,W), it prints and exits.

Python, 235 206 185 176 characters
H,W,P=input()
t=''
for x in range(16):t+=".O"[(P>>x)%2]
for n in[t[1:],t[0],"O","...O"]+["."]*(H-5)+[".O.."]:print(n*W)[:W]
print"B 1\nR",(H,3)[-W%4/2],"\n",("URDR"*W)[:W+W%2]

Usage:
Input is through stdin of the form [M, N, P].
$ echo [14, 17, 2] | python ice.py
O..............O.
.................
OOOOOOOOOOOOOOOOO
...O...O...O...O.
.................
.................
.................
.................
.................
.................
.................
.................
.................
.O...O...O...O...
B 1
R 3
URDRURDRURDRURDRUR

You said the maps had to be different for each seed P... and they are:
$ echo [14, 17, 233] | python ice.py
..O.OOO..........
OOOOOOOOOOOOOOOOO
OOOOOOOOOOOOOOOOO
...O...O...O...O.
.................
.................
.................
.................
.................
.................
.................
.................
.................
.O...O...O...O...
B 1
R 3
URDRURDRURDRURDRUR
$ echo [14, 17, 65133] | python ice.py
.OO.OO..OOOOOOO.O
OOOOOOOOOOOOOOOOO
OOOOOOOOOOOOOOOOO
...O...O...O...O.
.................
.................
.................
.................
.................
.................
.................
.................
.................
.O...O...O...O...
B 1
R 3
URDRURDRURDRURDRUR

And an example w/ a different size:
$ echo [10, 15, 65133] | python ice.py
.OO.OO..OOOOOOO
OOOOOOOOOOOOOOO
OOOOOOOOOOOOOOO
...O...O...O...
...............
...............
...............
...............
...............
.O...O...O...O.
B 1
R 10
URDRURDRURDRURDR

Satisfies all the supplied objective criteria:

Each P leads to a different puzzle
There is only one solution, thus it is the shortest
The solution takes N + N%2 steps, which is at least N
The solution always takes more than 2 (M + N) total spaces

Explanation:
Each row is constructed by repeating a certain string element W times and limiting the length to W (I use H and W instead of M and N).
The first two rows depend on P to make each puzzle unique. Basically, note that P fits into a 16-bit unsigned integer. I convert P to binary, using . for 0 and O for 1:
t=''
for x in range(16):t+=".O"[(P>>x)%2]

The first row element is the last 15 bits, t[1:], while the second row element is the 1st bit, t[0]. I couldn't put it all on one row because the minimum width is 15, which wouldn't fit all 16 bits if P > 32767. Thus the first two rows uniquely represent each of the possible values of P.
The third row is a full wall so that the value of P doesn't affect the solution.
Then follow the actual maze elements. This line prints them all, repeating them up to the cap. The result is as you see above:
for n in[t[1:],t[0],"O","O..."]+["."]*(H-5)+["..O."]:print(n*W)[:W]

The rest was just figuring out how to solve the dynamically generated maze. This depends only on the width of the maze. I noted that the solutions, for a given width, were:
  W  | solution
-----+---------
  1  | UR
  2  | UR
  3  | UR DR
  4  | UR DR
  5  | UR DR UR
  6  | UR DR UR
  7  | UR DR UR DR
  8  | UR DR UR DR

etc. Hence it's just URDR repeated and cut off at the right place, W+W%2.
print"B 1\nR",(H,3,3,H)[W%4],"\n",("URDR"*W)[:W+W%2]

how to the 33th bit of a integer does that work?

@masterX244: Lots and lots of golfing... basically exploiting the repetitive nature of the output and doing some maths to make sure it all lines up properly

mostly wondering about how the "randomness" is made (PS the downvote was not from me)

@masterX244: ah gotcha. I'll add an explanation

Hmm. Doesn't exactly meet "...generate a random difficult ice puzzle", but it hits the bulleted points for sure.

@Geobits: Ah I missed the "difficult" part. Anyways, yeah this is clearly following the letter and not the spirit of the rules. The minimum length and distance travelled requirements definitely made this less straightforward. We shall see if OP accepts this or modifies his question.

I didn't mean it in a negative way. It's clever for sure, I just hope aspiring game devs don't use this for actual puzzles :p

I was trying to avoid stuff like this (because I knew somebody would post it like this), but you managed to do it anyhow. I couldn't figure out a ruleset that would avoid solutions like this one.

If you have any suggestion as to how to create a better criterion that would disqualify solutions like this one, feel free to suggest it. Either way, your other puzzle would also be the current winner.

@JoeZ.: I actually was wondering if this is what you had in mind since it fit so nicely in the criteria. But hmm you could add a restrictions like... the path must be different for every value of P (minimum of 10 means you have 4^10 possibilities which is > 2^16). That would at least make it much harder to pull something like this off, though it might still win than doing it 'the hard way'

Although for the purposes of random generation, it would be really hard to purposely avoid a collision in the solutions. As well, there are actually only 2^10 possibilities, because every L or R must be followed by a U or D, or vice versa.

(Guess that just means that smaller puzzles need harder solutions. :P)

Java - 2632
While I admire the technical purity of Claudiu's answer, I decided to try my hand at making slightly more difficult puzzles ;)
Basic steps (pretty simple):
Randomize entry location
Step forward
For min(m,n)-1 steps:
    Rotate left or right
    Slide until I hit something or go a random distance
    Place a rock in front of stopping location
If I can slide straight to any wall:
    Slide to exit
Else
    Create another step and try again

If at any step I get trapped, start over
If BFS finds shorter path, start over

I also mark each spot as 'nogo' as I'm sliding. If I end up on a nogo spot(or right in front of one which would mean a rock was going there), it's an invalid step.
So, basically the idea is to randomly generate a lot of maps, and keep the first one that is valid. I plan to make this smarter(backtracking, etc), but it works fine right now. It might also cut down on some redundant code, we'll see.
As it is, it generates small maps(15x10) almost instantly, medium(30x20) maps in a couple seconds, and large(40x30) in some random amount of time between 20 seconds and 20 minutes, depending on seed. It tests between 300k-500k maps/second on my machine, depending on size.
Side note: Sometimes the maps aren't too hard, simply because there are only as many rocks as steps, and unless the step takes you to a wall, most times there's only one option if you want to hit an actual rock. I'll fix that later by placing "random" rocks in safe spots after all the steps are drawn. Since nogo spots are already marked, that should be pretty simple. For now, just enjoy these examples:
Output showing different sizes/seeds:
$ java I 30 20 6851              $ java I 15 10 1     $ java I 15 10 65513

............................O.      .......O.......     ....O..........
..............................      ...............     ...............
..............................      .........O.....     .........O.....
..........O......O............      .............O.     ..............O
...............O...........O..      ...............     ...............
..............................      .......O.......     .....O.O.......
..............................      O..............     ...............
........................O.....      ...............     ..........O....
..............................      ...............     O..............
...O.......................O..      ......O........     ...............
O...............O.OO..........
..............O..........O....
...........O..................      T 14                R 6
....O.........................      T 7                 T 14
..............................      DLDLULURU           LULDLDRURU
..............................
..............................
.................O............
.O............................
..............................

B 28
R 9
ULURDLDLDRURDLDRURUR

Max size 40x30:
$ java I 40 30 2

........................................
........................................
........................................
........................................
................O.......................
..........O.............................
........................................
.......O................................
.....................O..........O.......
......................O.................
.................................O......
......................................O.
........................................
........................................
..............................O.........
...........O............................
........................................
.......................................O
.........O...................O..........
....................O...................
...............................O........
............O..O......................O.
......O...........O.....................
..................O....O................
..................................O.....
........................................
..............................O.........
.....................................O..
...........O............................
...................O....................

B 19
B 11
URURDLULULDRDRDLULDLDLULURDLD

Golfed:
import java.util.*;import java.awt.*;class I{int m,n,p,g,a[][],b[][];Random r;Point s,e,c;ArrayList<Integer>z;void Q(String q,int l){if(l>0)System.out.println(q);else System.out.print(q);}void G(String[]y){m=Integer.valueOf(y[0]);n=Integer.valueOf(y[1]);p=Integer.valueOf(y[2]);r=new Random(p);Q("",1);int o=0,i,j,u=0;char t,f[]={85,76,68,82};while(o<3){if(++u%20000==0)Q("\r#"+u,0);a=new int[m+2][n+2];b=new int[m+2][n+2];for(i=0;i<m+2;i++)for(j=0;j<n+2;j++)if(i==0||i==m+1||j==0||j==n+1)a[i][j]=2;s=new Point();int e=r.nextInt(m*2+n*2);if(e<m*2){s.x=e%m+1;s.y=e<m?0:n+1;}else{s.y=(e-m*2)%n+1;s.x=(e-m*2)<n?0:m+1;}if(s.x<1)g=3;else if(s.x>m)g=1;else if(s.y<1)g=2;else if(s.y>n)g=0;a[s.x][s.y]=0;c=new Point(s);z=new ArrayList<Integer>();z.add(g);for(i=0;i++<Math.min(m,n)-1;)if(N()<1&&N()<1)break;o=((z.size()>=Math.min(m,n)-1)?1:0)+F()+((V()==z.size())?1:0);}Q("\r",0);for(j=1;j<n+1;j++){for(i=1;i<m+1;i++)Q(String.valueOf(a[i][j]>0?'O':'.'),0);Q("",1);}Q("\n\n",0);if(s.x<1||s.x>m){t=s.x<1?'L':'R';u=s.y;}else{t=s.y<1?'T':'B';u=s.x;}Q(t+" "+u,1);if(e.x<1||e.x>m){t=e.x<1?'L':'R';u=e.y;}else{t=e.y<1?'T':'B';u=e.x;}Q(t+" "+u,1);for(i=0;i<z.size();)Q(String.valueOf(f[z.get(i++)]),0);Q("",1);}public static void main(String[]a){new I().G(a);}int F(){int c=0;while(C()<1&&c++<10)if(N()<1)return 0;return e==null?0:1;}int C(){int d=g<2?-1:1;if(g%2<1){int y=c.y;while(y>0&&y<n+1){y+=d;if(a[c.x][y]==1)return 0;}e=new Point(c.x,y);}else{int x=c.x;while(x>0&&x<m+1){x+=d;if(a[x][c.y]==1)return 0;}e=new Point(x,c.y);}a[e.x][e.y]=0;return 1;}int V(){if((s.x-e.x)+(s.y-e.y)<2)return 0;Queue<Point>q=new ArrayDeque<Point>();Queue<Integer>d=new ArrayDeque<Integer>();a[s.x][s.y]=-2;q.add(s);d.add(0);while(q.size()>0){Point t=q.poll();int h=d.poll(),i=0;if(t.equals(e))return h;for(;i<4;i++){Point n=S(a,t,i<2?0:1,i%2<1?-1:1,99,1);if(a[n.x][n.y]==-2)continue;a[n.x][n.y]=-2;q.add(n);d.add(h+1);}}return 0;}int N(){Point q;int d=g<2?-1:1,x,y;System.arraycopy(a,0,b,0,a.length);q=S(b,c,g,d,r.nextInt((g%2<1?n:m)/2)+2,0);if(q.x<1||q.y<1||q.x>m||q.y>n||q.equals(c)||b[q.x][q.y]!=0)return 0;x=q.x;y=q.y;if(g%2<1)y+=d;else x+=d;if(b[x][y]<0)return 0;b[q.x][q.y]=-1;b[x][y]=1;int f=r.nextInt(2)<1?-1:1;g=g%2<1?(f<0?1:3):(g=f<0?0:2);c=q;System.arraycopy(b,0,a,0,a.length);z.add(g);return 1;}Point S(int[][]u,Point f,int w,int d,int q,int s){int i=1,x=f.x,y=f.y;for(;i<=q;i++){if(w%2<1)y=f.y+i*d;else x=f.x+i*d;if(e!=null&&e.x==x&&e.y==y)return e;if(y<0||y>n+1||x<0||x>m+1)return f;if(s<1&&u[x][y]<1)u[x][y]=-1;if(u[x][y]>0){if(w%2<1)y-=d;else x-=d;return new Point(x,y);}}if(w%2<1)return new Point(f.x,f.y+i*d);else return new Point(f.x+i*d,f.y);}}

With line breaks:
import java.util.*;
import java.awt.*;

class I{
    int m,n,p,g,a[][],b[][];
    Random r;
    Point s,e,c;
    ArrayList<Integer>z;

    void Q(String q,int l){if(l>0)System.out.println(q);else System.out.print(q);}

    void G(String[]y){
        m=Integer.valueOf(y[0]);
        n=Integer.valueOf(y[1]);
        p=Integer.valueOf(y[2]);
        r=new Random(p);
        Q("",1);

        int o=0,i,j,u=0;
        char t,f[]={85,76,68,82};
        while(o<3){
            if(++u%20000==0)
                Q("\r#"+u,0);

            a=new int[m+2][n+2];
            b=new int[m+2][n+2];
            for(i=0;i<m+2;i++)
                for(j=0;j<n+2;j++)
                    if(i==0||i==m+1||j==0||j==n+1)
                        a[i][j]=2;

            s=new Point();
            int e=r.nextInt(m*2+n*2);
            if(e<m*2){
                s.x=e%m+1;
                s.y=e<m?0:n+1;
            }else{
                s.y=(e-m*2)%n+1;
                s.x=(e-m*2)<n?0:m+1;
            }
            if(s.x<1)g=3;
            else if(s.x>m)g=1;
            else if(s.y<1)g=2;
            else if(s.y>n)g=0;

            a[s.x][s.y]=0;
            c=new Point(s);
            z=new ArrayList<Integer>();
            z.add(g);

            for(i=0;i++<Math.min(m,n)-1;)
                if(N()<1&&N()<1)
                        break;
            o=((z.size()>=Math.min(m,n)-1)?1:0)+F()+((V()==z.size())?1:0);
        }

        Q("\r",0);
        for(j=1;j<n+1;j++){
            for(i=1;i<m+1;i++)
                Q(String.valueOf(a[i][j]>0?'O':'.'),0);
            Q("",1);
        }
        Q("\n\n",0);
        if(s.x<1||s.x>m){
            t=s.x<1?'L':'R';
            u=s.y;
        }else{
            t=s.y<1?'T':'B';
            u=s.x;
        }
        Q(t+" "+u,1);
        if(e.x<1||e.x>m){
            t=e.x<1?'L':'R';
            u=e.y;
        } else {
            t=e.y<1?'T':'B';
            u=e.x;
        }
        Q(t+" "+u,1);
        for(i=0;i<z.size();)
            Q(String.valueOf(f[z.get(i++)]),0);
        Q("",1);
    }

    public static void main(String[]a){
        new I().G(a);
    }

    int F(){
        int c=0;
        while(C()<1&&c++<10)
            if(N()<1)
                return 0;
        return e==null?0:1;
    }

    int C(){
        int d=g<2?-1:1;
        if(g%2<1){
            int y=c.y;
            while(y>0&&y<n+1){
                y+=d;
                if(a[c.x][y]==1)
                    return 0;
            }
            e=new Point(c.x,y);
        }else{
            int x=c.x;
            while(x>0&&x<m+1){
                x+=d;
                if(a[x][c.y]==1)
                    return 0;
            }
            e=new Point(x,c.y);
        }
        a[e.x][e.y]=0;
        return 1;
    }

    int V(){
        if((s.x-e.x)+(s.y-e.y)<2)
            return 0;
        Queue<Point>q=new ArrayDeque<Point>();
        Queue<Integer>d=new ArrayDeque<Integer>();
        a[s.x][s.y]=-2;

        q.add(s);
        d.add(0);
        while(q.size()>0){
            Point t=q.poll();
            int h=d.poll(),i=0;
            if(t.equals(e))
                return h;
            for(;i<4;i++){
                Point n=S(a,t,i<2?0:1,i%2<1?-1:1,99,1);
                if(a[n.x][n.y]==-2)
                    continue;
                a[n.x][n.y]=-2;
                q.add(n);d.add(h+1);
            }
        }
        return 0;
    }

    int N(){
        Point q;
        int d=g<2?-1:1,x,y;
        System.arraycopy(a,0,b,0,a.length);
        q=S(b,c,g,d,r.nextInt((g%2<1?n:m)/2)+2,0);
        if(q.x<1||q.y<1||q.x>m||q.y>n||q.equals(c)||b[q.x][q.y]!=0)
            return 0;
        x=q.x;
        y=q.y;
        if(g%2<1)
            y+=d;
        else
            x+=d;
        if(b[x][y]<0)
            return 0;
        b[q.x][q.y]=-1;
        b[x][y]=1;
        int f=r.nextInt(2)<1?-1:1;
        g=g%2<1?(f<0?1:3):(g=f<0?0:2);
        c=q;
        System.arraycopy(b,0,a,0,a.length);
        z.add(g);
        return 1;
    }

    Point S(int[][]u,Point f,int w,int d,int q,int s){
        int i=1,x=f.x,y=f.y;
        for(;i<=q;i++){
            if(w%2<1)
                y=f.y+i*d;
            else
                x=f.x+i*d;
            if(e!=null&&e.x==x&&e.y==y)
                return e;
            if(y<0||y>n+1||x<0||x>m+1)
                return f;
            if(s<1&&u[x][y]<1)
                u[x][y]=-1;
            if(u[x][y]>0){
                if(w%2<1)
                    y-=d;
                else
                    x-=d;
                return new Point(x,y);
            }
        }
        if(w%2<1)
            return new Point(f.x,f.y+i*d);
        else
            return new Point(f.x+i*d,f.y);
    }
}

Could not while(o<3){...;o=...;} be for(;o<3;o=...){...;}, saving one byte?

if(w%2<1)return new Point(f.x,f.y+i*d);else return new Point(f.x+i*d,f.y); -> return new Point(f.x+(w%2<1?0:i*d),f.y+(w%2<1?f.y:0));.