text:
Write a Binding Greeter
You will write a Program which writes the Second Program.
Each program has one Input; which may be a command line argument, or be read from stdin.  A Input is a single word made up of upper and/or lowercase letters (a-z)
Each program has Output; which may be to a file, or to stdout.
The Program (which you post here)

accepts the Input Greeting, e.g. "Hello"
the Output contains the source code of another program, which is described below

The Second Program

accepts a Input of Name, e.g. "John"
MUST NOT contain the Greeting in a format that could be read by an average computer programmer
when executed makes the Output in the format of {Greeting} {Name}, e.g. "Hello John"
MUST NOT use an encoding library or function, including but not limited to

base64/base32/baseN (unless manually implemented)
cryptography (unless manually implemented)

"not be read by an average computer programmer" is ambiguous, but here are some examples for the Greeting "Hello".  Use common sense, and I'll downvote if you do one of those Well he didn't say "He" + "ll" + "o" was against the rules

Good

"Dqkta"
[9,3,5,1,6,1,5]
↛↝↧
a^|12..7
..--..--!!--.--.----.-,,--.

Bad

"Hello"
"hEllo"
"h3110"
"He" + "llo"
["H", "e", "l", "l", "o"]
"H_e_l_l_o"

Scoring:

usual codegolf, least bytes wins
addition command line arguments cost the usual 1 point

no command line arguments allowed for the Second Program

scoring only applies to the first Program (the one you post here)

Please also include an example generated program and a description.  If you're confused, see my example answer bellow.

is "olleH" good enough?

@JanDvorak Not if your layout settings are RTL ;-)

Nope.  Another way to look at it is, "Here's the Second Program; and here are 5 possible greetings that could be in it".  If someone could tell which of the 5 was used; it's not good enough.

Are the greetings mixed case, or can we just accept lowercase?

@LegoStormtroopr, letters of the alphabet and they can be upper or lowercase.  In Regular Expressions [a-zA-Z]+

No " in the greeting allowed? That would make this intresting.

@JohannesKuhn, you can assume there will be only letters.  The user won't ever give invalid input.

A ! would break both of your solutions. Would be more intresting to find a solution that works with all ascii chars or even unicode characters.

Does the second program need to be in the same language as the first?

@Johannes My solution works with all ASCII characters; it probably would work with Unicode but windows command prompt doesn't support Unicode :P so I can't test

@plannapus, nope :-)

How about conversion to ASCII characters?

GolfScript, 15 / 11 characters
{)}%`'{(}%" "@'

Performs the same obfuscation as the example program. The resulting code for input Howdy is then
"Ipxez"{(}%" "@

For both programs input must be supplied on STDIN while output goes to STDOUT.
If it's ok to convert the string to codes only you can also take the 11 character solution
{}/32]`'\+'

(Thanks to Peter for an idea to save two more characters).

Wow, nice!  I was hoping it'd be a bit more difficult :-)  I probably should have picked a single difficult encoding, instead of just "unreadable".

@FakeRainBrigand I didn't think that simple shifting was allowed and had a much more complex idea in mind before I read your example.

@FakeRainBrigand And the difficult part is still to be done, namely beating the 12 character solution Peter will come around with in a few minutes.

Your 13-character solution can save two by replacing " "+ with 32 before the ]. I've only looked at this task briefly, and currently am lagging behind on 17.

APL(Dyalog), 16/20
Losing to GS again...
'⍞,⍨⊂⎕UCS',⎕UCS⍞

This may break the "no cryptography" rule. ⎕UCS is a function to convert characters to unicode code points and back.
Example
First input: Hello
First output: ⍞,⍨⊂⎕UCS 72 101 108 108 111
Second input: John
Second output: Hello John (Note the space before "Hello")

'⎕AV[','],⊂⍞',⍨⎕AV⍳⍞

Similar idea with the cryptography is manually implemented: Convert to/from index of some pre-defined character array (⎕AV) which includes all upper and lower alphabets.

Tcl, 111
puts "binary scan [join [lmap a [split $argv {}] {format %c [expr [scan $a %c]+256]}] {}]Ġ\$argv a* a;puts \$a"

Exploits the way how Tcl converts strings to bytearrays.
The output for Howdy is
binary scan ňůŷŤŹĠ$argv a* a;puts $a

R 113 109 97 characters
cat(unlist(sapply(utf8ToInt(scan(,"",n=1)),function(x)c(rep("+",x),".>"))),rep("+",32),".>+[,.]")

Takes an input as stdin and output a BrainF**k program that prints the input of the first program, a space and then takes a second input and output it, character by character, until an EOF character (or an empty input depending on the BF interpreter used).
Example output with first input Salut:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + .> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + .> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + .> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + .> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + .> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + .>+[,.]

which you can test here.
Initial input can include printable ASCII characters from ! onwards (spaces don't work because by default scan() uses spaces as separators). Example for $!"§&:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + .> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + .> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + .> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + .> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + .> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + .> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + .>+[,.]

This is really cool!  I still can't rap my head around these stack languages.

Brainfuck 122 120 109 106
+++++++[>++++++>+++++++++++++>++++<<<-]>+<,[[>.<-]>+++.>.<-.>++.--<--<,]>....>>[<<.>>-]<<+++.>.<--.++.>++.

+1 Neat, but could you explain some of the parts? I have trouble understanding why there is two times ,. Also what it the purpose of this ><<? Shouldn't it be just <?

@plannapus Sorry. I fogot to delete the >< when I modified my code. The first , is to ensure that the byte at the pointer is nonzero.

Here's a simple example.  It's not competitive, but shows how it should work.  This is JavaScript which runs on Node.js
var i, charCode, Greeting = process.argv[2], obfuscated = '';

// We're just doing a regular upshift of characters
// a becomes b, etc.
for ( i = 0; i < Greeting.length; i++ ) {
    charCode = Greeting.charCodeAt(i);
    obfuscated += String.fromCharCode(charCode + 1);
}

// You'll want to compress this somehow
var code = [
    "var i, deObfuscated = '';", "var Name = process.argv[2];", "var Greeting = '" + obfuscated + "';",
    "for (i=0; i<Greeting.length; i++) {", "charCode = Greeting.charCodeAt(i);",
    "deObfuscated += String.fromCharCode(charCode - 1);}", "console.log(deObfuscated + ' ' + Name)"];

console.log(code.join('\n'));

I'll call this file Program.js.  It can be tested like so:
$ node Program.js Howdy > Second.js
$ node Second.js Partner
Howdy Partner

Second.js contains this.  Notice how "Howdy" doesn't appear visibly in this code.
var i, deObfuscated = '';
var Name = process.argv[2];
var Greeting = 'Ipxez';
for (i=0; i<Greeting.length; i++) {
charCode = Greeting.charCodeAt(i);
deObfuscated += String.fromCharCode(charCode - 1);}
console.log(deObfuscated + ' ' + Name)

Ruby, 63
$><<"puts ''<<"+gets.chop.each_codepoint.to_a*'<<'+"<<' '+gets"

Output for Hello:
puts ''<<72<<101<<108<<108<<111<<' '+gets

Output for asdfASDF1234!@#$<>,.:
puts ''<<97<<115<<100<<102<<65<<83<<68<<70<<49<<50<<51<<52<<33<<64<<35<<36<<60<<62<<44<<46<<' '+gets

PHP, 58 61 64 74 Bytes
<?=0?~0 ." $argv[1]":strtr(file(__FILE__)[0],[~$argv[1]]);

The script replaces all 0 in its own source code with the inverted greeting. If run as php greeter.php Hello, the output is:
<?=ÀÜôôÉ?~ÀÜôôÉ ." $argv[1]":strtr(file(__FILE__)[ÀÜôôÉ],[~$argv[1]]);

If you run this as php greeter2.php John, the output with full error reporting is
PHP Notice:  Use of undefined constant ÀÜôôÉ - assumed 'ÀÜôôÉ'
PHP Notice:  Use of undefined constant ÀÜôôÉ - assumed 'ÀÜôôÉ'
Hello John

otherwise, just Hello John

source: Stack Exchange

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

sort: votes


text:
Game of Set Puzzle
May be you know the game of Set (a wonderful game for kids btw) a card game with 81 cards, where each card has a figure on it with 4 different attributes (form , number, colour and fill). Each attribute has 3 different values:
form: wave, oval, diamond
colour: red, purple, and green
number: 1, 2, 3
fill: none, dashed, opaque.

12 cards are laid open on the table and now the challenge is to indicate sets. A set consists of three cards where every attribute value occurs 0, 1 or 3 times. having 2 cards with red figures, or opaque, or 1 number is no good. See the supplied link for a more visual explanation.
I do envision a code for a card where all attributes are encoded so
"WP2N"

stands for
2 Purple Waves with No fill

Together with for instance OR1N and DG3N
 and
it is a set (3 different forms, 3 different colors, 3 different number, 1 fill).
Input is space delimited string of unique codes (randomly chosen out of 81 possible codes) representing cards.
"OR1N WP2N DG3N DR1D WG3S WG1N WR2D WP3N DR2O DR2D OG3O OR2D"

The solution must indicate all possible sets within the given collection. So
OR1N, WP2N, DG3N

must be part of the solution together with all other sets.

Sounds promising, but please specify more precisely what kind of input data needs to be handled (stdin, file, parameter) and how the input and output data will look like. Also provide a visual representation (screenshot or similar) of a sample run.

I'm voting to close this as "unclear what you're asking" because 1. We have no idea what the input or output is supposed to be, and 2. There's no objective winning criterion.  If you edit your question to include these, I may retract my close vote.

I extended my explanation

I have retracted my close vote and upvoted this; it's very interesting! :)

Still missing a objective winning criterion.

This is labelled a code-challenge, which usually indicates not code golf. Is that intentional? If not, then the label should be changed (and the description should mention code golf). If it is intentional, then as @Howard notes an objective winning criterion should be described.

By the way, your sample has DR1D twice; is that intentional?

The 2nd DR1D has been modified. The tag has also been changed code-golf, although I'm personally more interested in seeing the shortest readable code, showing of language features.

The hell do you mean by "game for kids"?

Waitaminute... there are 4 different 4th letters: N, D, S, and O.

While you address @boothby's very good point, can we make the alphabet for shading: {N, S, F} i.e. Non-filled, Striped, Filled. That way, there is no possible confusion even across attributes.

@flodel there are possible savings to be had if the alphabets overlap...

@boothby: I would have said the opposite. If the alphabets don't overlap, for every candidate set, you can just count how many times each letter or number shows up: the set is valid if and only if no number or letter appears twice.

@flodel see my second solution which takes advantage of an overlap.

@flodel In any case it usually is not a good idea to change a question in a way that excludes or includes a complete class of solutions, especially when several answers are provided already.

@flodel I clearly see your points and I do realize it's a whole different exercise if the value attributes become unique. However given the amount of answers and effort people put into it, I do agree with Howard and I think it's not fair to update the question at this point.

@boothby, its a physical card game which you can buy in a shop or online. Its easy to explain to everyone also kids, and it helps to keep a bunch of indoor kids quiet for at least a few minutes.

I disagree that it is unfair to update the question.  With the exception of my (non-competitive) answer, nobody actually checks what the letters are.  Thus, [DG3N WG3S OG3O] is getting reported as a 'set'.  That's wrong.  Future answers will be improved by a corrected question.

Ruby, 104 98 81 80 characters
$*.combination(3).map{|c|puts c*?,if(0..3).all?{|i|c.map{|x|x[i]}.uniq.size!=2}}

Sample run (using your example data):
c:\a\ruby>set.rb OR1N WP2N DG3N DR1D WG3S WG1N WR2D WP3N DR2O DR1D OG3O OR2D
OR1N,WP2N,DG3N
WP2N,DR1D,OG3O
WP2N,DR1D,OG3O
DG3N,WG3S,OG3O

It outputs WP2N,DR1D,OG3O twice because you have two DR1Ds in your sample data.
Explanation:
$*.combination(3).map{|c| - each combination of 3 cards
puts c*?,if - output the set, if...
(0..3).all?{|i| - if all of the numbers from 0 to 3 (the indeces of the properties in the string) evaluate to true when passed into this block
c.map{|x|x[i]} - take the ith index of each string
.uniq.size!=2} - if the amount of unique properties (form, color, etc.) is not 2 (so, 1 or 3)

Assuming this challenge will become codegolf, may I propose two improvements: a) get rid of end plus several line breaks: transform if ... puts ... end into puts ... if ... b) all can take a block, thus x.map{}.all? is equal to x.all?{}

@How Thanks, I'll make those improvements when I get to a computer.

@Howard Edited to include both. Thanks!

Also remove the space after if.

I like the ruby solution, short, concise and more or less readable

Mathematica 93 92 93 82 76 73
f={}⋃Select[StringSplit@#~Subsets~{3}, FreeQ[Tally/@(Characters@#^T),2]&]&

The Logic
StringSplit@#~Subsets~{3} produces a list of  3-card subsets.  Each triple such as:
{{"D", "G", "3", "N"}, {"W", "G", "3", "S"}, {"O", "G", "3", "O"}}
or

is then  transposed,

and Tally/@(Characters@#^T) tallies the number of distinct items in each row.
{3,1,1,3}

3 corresponds to "all different"; 1 corresponds to "all same".
FreeQ[...,2] determines whether 2 cards of the same type or in the triple.
If 2 is not among the tallies, then the three cards are a "set", according to Game of Set rules.

Usage
f["OR1N WP2N DG3N DR1D WG3S WG1N WR2D WP3N DR2O DR1D OG3O OR2D"]

{{"DG3N", "WG3S", "OG3O"}, {"OR1N", "WP2N", "DG3N"}, {"WP2N", "DR1D",
    "OG3O"}}

It can be shorter if duplicates are allowed. f=Select[StringSplit@#~Subsets~{3},FreeQ[Tally/@Thread@Characters@#,2]&]& Output will be {{"OR1N", "WP2N", "DG3N"}, {"WP2N","DR1D", "OG3O"}, {"WP2N", "DR1D", "OG3O"}, {"DG3N", "WG3S", "OG3O"}}

Very clever way to check for "all same" or "all different"!

Mathematica 73
f = Select[StringSplit@#~Subsets~{3}, FreeQ[Tally /@ Thread@Characters@#, 2] &] &

Usage
f["OR1N WP2N DG3N DR1D WG3S WG1N WR2D WP3N DR2O DR1D OG3O OR2D"]

{{"OR1N", "WP2N", "DG3N"}, {"WP2N", "DR1D", "OG3O"}, {"WP2N", "DR1D", "OG3O"}, {"DG3N", "WG3S", "OG3O"}}

Brachylog, 12 bytes
ṇ₁⊇Ṫz{=|≠}ᵐz

Try it online!
Takes input through the input variable and generates the output through the output variable.
Second test case taken from a recently closed duplicate in its encoding, since this solution doesn't really care what anything actually means.
                The output variable is
  ⊇             a subsequence
   Ṫ            of length 3
ṇ₁              of the input split on spaces,
    z      z    the columns of which
     {   }ᵐ     are all
       |        either
      =         the same element repeated,
        ≠       or entirely free of duplicates.

+1 byte if output can't be a list of character lists, as opposed to a list of strings

GolfScript, 53 characters
" "/:w,,{:a,{:^,{a^]{w=}%.0\zip{.&,2=|}/!{.p}*;}/}/}/

Input must be provided on STDIN, example online:
> OR1N WP2N DG3N DR1D WG3S WG1N WR2D WP3N DR2O DR2D OG3O OR2D
["OR1N" "DG3N" "WP2N"]
["WP2N" "OG3O" "DR1D"]
["DG3N" "OG3O" "WG3S"]
["WR2D" "OR2D" "DR2D"]

Commented code:
" "/:w          # split the input at spaces and assign it to variable w
,,              # create the array [0..n-1] (n being the length of w)
{:a,{:^,{       # three nested loops: a=0..n-1, ^=0..a-1, _=0..b-1
                # (third loop has no variable assigned but just pushes on stack)
    a^]         # make an array [a,^,_] of the three loop variables
    {w=}%       # take the corresponding list items, i.e. [w[a],w[^],w[_]]
    .0\         # push zero, add duplicate of the the array
    zip         # zip transposes the array, thus [OR1N WP2N DG3N] -> [OWD RPG 123 NNN]
    {           # loop over those entries
      .&        # unique
      ,2=       # length equals 2?
      |         # "or" with top of stack (two zero pushed before)
    }/          # end of loop, on stack remains the results of the "or"s
    !{.p}*      # if no length of 2 is there, make a copy of the set and print it
    ;           # discard stack item
}/}/}/          # closing the three nested loops

I would say a clear winner for a code-golf. Hower totally unreadable..

@drjerry Compared with other golfscript code it's quite readable. E.g. it contains only plain loops and no advanced tricks. I'll add an explanation of the code later.

0\zip{.&,2=|}/! can be shortened to zip{.&,}%2&!

javascript 323 313
function a(b){d=h=[];c=e=f=0;for(i in b){for(j in b){for(k in b[i]){if(b[i][k]==b[j][k]){if(c+f<4)c++;else if(c==4){h+=b[j];if(h.length=3)return h}}else{for(l in d){for(m in d[l]){g=f;if(d[l][2]==i){if(d[l][3]==k)if(b[j][k]!=d[l][0]&&b[j][k]!=d[l][1])f++;}else{continue}}if(g==f)d[e++]=[b[i][k],b[j][k],j,k]}}}}}}

its a function that takes a array of objects, and returns a array of objects.
DEMO fiddle (with tidy-up).

You don't have to declare variables...

@Doorknob i take it back, you are right. edited. thanks!

APL(IBM), 76
⍉¨x/⍨{{⍵≡1⌽⍵}⍵=1⌽⍵}¨x←⊃¨(∘.,/3⍴⊂⍪¨(' '≠y)⊂y←⍞)⌷⍨¨z/⍨∧/¨2</¨z←,⍳3⍴12

I don't have IBM APL, but I believe this will work.
Sample run (Emulating IBM APL in Dyalog APL)
OR1N WP2N DG3N DR1D WG3S WG1N WR2D WP3N DR2O DR1D OG3O OR2D
 OR1N  WP2N  WP2N  DG3N
 WP2N  DR1D  DR1D  WG3S
 DG3N  OG3O  OG3O  OG3O

First time I see apl code thanks!

Sage, 71
If C is a string, say "OR1N WP2N DG3N DR1D WG3S WG1N WR2D WP3N DR2O DR1D OG3O OR2D", execute
[c for c in Subsets(C.split(),3)if{1,3}>={len(set(x))for x in zip(*c)}]

to get [{'DR1D', 'OG3O', 'WP2N'}, {'DR2D', 'WR2D', 'OR2D'}, {'WG3S', 'OG3O',
'DG3N'}, {'DG3N', 'WP2N', 'OR1N'}]
And here's a very different approach using the interpretation that a Set is a projective line in GF(3)^4:
[c for c in Subsets(C.split(),3)if sum(matrix(3,map('WODRPG123N'.find,''.join(c))))%3==0]

I was a little annoyed that D was used twice... until I figured how to abuse that.  But even better, I abuse the find method, too. str.find returns -1 if a letter isn't found.  Since -1 = 2 mod 3, the letter S is handled appropriately because it doesn't occur in 'WODRPG123N'.

Python 2, 99 bytes
lambda A:[a for a in combinations(A,3)if all(len(set(t))-2for t in zip(*a))]
from itertools import*

Try it online!

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

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


text:
Shortest Mirror Quine Challenge
Find the shortest mirror quine in a language of your choice.
A mirror quine is a quine whose source code is equal to the reverse of its own source code.
Note:
1) Length of source code should be atleast 2.
2) Quines not allowed are the one whose text can be echoed directly.
Example: Let L' be any language, then a quine with source code like ABBA or ABCBA is a mirror quine.

Maybe you also want to exclude the form code+comment char+reverse code.

@Howard yes, thanks for pointing this out..

does ( mirror as (, or as ) (and similarly for other brackets)? If it's the former, then I think it disqualifies any potential solution. Even golfscripters need blocks.

@Howard what you suggest? or lets wait for atleast a single possible solution :P

or lets wait for at least a single possible solution considering "(" mirrors as "(" (and similarly for other brackets) and also exclude the form code+comment char+reverse code

@Codingman My Befunge program does exactly that

The name "mirror quine" is confusing. It sounds like a program that outputs the reverse of its source (itself an interesting challenge perhaps). Yours is a palindromic quine.

For anyone looking for the non-closed, clearly specified version of this challenge, it's here. Unfortunately, I can't re-close as duplicate without moderator intervention, and a comment works almost as well as getting the moderators would.

HQ9+, 3 Characters
Am I cheating?
+Q+

The right tool for the task.

Finding an unexpected use for HQ9+ is always a good thing, so if it is a cheat, it's completely justified.

Perl, 53 characters
Perl's multifaceted text-handling features once again prove useful for golfing.
---BEGIN---

say$/.reverse$_=<<'';say
yas;''<<=_$esrever./$yas

----END----

Ignore the BEGIN and END markers; they're just there to keep the blank lines at the beginning and end from being suppressed from display. Yes, the source really does have two blank lines at the top and one blank line at the bottom. This apparent lack of symmetry may throw you at first, but that's just the nature of line breaks. What's really happening, of course, is that the source both begins and ends with two line break characters.

wait, what? No parens? +1 from me

Why 2 line breaks at beginning and end? Why not 1?

The concluding blank line closes the here-doc.

Golfscript, 33 characters
""~.{'""~.'print tnirp'.~""'}.~""

Since every language uses parentheses of some form, I assert the "( mirrors to (" version of this challenge is impossible (under rule #2), and assume ( mirrors to ). Additionally, this version provides more visual symmetry.
If trailing whitespace is allowed, empty strings can be replaced with newlines (29 characters):
n~.{'n~.'print tnirp'.~n'}.~n

Proceeds as follows:

""~. pushes an empty string onto the stack, evaluates it and clones the input (empty string)
{...} is a block
.~"" clones the block, evaluates one copy and pushes an empty string to the stack.

That block:

'""~.' pushes the string ""~. onto the stack
print outputs it directly and removes it from the stack
tnirp is an undefined symbol and does nothing
'.~""' pushes the string .~"" onto the stack

After the program finishes, the stack contents are printed:

the empty string (twice)
the main block, including delimiters
the program suffix as a string
another empty string

Befunge 98 - 40 35 31 or 29 characters
#r:0g,:a3*`!e*j@j*e!`*3a:,g0:r#

Saved another 4 characters, for 31 total, and complied with specs.
Or, if the other code can just be filler (29):
>:0g,:e2*`!e*j@j*e!`*2e:,g0:>

Old Version
#r:0g,:'#`3+ja+1r@r1+aj+3`#':,g0:r#

Saved 5 characters by using ' to fetch the length of the program

#r:0g,:a4*`3+jb+1r@  @r1+bj+3`*4a:,g0:r#

Just a variation on a normal quine, but made into a palindrome.
:0g get the character at a location (counter, 0)
,   print it
:   take the counter
a4* get 10 * 4 (40, length of program)
`   compare them (0 if counter is less or equal, 1 if greater)
3+  add 3
j   jump that amount (4 or 3)

if 4:
@   end program

if 3:
r   head the other way (to the left)
1+  increment counter
bj  jump 11 chars (to beginning r (reverse direction again))

Mouse-2002, 73 bytes
2 0&FOPEN (x.74<^2&F?' !'x.1+x:)36!'~'!63):x+1.x'!'? F&2^<75.x( NEPOF&0 2


text:
Nth K-Ugly Number
Write the shortest code in any language of your choice to find the \$N\$th \$K\$-ugly number.
A \$K\$-ugly number is a number whose only prime factors are the prime numbers \$\le K\$.
\$K\$-ugly number's are popularly known as \$K\$-smooth numbers.
Constraints:

\$0 < N < 1000\$

\$0 < K < 25\$

Input:

N K (separated by a single space)

Output:

-1 (if no such number exists)
or
\$M\$ (if \$N\$th \$K\$-ugly number is \$M\$)

These numbers are usually referred to as k-smooth.

@primo hahaha.. thats funny. I never knew about k-smooth

You should exclude k=1.

Related: http://stackoverflow.com/questions/4600048/nth-ugly-number/4600082#4600082

@DavidCarraher Well, the objective is quite different and thus I think it is fine.

I now see that the present problem is of a more general nature.

May we assume a largest output? For example N=1000, K=2 gives 5.357543 x 10^300.

Mathematica 82 72 70
n_~u~k_:=(c=m=1;While[m <= n,If[FactorInteger[c][[-1,1]]<=k,m++];c++];c-1)

Usage
u[1, 5]
u[5, 2]
u[20, 3]
u[57, 5]
u[66, 13]
u[100, 5]
u[1000, 25]

1
16
96
324
110
1536
5474

Prime factors and their powers are in the center column.
Table[{t, FactorInteger[t], u[t, 5]}, {t, 15}] // Grid

n_~u~k_:= OMG! you made my day :)

c=1;m=1; can be replaced with c=m=1;

@alephalpha Yes. Good catch.

Python 2 - 63 bytes
i=t=1
n,k=input()
while~-n:i+=1;t*=i>k or i**n;n-=t%i<1
print i

Input is taken from stdin, comma separated.
Sample usage:
$ echo 1, 5 | python nth-k-smooth.py
1

$ echo 5, 2 | python nth-k-smooth.py
16

$ echo 20, 3 | python nth-k-smooth.py
96

$ echo 57, 5 | python nth-k-smooth.py
324

$ echo 66, 13 | python nth-k-smooth.py
110

$ echo 100, 5 | python nth-k-smooth.py
1536

$ echo 1000, 25 | python nth-k-smooth.py
5474

At N = 1000, the script has a reasonable execution time for all values K ≥ 7. For the input N = 1000, K = 2 the correct answer is 2999 ≈ 5.357543300·10300. Using an "increase by one" approach, as David Carraher's answer also does, it would take longer than the age of the universe to reach this value (considerably longer!).

syntax error at "n,k=input()"

The script is written for Python 2.

mine is Python 2.7.3, shouldn't it work? i m noob :)

My version is also 2.7.3. Are you sure you're receiving a Syntax Error and not EOF Error? If not run interactively, you will need to supply input via stdin, as in the usage examples above.

my mistake, its EOF error. I assumed your input is single space separated n and k as specified in the problem.

Hah.  This is shorter than the sage solution I'd come up with, using built-ins... problem being that they've got lotsa letters to be user-friendly: x.prime_divisors()... ugh

you never use that j

You're right... it was the counting variable for a loop which is no longer there. Thanks

APL(Dyalog), 38
{⍵≡1:¯1⋄⊃⌽⍺{0~⍨⍺↑y[⍋y←∪,⍵∘.×⍵]}⍣≡⍳⍵}/⎕

Finally, for once, APL has beaten GS!!

Sample
⎕:
      5 3
6

⎕:
      20 5
36

⎕:
      500 20
2028

⎕:
      50 1
¯1

Explanation
/⎕ Takes evaluated input (space-seperated numbers are interpreted as numerical array) and insert a function in between (reduce).
⍵≡1: If right argument (k) is 1
¯1 return -1 (¯ is the high-minus, APL's way of representing negative numbers)
⋄ Statement seperator used as else.
⍳⍵ Generate a numerical array from 1 to k
⍺{...}⍣≡ Recursively apply function until output of an iteration is the same as that of the last iteration (fixpoint), passing the left argument of outer function (N) as the left each iteration.
⍵∘.×⍵ Outer product of the left argument with itself (generating a multiplication table)
, Unravel the matrix to numerical array
∪ Remove duplicates
y[⍋y←...] Sort
⍺↑ Get the first N values (fills 0s if shorter than N)
0~⍨ Remove 0s
In short, ⍺{0~⍨⍺↑y[⍋y←∪,⍵∘.×⍵]}⍣≡⍳⍵ generates the first N k-smooth numbers
⊃⌽ get last value

R 133 characters
a=scan(n=2)
k=1:a[2]
i=m=0
while(m<a[1]){i=i+1;if(all(sfsmisc::factorize(i)[[1]][,1]%in%k[rowSums(!outer(k,k,`%%`))<3]))m=m+1}
cat(i)

Explanation:
k[rowSums(!outer(k,k,`%%`))<3]: k being here the sequence from 1 to K, this piece of code outputs the list of primes smaller or equal to K.
all(sfsmisc::factorize(i)[[1]][,1]%in%k[rowSums(!outer(k,k,`%%`))<3]): this checks that all of the primes used to factorize a number belong to the previous list. It uses a function from package sfsmisc that performs the prime factorization.

these brackets around m=m+1 are not necessary.

GolfScript, 42 characters
~),2>{:s,2>{s\%!},!},:^1+1+{$({*}+^%|}@*0=

Unfortunately, I had to insert several correction terms to get the indexing correct.
Examples:
> 5 2
16

> 20 3
96

> 66 13
110

> 1000 25
5474

Mathematica, 96 characters
{n,k}=%~Read~{Number,Number};If[n>k==1,-1,While[p<n,m++;If[Max@FactorInteger[m][[All,1]]<=k,p++]];m]

Ungolfed:
{n, k} = % ~Read~ {Number, Number};
If[n > k == 1,
  -1,
  While[p < n,
    m++;
    If[Max@FactorInteger[m][[All, 1]] <= k, p++]
  ]; m
]

I did manage to find a shorter solution, more in the spirit of Mathematica's functional programming style by avoiding the while-loop, but it runs out of memory without an upper bound on M. It also cheats on the space-seperated input, but I thought it was elegant (60 characters):
Select[Range@999,Max@FactorInteger[#][[All,1]]<=k&][[n]]~Check~-1

Ruby 1.9+, 101 chars
Sort of verbose but nice and functional:
require'Prime'
n,k=gets.split.map &:to_i
p (1..5474).select{|i|i.prime_division.all?{|j,l|j<=k}}[n-1]

edit:

The number constant 5474 represents the highest value the program will ever output (upper bound), and is the answer to N = 1000, K = 2. As Primo points out, this may be a little low.
If you for some reason would like to run this program, the upper bound can be changed to whatever you want. Increasing it by a few digits will however increase execution time dramatically1, even for small outputs.
A feature I find quite neat is that the program cleanly outputs nil if the output would exceed the upper bound.

5474 (the result of N = 1000, K = 23-28) as an upper bound might be a bit low. For example, N = 1000, K = 7 -> 385875.

@primo I totally agree. Added some clarification.

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


text:
Golfing: How many unit-length squares in a list of 2d coordinates?
Given a list of 2d (x, y) coordinates, determine how many unit squares (edge length 1 unit) can be formed using the coordinates.

Input will be an array of 0 or more pairs of coordinates: e.g. in JavaScript: numofsq([[0,0], [1,0], [1,1], [0,1]])
No duplicate coordinates in input
Input order will be random (random 2d coordinates).
Coordinate form: [x-coordinate, y-coordinate] (duh)
Order of coordinates: [0,0], [1,0], [1,1], [0,1] and [0,0], [0,1], [1,1], [1,0] denote the same unit square (to be counted just once)
Coordinates can be negative or positive integers (duh)
Function will return just the number of unit squares possible, 0 or more.

Test cases:
Input Coordinates Pairs                                               Expected Output
[0,0], [0,1], [1,1], [1,0], [0,2], [1,2]                              2
[0,0], [0,1], [1,1], [1,0], [0,2], [1,2], [2,2], [2,1]                3
[0,0], [0,1], [1,1], [1,0], [0,2], [1,2], [2,2], [2,1], [2,0]         4
[0,0], [0,1], [1,1], [1,0], [0,2], [1,2], [2,2], [2,1], [2,0], [9,9]  4

Spoiler Alert: Solution stuff here-onwards [JS]
Non-Golfed, quick and dirty, brute-force approach (included to provide some directions).

//cartesian distance function
function dist(a, b) {
    if (b === undefined) {
        b = [0, 0];
    }
    return Math.sqrt((b[0] - a[0]) * (b[0] - a[0]) + (b[1] - a[1]) * (b[1] - a[1]));
}

//accepts 4 coordinate pairs and checks if they form a unit square
//this could be optimized by matching x,y coordinates of the 4 coordinates
function isUnitSquare(a) {
    var r = a.slice(),
        d = [],
        c = [],
        i,
        j = 0,
        counter = 0;

    for (i = 1; i < 4; i++) {
        if (dist(a[0], a[i]) === 1) {
            d.push(a[i]);
            r[i] = undefined;
            counter++;
        }
    }
    r[0] = undefined;
    c = d.concat(r.filter(function(a) {return undefined !== a}));

    if (dist(c[0], c[1]) === 1) {j++};
    if (dist(c[1], c[2]) === 1) {j++};
    if (dist(c[2], c[0]) === 1) {j++};
    return counter === 2 && j === 2;
}

//a powerset function (from rosetta code)
//however, we will need only "sets of 4 coordinates"
//and not all possible length combinations (sets of 3 coords or
//sets of 5 coords not required). Also, order doesn't matter.
function powerset(ary) {
    var ps = [[]];
    for (var i=0; i < ary.length; i++) {
        for (var j = 0, len = ps.length; j < len; j++) {
            ps.push(ps[j].concat(ary[i]));
        }
    }
    return ps;
}

//so to capture only sets of 4 coordinates, we do
var res = powerset([[0,0], [0,1], [1,1], [1,0], [0,2], [1,2], [2,2], [2,1], [2,0]])
          .filter(function (a) {return a.length === 8;});

//and a little bit of hoopla to have a nice set of sets of 4 coordinates.
//(Dizzy yet? Wait for the generalized, 3D, cube of any edge length version ;))
var squareQuads = res.map(function(ary) {
    return ary.join().match(/\d\,\d/g)
       .map(function(e) {
           return [+e.split(',')[0], +e.split(',')[1]];
        });
});

//Finally, the last bit
var howManyUnitSquares = 0;
squareQuads.map(function(quad) {
    if (isUnitSquare(quad)) {
        howManyUnitSquares++;
    }
});

console.log(howManyUnitSquares);

//Cleaning up and putting those in-line stuff into a function
function howManySquares(r) { //r = [[x,y], [x,y], [x,y], [x,y], ......];
    var res = powerset(r)
          .filter(function (a) {return a.length === 8;});
    var squareQuads = res.map(function(ary) {
        return ary.join().match(/\d\,\d/g)
               .map(function(e) {
                   return [+e.split(',')[0], +e.split(',')[1]];
                });
    });

    var answer = 0;
    squareQuads.map(function(quad) {
        if (isUnitSquare(quad)) {
            answer++;
        }
    });

    return answer;
}

is [-1,0],[0,-1],[1,0],[0,1] a square?

@JohannesKuhn No, their edge lengths are not unity, but sqrt(2), so they are not unit squares.

But [-2,0],[0,-2],[2,0],[0,2] has a edge length of 2. Square?

@JohannesKuhn Square? Yes. UNIT Square? No.

APL(Dyalog), 30
+/{(2-/⍵)≡2-/,⍳2 2}¨,∘.,⍨⍣2⊂¨⎕

Well, in most cases, readability and char count is proportional.

Sample Output
⎕:
      (0 0)(0 1)(1 0)(1 1)(0 2)(1 2)(2 2)(2 1)(2 0)
4

Explaination
So, 4 points forms a unit square if and only if their relative positions are (1,1),(1,2),(2,1),(2,2)
{(2-/⍵)≡2-/,⍳2 2} is a function that return 1 or 0 (true/false) given a set of 4 points as input based on whether they are in relative positions and sorted in the order (1,1),(1,2),(2,1),(2,2):
⍳2 2 Generate a 2×2 matrix of the points (1,1),(1,2),(2,1),(2,2)
, Unravel that matrix to an array of points
2-/ Pair-wise subtraction reduce: (1,1) - (1,2) ; (1,2) - (2,1) ; (2,1) - (2,2), which gives the array [(0,-1),(-1,1),(0,-1)]
(2-/⍵) Pair-wise subtraction reduce on the input
≡ Check if the two arrays equal
The main program
⎕ Takes input and evals it. Things like (0 0)(0 1)(1 0)(1 1) evaluates to a nested array (Equivalent of [[0,0],[0,1],[1,0],[1,1]] in JS)
⊂¨ For every point (¨), enclose it in a scalar (⊂) ([[[0,0]],[[0,1]],[[1,0]],[[1,1]]])
∘.,⍨⍣2 For every pair of elements of the array, concatenate them to form a new array. ([ [[0,0],[0,0]],[[0,0],[0,1]]...) Repeat once. This gives all sets of 4 points that can be made using the given points. In some of these sets, the same point would be used multiple times, but these would not be unit squares so no need to waste keystrokes to remove them. (, concatenates 2 arrays, ∘. means "do that for every pair of elements", ⍨ means "use right operand as both left and right operands", and ⍣2 means "do this twice")
, As the previous operation would give a 4-dimensional array (note that nested arrays and multi-dimensional arrays are different things in APL), we have to unravel it to get an array of sets (of 4 points).
¨ For each of the sets,
{...} execute the aforementioned function. The result would be an array of 0s and 1s indicating whether the set is a unit square. Note that because the function also check ordering, duplicates are eliminated.
+/ Finally, sum resulting array to get the count.

Mathematica 65 chars
f@d_ := Length@Select[Subsets[d, {4}], Sort[g@#] == {1, 1, 1, 1, √2, √2} &]

Tests
f[{{0, 0}, {0, 1}, {1, 1}, {1, 0}, {0, 2}, {1, 2}}]

2

f[{{0, 0}, {0, 1}, {1, 1}, {1, 0}, {0, 2}, {1, 2}, {2, 2}, {2, 1}}]

3

f[{{0, 0}, {0, 1}, {1, 1}, {1, 0}, {0, 2}, {1, 2}, {2, 2}, {2, 1}, {2,0}}]

4

f[{{0, 0}, {0, 1}, {1, 1}, {1, 0}, {0, 2}, {1, 2}, {2, 2}, {2, 1}, {2,0}, {9, 9}}]

4

Explanation
Generates all subsets of 4 points and checks all the inter-point distances.
The sorted inter-point distances for a unit square are: `{1, 1, 1, 1, √2, √2}.
Length then counts the number of unit squares.

What is the definition of g?

Here is my shorter solution: f=Count[#-#[[1]]&/@(Sort/@#~Subsets~{4}.{1,I}),{0,I,1,1+I}]&

Ruby, 164 161 153 147 characters
f=->a{a.combination(4).map(&:sort).uniq.count{|x|[x[1][0]==l=x[0][0],x[3][0]==m=x[2][0],x[2][1]==n=x[0][1],x[3][1]==o=x[1][1],m-l==1,o-n==1].all?}}

It's actually very readable, except for the part that tests whether it's a unit square or not.
Probably many improvements possible, attempting to find them now.
Samples (all of them work):
puts f[[[0,0], [0,1], [1,1], [1,0], [0,2], [1,2]]]                             #--> 2
puts f[[[0,0], [0,1], [1,1], [1,0], [0,2], [1,2], [2,2], [2,1]]]               #--> 3
puts f[[[0,0], [0,1], [1,1], [1,0], [0,2], [1,2], [2,2], [2,1], [2,0]]]        #--> 4
puts f[[[0,0], [0,1], [1,1], [1,0], [0,2], [1,2], [2,2], [2,1], [2,0], [9,9]]] #--> 4

I may be able to find a trick with transpose, but I've been trying for a while and I can't. Here's what it does:
irb(main):001:0> a = [[5, 10], [5, 11], [6, 10], [6, 11]]
=> [[5, 10], [5, 11], [6, 10], [6, 11]]
irb(main):002:0> a.transpose
=> [[5, 5, 6, 6], [10, 11, 10, 11]]

Agree with the readable part - As someone who has never programmed in Ruby, I can still clearly understand the steps. Too bad JS doesn't have some combinatorics built in.

Python, 61 chars
f=lambda l:sum(1for x,y in l if{(x+1,y),(x,y+1),(x+1,y+1)}<l)

Sample:
>>> f({(0,0), (0,1), (1,1), (1,0), (0,2), (1,2)})
2
>>> f({(0,0), (0,1), (1,1), (1,0), (0,2), (1,2), (2,2), (2,1)})
3
>>> f({(0,0), (0,1), (1,1), (1,0), (0,2), (1,2), (2,2), (2,1), (2,0)})
4
>>> f({(0,0), (0,1), (1,1), (1,0), (0,2), (1,2), (2,2), (2,1), (2,0), (9,9)})
4

Mathematica, 56 characters
f=Count[#-#[[1]]&/@Subsets[{}⋃#.{1,I},{4}],{0,I,1,1+I}]&


text:
Bitwise GCD Challenge
Write the shortest iterative function to find gcd of two numbers (assume 32 bit numbers).
Rules:

Arithmetic, Comparison and Logical Operators are not allowed (except equality comparison (a==b) operator).
Function should work for both positive and negative numbers
No inbuilt functions allowed.
All bitwise operators allowed.

What is allowed in the loop head? Only zero-test?

@JanDvorak Can be anything, but within the limit of the rules

ok, does equality test count as comparison, or do we have to do a poor-man's XOR followed by a zero-check?

@JanDvorak No comparison operator allowed. You can use your second idea.

@JanDvorak Unfortunately XOR is also not allowed and has to be replaced by (a|b)&!(a&b). Together with no comparisons allowed this seems rather arbitrary to me and disqualifies lots of languages. Not interesting.

Are we at least allowed to do == 0 in languages where 0 is truthy?

there were some unnecessary restrictions, I updated them

possible duplicate of math with bitwise operators

Python - 196 bytes
def A(a,b):
 while b:a,b=a&~b|~a&b,(a&b)<<1
 return a
def G(a,b,i=0):
 if a>>31:a=A(~a,1)
 if b>>31:b=A(~b,1)
 while~a&b|a&~b:c,d=~a&1,~b&1;i=A(i,c&d);a,b=[b,a>>c,A(a,b),b>>d][c|d::2]
 return a<<i

Sample usage:
from random import randint
for i in range(10):
  a = randint(-2147483647,2147483647)
  b = randint(-2147483647,2147483647)
  print 'gcd(%d, %d) = %d'%(a, b, G(a,b))

Sample output:
gcd(-36916085, -1872111029) = 1
gcd(1355889652, 1816917540) = 188
gcd(-366482295, 1612196424) = 9
gcd(836632083, -1156302534) = 3
gcd(1223074731, -1299765354) = 123
gcd(-1154829176, 522085100) = 4
gcd(-1673024403, 1589241938) = 1
gcd(-1871498822, -1089342630) = 2
gcd(1653429392, 2095617430) = 2
gcd(1525670601, -1985869899) = 39

Implementation Notes

A -> a function which adds two integers.
a&~b|~a&b -> a^b
if a>>31 -> if a<0
a=A(~a,1) -> a=-a (taken together, if a>>31:a=A(~a,1) -> a=abs(a))
~a&1 -> a%2==0 a.k.a. a is even.

The function G begins by removing powers of 2 from both a and b (and shifting the result if both are even). When both a and b are odd, it continues on with a=b, b=(a+b)/2. This works because gcd(a, b) = gcd(a, a+b), and a+b is necessarily even. This would terminate noticeably sooner using a comparison and a subtraction (subtracting the smaller value from the larger), but neither are available.

great!!, first to answer

you are using recursion, please do it iteratively..

please, verify if the description was ambiguous "Write the shortest iterative function to find gcd of two numbers". If ambiguous, recursion will be fine and I will update the question else you have to update the code :P

I apologize. I must have skipped over the word 'iterative' while reading the description.


text:
Stopwatch for Alphabets
Implement Stopwatch for typing Alphabets
Alphabets = "a b c d e f g h i j k l m n o p q r s t u v w x y z".
Note

The program should run infinitely and should stop only when Esc button is pressed.
The stopwatch starts with keystroke "a" and ends with keystroke "z"
Output is the time taken to type the Alphabets correctly (ie. time take for 51 keystrokes)
If an illegal character occurs then stopwatch should stop and print "Failed"
If a new record is set then print "!!New record!!," TimeTaken
where, TimeTaken = time taken to print alphabets correctly.

Winner: One with the shortest code.

What do you mean by "new record"? Is the alphabet typed in over and over again?

yes, the program will run till we press "Esc"

@Codingman How exactly is the record supposed to be saved?

I created something like this a while back: https://ethproductions.github.io/type/ Level 15 is the alphabet.

Mathematica, 303
Here with white-space and expanded symbols.
Everything happens in the Switch statement of the EventHandler where I pattern match {pressed key, next letter}.
Might want to replace the Quit with something less sinister before hitting escape:
z := AbsoluteTime[];
f = "a"; y = Dynamic;
DynamicModule[{
  a = f~CharacterRange~"z", c = 1, d = f, r = \[Infinity]},
 EventHandler[
  y@d~InputField~String,
  "KeyDown" :> Switch[
    {CurrentValue@"EventKey", a[[c]]},
    {f ..},
      t = z; c++; d = y@a[[c]],
    {"z" ..},
      t = z - t;
      d = If[t < r,
         r = t; "!!New record!!,",
         ""] ~~ ToString@t;
      c = 1,
    {a_, a_},
      c++,
    {"\[RawEscape]", _}, Quit[],
    _, d = "Failed"; c = 1]]]

I apologize. "!!New record!!, TimeTaken" is not string completely. Instead, it is "!!New record!!," TimeTaken. TimeTaken is variable storing the time taken. I am not aware of Mathematica. I hope, you will handle it correctly

@Codingman Oh, I should have figured, just mindless copy+paste :)

C, 181
Note that in order for this to work, your terminal must be setup to not buffer characters.  One possible linux solution is here.  Should this be considered part of my code?
double t,c,r=2<<29;main(l){for(;l<27&&96+l++==(c=getchar());)l==2&&time(&t);if(c==27)return;t=difftime(time(),t);l-27?puts("Failed"):t<r&&printf("!!New record!! %f\n",r=t);main(1);}

Perl, 182
use Term::ReadKey;ReadMode 3;@a=a..z;while(1){$c=getc;$s=time if!$i;last if$c eq"\e";if($c ne$a[$i++]){print"Failed";last}if($i==@a){print"!!New record!!,",(time-$s);last}}ReadMode 0

There's probably room for improvement. I could also remove the ReadMode 0 from the end, saving 10 chars. In addition, it's not clear to me if the use of Term::ReadKey is OK or not for the Code Golf. If it's not, then I don't think that this particular golf can be solved with Perl.
Same program written properly and in a readable fashion:
use warnings;
use strict;
use Term::ReadKey;
use Time::HiRes qw(time);
ReadMode 3;
my @a=('a'..'z');
my $i=0;
my $s;
while (1) {
    my $c=ReadKey(0);
    $s=time if !$i;
    last if $c eq "\e";
    if ($c ne $a[$i++]) {
        print "Failed";
        last;
    }
    if ($i==@a) {
        print "!!New record!!,",(time-$s);
        last;
    }
}
ReadMode 0;


text:
Tips for golfing in Mathematica
What general tips do you have for golfing in Mathematica? I'm looking for ideas that can be applied to code golf problems in general that are at least somewhat specific to Mathematica (e.g. "remove comments" is not an answer).

Tips below vary from the most economical to the most often used:

Use Mathematica's high-level commands where possible, even bulky ones:

MorphologicalComponents: Code-Golf: Count Islands
Image manipulation capabilities: e.g. Today (September 24) is HONDA birthday
Subsets
IntegerPartitions
Distance and Similarity measures: e.g. EuclideanDistance can be a byte saver. Note however, that it's usually shorter to write Total@Abs[a-b] instead of a~ManhattanDistance~b and Max@Abs[a-b] instead of a~ChessboardDistance~b.

Use Graphics and Text for Ascii art: e.g Star programming!
and Build an analog clock
Dedicated symbols:

logic and set operations symbols instead of their long form names:
⋂, ⋃, ∧, ∨
Map and Apply: /@, //@. @@, @@@

Prefix and infix notation:

Print@"hello" in place of Print["hello"]
a~f~b in place of f[a,b]

When a function is used only once, a pure function may economize a character or two.
Joining strings in a list. ""<>{"a","b","c"} instead of StringJoin@{"a","b","c"}
Exploit listable functions. The longer the lists the better.
{a, b, c} + {x, y, z}= {a+x, b+y, c+z}
{2, 3, 4} {5, 6, 7}= {10, 18, 28}
{{a, b}, {c, d}}^{2, 3} = {{a^2, b^2}, {c^3, d^3}}

It's always shorter to write (Norm[#-#2]&) instead of EuclideanDistance.

Some built-in functions with long names can be replaced with shorter expressions.
For example:

Total => Tr for 1d arrays
Transpose => Thread or  (\[Transpose])
True => 1<2
False => 1>2
Times => 1##&
Alternatives => $|##&
IntegerQ => ⌊#⌋==#& or 1∣#& (Thanks to @Misha Lavrov)
a[[1]] => #&@@a
a[[All,1]] => #&@@@a
ConstantArray[a,n] => Array[a&,n] or Table[a,n]
Union@a => {}⋃a or a⋃a
ToExpression@n => FromDigits@n if n is a number
Divisible[n,m] => m∣n
FromDigits[n,2] => Fold[#+##&,n] if n is a list of 0s and 1s
Complex@z => {1,I}.z where z is a list of the form {x,y}
Rest@FoldList[f[#,#2]&,x,l] => t=x;(t=f[t,#])&/@l
Table[f[i,l],{i,Length@l}] => i=1;f[i++,l]&/@l
CoefficientList[f,x] => (f+O@x^n)[[3]] if you know that the degree of the polynomial f is n and the constant term is not zero
FractionalPart[x] => Mod[x,1] if x is nonnegative

I don't get the Transpose[] thing

@belisarius Thread[{{a,b},{c,d}}]==Thread[List[{a,b},{c,d}]]=={List[a,c],List[b,d]}=={{a,c},{b,d}}==Transpose[{{a,b},{c,d}}]

Oh, I see. Very clever:)

I think your Fold trick for FromDigits also works for any other base except 10. E.g. FromDigits[n,5] --> Fold[4#+##&,n] (with the bonus of saving an extra byte for bases 100 and 1000).

How many bytes is \[Transpose]?

@mbomb007 3 bytes in UTF-8. In fact this character is U+F3C7.

Is it possible to type the symbol with a keyboard, or would I need to copy/paste it?

@mbomb007 Just type \[Transpose] in a Mathematica notebook.

I mean is it possible to type it on PPCG?

@mbomb007 . It's in the private use area.

What "private use area"?

@mbomb007 https://en.wikipedia.org/wiki/Private_Use_Areas

I finally installed 10.3. If we're considering full programs, I don't think Echo is an option, because it prints >> (and a space) to STDOUT before printing the actual string.

⌊ and ⌋ take at least 3 bytes each, I think? So the IntegerQ replacement is longer.

For Complex[x,y] => {1,I}.{x,y}, I think x+y*I is much shorter with the same effect?

As mentioned, ⌊#⌋==#& is not an improvement on IntegerQ (it's the same number of bytes as Floor@#==#&) but 1∣#& (where ∣ is the 3-byte Unicode symbol for \[Divides]) is. Example: https://codegolf.stackexchange.com/a/173447

@ShieruAsakoto that form is useful with Complex@@z vs {1,I}.z where z={x,y}

Identity/#& (single argument identity function) -> D or N

Lists with repeated values
This is quite a common vector to work with:
{0,0}

It turns out this can be shortened by a byte:
0{,}

Even more bytes are saved if the vector is longer than two zeros. This can also be used to initialise zero matrices, e.g. the following gives a 2x2 matrix of zeros:
0{{,},{,}}

This can also be used for non-zero values if they're sufficiently large or sufficiently many or negative. Compare the following pairs:
{100,100}
0{,}+100

{-1,-1}
0{,}-1

{3,3,3,3}
0{,,,}+3

But remember that starting at 6 values, you're better off with 1~Table~6 in this case (potentially earlier, depending on precedence requirements).
The reason this works is that , introduces two arguments to the list, but omitted arguments (anywhere in Mathematica) are implicit Nulls. Furthermore, multiplication is Listable, and 0*x is 0 for almost any x (except for things like Infinity and Indeterminate), so here is what's happening:
  0{,}
= 0*{,}
= 0*{Null,Null}
= {0*Null,0*Null}
= {0,0}

For lists of 1s, you can use a similar trick by making use of exponentiation rules. There are two different ways to save bytes if you have at least three 1s in the list:
{1,1,1}
1^{,,}
{,,}^0

+1; this just goes to show that while Mathematica may have a built-in for everything, golfing in it can be a real challenge.

If you want an array that's ultimately filled with 1s, then 1^{,,,} is one byte smaller than 0{,,,}+1.

@MishaLavrov Oh, good catch. That makes it shorter at three values and you can also use {,,}^0. I'll edit the post.

Know your pure function arguments
When golfing code, you'll often employ a functional approach, where you use anonymous (pure) functions with the & shorthand syntax. There are a lot of different ways to access the arguments of such a function, and you can often shave off a couple of bytes by having a good grasp on the possibilities.
Accessing single arguments
You probably know this if you've used pure functions before. The nth argument is referred to as #n, and # acts as an alias for #1. So if, say, you want to write a function that takes as parameters another function and its argument (to pass the argument to that function), use
#@#2&

This does not work with negative numbers (such as you might use when accessing lists).
Accessing named arguments (new in V10)
One of the major new language features in Mathematica 10 is Associations, which are basically key-value maps with arbitrary key types, written like
<| x -> 1, "abc" -> 2, 5 -> 3 |>

If such an association is passed in as the first argument to a pure function, you can access some if its arguments as named parameters:
{#, #2, #3, #abc, #xyz} & [<| "abc" -> "1st", "xyz" -> "2nd", abc -> "3rd" |>, "4th", "5th"]
(* {<| "abc" -> "1st", "xyz" -> "2nd", abc -> "3rd" |>, "4th", "5th", "1st", "2nd"} *)

Note that # still refers to the entire association as expected. For the named parameters to work, the keys have to be strings (it won't work if you use undefined variables for instance), and those strings must begin with a letter and only contain letters and digits.
The "self" argument #0
A lesser known feature is that #0 also exists, and gives you the function object itself. This can be really useful in quines and generalised quines. In fact, the shortest Mathematica quine (I know of) is
ToString[#0][] & []

What's slightly annoying is that it won't give you the exact characters you entered. E.g. if use @ for function application, it will still render as [...] and spaces will be inserted in some places. This will usually make the quine a bit longer than you'd like it to be, but it will always work, by golfing the quine first, and then just copying its output - which should now be a real quine.
Apart from quines, this also means that you can write recursive code without having to name your function. Compare these three (naive but golfed) Fibonacci implementations:
f@0=0;f@1=1;f@n_:=f[n-1]+f[n-2]
f@n_:=If[n<2,n,f[n-1]+f[n-2]]
If[#<2,#,#0[#-1]+#0[#-2]]&

Sequences of arguments
Now this is where the real magic starts. Sequences aren't used often in golfing, because Sequence it's just too long a name to be worth it most of the time. But in pure functions is where they shine. If you're not familiar with sequences, they are basically like splats in some other languages, if you use a sequence in a List or the argument list of a function, it's elements will automatically be expanded into separate slots. So
{1, Sequence[2, 3, 4], 5} == {1, 2, 3, 4, 5}
f["a", Sequence[0, {}], "b"] == f["a", 0, {}, "b"]

Now, in pure functions ## or ##1 is a sequence of all the arguments. Likewise, ##2 is a sequence of all arguments starting from the second, ##3 all arguments starting from the third etc. So for a start, we can just reimplement Sequence as ##&, saving 5 bytes. As an example usage, this provides us with an alternative to Join@@list (see this tip), which doesn't save any bytes, but is good to know about anyway:
 ##&@@@list

This effectively flattens the first level of a nested list. What else can we do with this? Here is a 1-byte saving for RotateLeft:
 RotateLeft@list
 {##2,#}&@@list

For these things alone it's worth keeping this feature in mind. However, we can do better! Sequences get really interesting when consider that operators are actually implemented as functions under the hood. E.g. a+b actually evaluates to Plus[a,b]. So if we give that a sequence...
1+##&[1,2,3]
=> Plus[1,##]
=> Plus[1,1,2,3]
=> 7

This trick has been use in this tip to save a byte on Times, because juxtaposition is technically also just an operator:
1##&[1,2,3]
=> Times[1,##]
=> Times[1,1,2,3]
=> 6

You can also use it to save a byte on Unequal if you have a single-character value or variable you know is not in your arguments (N will probably work in 99% of the cases):
Unequal[a,b,c]
N!=##&[a,b,c]

This gets even more interesting with unary operators and - and / - the latter two are actually implemented in terms of multiplication and exponentiation. Here is a list of things you can do, where the last column assumes that the function was passed the arguments a, b, c:
Operator    Function                Expanded                    Equivalent to

+##         Plus[##]                Plus[a,b,c]                 a+b+c
1##         Times[1,##]             Times[1,a,b,c]              a*b*c
-##         Times[-1,##]            Times[-1,a,b,c]             -a*b*c
x+##        Plus[x,##]              Plus[x,a,b,c]               x+a+b+c
x-##        Plus[x,Times[-1,##]]    Plus[x,Times[-1,a,b,c]]     x-a*b*c
x##         Times[x,##]             Times[x,a,b,c]              x*a*b*c
x/##        Times[x,Power[##,-1]]   Times[x,Power[a,b,c,-1]]    x*a^b^c^-1
##/x        Times[##,Power[x,-1]]   Times[a,b,c,Power[x,-1]]    a*b*c/x
x^##        Power[x,##]             Power[x,a,b,c]              x^a^b^c
##^x        Power[##,x]             Power[a,b,c,#]              a^b^c^x
x.##        Dot[x,##]               Dot[x,a,b,c]                x.a.b.c

Other common operators are !=, ==, &&, ||. Less common ones to keep in mind are |, @*, /*. To conclude, here is a little bonus trick:
####        Times[##,##]            Times[a,b,c,a,b,c]          (a*b*c)^2

Keep experimenting with these, and let me know if you find any other useful or particularly interesting applications!

I think you meant {##2,#}&@@list rather than {##2,#}&@list.

@theorist Good catch, thank you!

Sqrt@2 or 2^.5 => √2
a[[1]]=>a〚1〛
#+#2&=>+##&
Flatten@a=>Join@@a (sometimes)
Function[x,x^2]=>xx^2 or #^2&
a〚1;;-1;;2〛=>a〚;;;;2〛
a〚2;;-1 ;;2〛=>a〚2;;;;2〛
a〚All,1〛=>a〚;;,1〛
{{1}}〚1,1〛=>Tr@{{1}}
0&~Array~10=>0Range@10
Range[10^3]=>Range@1*^3

Note that when measuring by bytes, using 〚 and 〛 takes 3 bytes each (assume UTF8)

Note that, whileSqrt@2 ⟹ √2, 2^.5 !⟹ √2 (at least not exactly), as the latter will return a numerical result rather than a symbolic one, i.e., 1.14121...

Operators as Functions
Inspired by Dennis's recent discovery for Julia I thought I'd look into this for Mathematica. I was aware that Mathematica defines a large number of unused operators, but never paid much attention to it.
For reference, the list of all operators can be found here in the form of a precedence table. The triangle in the last column indicates whether that operator has a built-in meaning or not. While not all of those that don't can be defined easily, most of them can.
Conveniently, there are two unused operators with a codepoint less than 256, such that they can be used as single bytes in an ISO 8859-1 encoded source file:

± (0xB1) can be used either as a unary prefix operator or a binary infix operator.
· (0xB7) can be used as a variadic or n-ary infix operator, for n > 2.

There's one more catch though: for some weird reason when defining these operators you need one space in front of them, or else Mathematica tries to parse a multiplication. When using them you don't need any spaces though:
±x_:=2x
x_ ±y_:=x+y
x_ ·y_ ·z_:=x*y+z
Print[±5]  (* 10 *)
Print[3±4] (*  7 *)
Print[3·4·5] (* 17 *)

Compare this with:
f@x_:=2x
x_~g~y_:=x+y
h[x_,y_,z_]:=x*y+z
Print[f@5]   (* 10 *)
Print[3~g~4] (*  7 *)
Print[h[x,y,z]] (* 17 *)

So this saves one byte when defining the function and two bytes when using it. Note that the definition of · will not save bytes for four operands and will start costing bytes for more operands, but the usage may still save bytes, depending the precedence of operators used in the arguments. It's also good to note that you can cheaply define a variadic function that can then be called much more efficiently:
x_ ·y__:={y}
Print[1·2·3·4·5] (* {2, 3, 4, 5} *)

But note that it's not easily possible to call these variadic functions with a single argument. (You could do CenterDot[x] or ##&[]·x but if you actually need that there's a good chance you're better off with a different solution.)
Of course, this isn't saving anything for solutions where an unnamed function suffices, but sometimes you need to define helper functions for use later on, and sometimes it's shorter to define named functions e.g. to set up different definitions for different parameters. In those cases, using an operator instead can save a decent amount of bytes.
Note that using these ISO 8859-1 encoded files requires $CharacterEncoding to be set to a compatible value, like the Windows default WindowsANSI. On some systems this defaults to UTF-8 which won't be able to read these code points from single bytes.

This is really great, I did not know Mathematica had a list of operators, and even included their precedence. Those two operators you found I'm sure will come in handy.

Explore recursive solutions -  Mathematica is multi-paradigm, but the functional approach is often the most economical. NestWhile can be a very compact solution to searching problems, and NestWhileList and FoldList are powerful when you need to return or process the results of intermediate iterations. Map (/@), Apply (@@, @@@), MapThread, and really everything on Wolfram's Functional Programming documentation page is potent stuff.
Shortened form for increment/decrement - For example, instead of While[i<1,*code*;i++] you can doWhile[i++<1,*code*]
Don't forget you can pre-increment/decrement - For example, --i instead of i--. This can sometimes save you a few bytes in the surrounding code by eliminating a preparatory operation.
Corollary to David Carraher's #5: When the same function is used many times, assigning a symbol to it can save bytes. For example, if you are using ToExpression 4 times in a solution, t=ToExpression enables you to use t@*expression* thereafter. However, before you do this consider whether the repeated application of the same function indicates an opportunity for a more economical recursive approach.

MapThread can often be replaced by \[Transpose]. TIO.

Choosing values based on integer
The naive approach to choose between y and z, depending on whether x is 0 or 1 is
If[x<1,y,z]

However, there's a shorter way:
y[z][[x]]

This works because [[0]] gives the Head of an expression, in this case y, whereas [[1]] just gives the first element - in this case the first argument, z.
You can even use this to choose between more than two values:
u[v,w][[x]]

Note that this won't work if u is a function that actually evaluates to something. It's important that Mathematica keeps u[v,w] as it is. However, this works in most cases, including if u is a is a number, a string or a list.
Credits for this trick go to alephalpha - I discovered this in one of his answer.
If x is 1-based instead of zero-based, just use
{y,z}[[x]]

or
{u,v,w}[[x]]

In some rare cases, you can even make use of the fact that multiplication is not evaluated for some values:
{"abc","def"}[[x]]
("abc""def")[[x]]

Note though that Mathematica will actually reorder the arguments, of a multiplication if it remains unevaluated, so the above is identical to
("def""abc")[[x]]

Alternatives to Length
This has been entirely rewritten with some suggestions from LegionMammal978 and Misha Lavrov. Many thanks to both of them.
In many cases, Length can be shortened a bit by making use of Tr. The basic idea is to turn the input into a list of 1s, so that Tr sums them up which will then equal the length of the list.
The most common way to do this is to use 1^x (for a list x). This works because Power is Listable and 1^n for most atomic values n is just 1 (including all numbers, strings and symbols). So we can already save one byte with this:
Length@x
Tr[1^x]

Of course, this assumes that x is an expression with higher precedence than ^.
If x contains only 0s and 1s, we can save another byte using Factorial (assuming x has higher precedence than !):
Length@x
Tr[x!]

In some rare cases, x might have lower precedence than ^ but still higher precedence than multiplication. In that case it will also have lower precedence than @, so we really need to compare with Length[x]. An example of such an operator is .. In those cases, you can still save a byte with this form:
Length[x.y]
Tr[0x.y+1]

Finally, some remarks about what kind of lists this works on:
As mentioned at the top, this works on flat lists containing only numbers, strings and symbols. However, it will also work on some deeper lists, although it actually computes something slightly different. For an n-D rectangular array, using Tr gives you the shortest dimension (as opposed to the first). If you know that the outermost dimension is the shortest, or you know they're all the same, than the Tr-expressions are still equivalent to Length.

Just found an even shorter solution: Length@x == Tr[1^x]. Should work with most lists.

@LegionMammal978 that's amazing, thanks :). I'll edit it in soon.

Twice now, I've found myself using Tr[x!] instead of Tr[1^x] to save one byte in the special case where x only contains zeroes and ones.

@MishaLavrov That's really neat! :)

Don't use {} if you are using @@@.
In some cases, you may encounter an expression like:
f@@@{{a,b},{c,d}}

It is possible to reduce bytes by writing:
f@@@{a|b,c|d}

Alternatives has a very low precedence, so it's generally okay to write expressions (a notable exception is pure functions; you can use it only in the leftmost element of Alternatives).
f@@@{f@a|b~g~1,#^2&@c|d@2}

Note that f@@a|b|c (instead of f@@{a,b,c}) does not work because Apply has a higher precedence than Alternative.
In this case, you should simply use f@@{a,b,c}.

Don't write 0-argument functions
There is no need for code like this:
f[]:=DoSomething[1,2]
(*...*)
f[]
(*...*)
f[]

You can simply use a variable with := to force re-evaluation of the right-hand side:
f:=DoSomething[1,2]
(*...*)
f
(*...*)
f

This also means that you can alias any action that you perform often (even if it's just something like n++) to a single character at the cost of 5 bytes. So in the case of n++ it pays back after the fourth use:
n++;n++;n++;n++
f:=n++;f;f;f;f

Mathematica 10 only
Operator forms
Mathematica 10 supports so-called "operator forms", which basically means some functions can be curried. Currying a function is to create a new function by fixing one of its operators. Say, you're using SortBy[list, somereallylongfunction&] a lot of different lists. Before, you probably would have assigned SortBy to s and the pure function to f so
s=SortBy;
f=somereallylongfunction&;
list1~s~f;
list2~s~f;
list3~s~f;

Now you can curry SortBy, which means you can now do
s=SortBy[somereallylongfunction&];
s@list1;
s@list2;
s@list3;

The same works for a lot of other functions, which take a list or function argument, including (but not limited to) Select, Map, Nearest, etc.
ybeltukov over on Mathematica.SE was able to produce a complete list of these:
{"AllTrue", "AnyTrue", "Append", "Apply", "AssociationMap", "Cases",
 "Count", "CountDistinctBy", "CountsBy", "Delete", "DeleteCases",
 "DeleteDuplicatesBy", "Extract", "FirstCase", "FirstPosition",
 "FreeQ", "GroupBy", "Insert", "KeyDrop", "KeyExistsQ", "KeyMap",
 "KeySelect", "KeySortBy", "KeyTake", "Map", "MapAt", "MapIndexed",
 "MatchQ", "MaximalBy", "MemberQ", "Merge", "MinimalBy", "NoneTrue",
 "Position", "Prepend", "Replace", "ReplacePart", "Scan", "Select",
 "SelectFirst", "SortBy", "StringCases"}

Composition and RightComposition
There are new shorthands for Composition (@*) and RightComposition (/*). An obviously contrived example where these can save characters is seen in the following three equivalent lines
Last@Range@# & /@ Range[5]
Last@*Range /@ Range[5]
Range /* Last /@ Range[5]

If you need a list of numbers sorted in reverse, don't use
Reverse@Sort@x

but
-Sort@-x

to save six bytes. Sorting by a negative value is also useful for SortBy scenarios:
Reverse@SortBy[x,Last]
SortBy[x,-Last@#&]

What about -Sort@-x?

@JungHwanMin Oh, uhhh, yeah, that's much better. :)

Use Null as an iteration variable
As has been mentioned elsewhere, missing arguments are interpreted as Null. Since iterators such as those used in Sum or Table localize the iteration variable, symbols such as Null can be used as the iteration variable, potentially saving bytes.
For example,
Sum[,{,10}]

is interpreted as Sum[Null,{Null,10}], which evaluates to the expected 55.

Checking if a list is sorted
This is essentially a corollary of this tip but this is a sufficiently common task that I think it warrants its own answer.
The naive way to check if a list is in order is to use
OrderedQ@a

We can do one byte better with
Sort@a==a

However, this doesn't work if we don't have the thing we want to check in a variable already. (We'd need something like Sort[a=...]==a which is unnecessarily long.) However, there's another option:
#<=##&@@a

The best thing is that this can be used to check whether the input is reverse sorted for the same byte count:
#>=##&@@a

One more byte can be saved if a) we know that the list elements are distinct and b) we know a lower bound between 0 and 9 (inclusive; or upper bound for reverse sorted order):
0<##&@@a
5>##&@@a

To see why this works, check out "Sequences of arguments" in the tip linked at the top.

Alternatively, (strict) lower-bound for reverse-sorted also work: ##>0&@@a. Similar for upper-bound for sorted.

@user202729 Oh good point, feel free to edit (otherwise I'll try to do it on the weekend if I remember).

Use % to get a free variable
This tip is only applicable if Mathematica's REPL environment can be assumed. % is not defined when code is run as a script.
When you can make use of the REPL features, don't do this:
a=someLongExpression;some[other*a,expression@a,using^a]

Instead, remember that Mathematica stores the last evaluated (newline-terminated) expression in %:
someLongExpression;
some[other*%,expression@%,using^%]

The added newline costs a byte, but you are saving two by removing a=, so overall this saves one byte.
In some cases (e.g. when you want to print the value of a anyway), you can even leave off the ;, saving two bytes:
someLongExpression
some[other*%,expression@%,using^%]

One or two bytes may seem fairly minor, but this is an important case, because it makes extraction of repeated expressions (which is a very common technique) much more useful when golfing:
The normal technique of extracting repeated expressions costs four bytes of overhead, which need to be saved by further uses of the expression. Here is a short table of the minimum number of uses of an expression (by length of the expression) for extraction into a named variable to save anything:
Length   Min. Uses
2        6
3        4
4        3
5        3
6        2
...      2

By using the unnamed variable, it will be possible to save a couple of bytes much more often:
When ; is required                        When ; can be omitted

Length   Min. Uses                        Length   Min. Uses
2        5                                2        4
3        3                                3        3
4        3                                4        2
5        2                                ...      2
...      2

I don't think %% or %n can be used for golfing, because if you don't use them at least twice, you can just put the expression right where it's needed. And if you use it twice, the additional character in the variable name cancels out the savings from omitting some x=.

Note that it doesn't work in script mode.

@alephalpha What is script mode?

A mathematica script.

@alephalpha Oh right, I shut off my brain there for a second... so that would mean it can't be really be used at all, unless the REPL environment can be assumed.

Mathematica 10.2: BlockMap is Partition+Map
This tip could also be titled, "Read the release notes, all of them". (For reference, here are the release notes for 10.2 and here of today's 10.3 release.)
Anyway, even minor releases contain a wealth of new features, and one of the more useful ones (for golfing) from 10.2 is the new BlockMap function. It essentially combines Partition and Map, which is great for is golfers, because Partition is used quite often, and it's a really annoyingly long function name. The new function won't shorten Partition by itself, but whenever you want to map a function onto the partitions (which probably happens more often than not), you can now save a byte or two:
#&/@l~Partition~2
BlockMap[#&,l,2]

#&/@Partition[l,3,1]
BlockMap[#&,l,3,1]

The savings get even bigger when the new position of the unnamed function allows you to save yourself some parentheses:
#&@@(#&/@Partition[l,3,1])
#&@@BlockMap[#&,l,3,1]

Unfortunately, I have no idea why didn't also add BlockApply while they were at it...
Also note that BlockMap does not support the 4th parameter you can use with Partition to get a cyclic list:
Partition[Range@5, 2, 1, 1]
(* Gives {{1, 2}, {2, 3}, {3, 4}, {4, 5}, {5, 1}} *)
BlockMap[f, Range@5, 2, 1, 1]
(* Nope... *)

MovingMap[f,list,n-1] instead of BlockMap[f,list,n,1] when n-1 is at least as short as n; MovingMap also supports padding with a constant/list (but on the left by default).

Repeating a string
Instead of StringRepeat[str,n] use (0Range[n]+str)<>"". Or if str doesn't depend on any slot arguments, even better is Array[str&,n]<>"" as per this tip.

Corollary: instead of StringRepeat[s,n+1] use Array[s&,n]<>s (even when you already have n+1 in a variable, too).

Better, Table[str,n]<>""

Here is a list with loads of operator input forms which can shorten a lot of things. Some of these have been mentioned in other posts, but the list is long and I'm always surprised to find a few new things on there:

However, this only works when the operator uses less UTF-8 bytes.

You can stick an expression in Break which can save one or two characters. Example (other details not golfed for clarity):
result = False;
Break[]

can be turned into
Break[result = False]

to save one character. If the expression in question does not have lower precedence than function application you can even save another character:
Print@x;
Break[]

can be turned into
Break@Print@x

Although undocumented, the argument to Break seems to be returned by the surrounding loop, which can potentially lead to even more savings.

To remove all whitespace from a string s, use
StringSplit@s<>""

That is, use StringSplit's default (split into non-whitespace components) and simply join them back together. The same is probably still the shortest if you want to get rid of any other character or substring:
s~StringSplit~"x"<>""

Alternatives to Range
A very common task is to apply some sort of function to all numbers from 1 to a n (usually given as input). There are essentially 3 ways to do this (using an unnamed identity function as an example):
#&/@Range@n
Array[#&,n]
Table[i,{i,n}]

I tend to go for the first one (for whatever reason), but this is rarely the best choice.
Using Array instead
The above example shows that using Array has the same byte count. However, it has the advantage that it is a single expression. In particular, if you want to further process the result with a function f you can use prefix notation, which saves a byte over Range:
f[#&/@Range@n]
f@Array[#&,n]

Furthermore, you may be able omit parentheses around your unnamed function which you might have needed with Range, e.g.
15/(#&)/@Range@n
15/Array[#&,n]

If you don't want to use it further (or with an operator which has lesser precedence), you can instead write Array itself in infix notation and also save a byte:
#&/@Range@n
#&~Array~n

Hence, Array is almost certainly better than Range.
Using Table instead
Now table has to make up for 3 bytes, or at least 2 when infix notation is an option:
#&/@Range@n
i~Table~{i,n}

When not using infix notation, Table might allow you to omit parentheses if your function consists of several statements:
(#;#)&/@Range@n
Table[i;i,{i,n}]

This is still longer, but gives extra savings with in the case mentioned below.
The real savings stem from the fact that Table gives the running variable a name should not be dismissed. Often, you'll have nested unnamed functions where you want to use the outer variable inside one of the inner functions. When that happens, Table is shorter than Range:
(i=#;i&[])&/@Range@n
Table[i&[],{i,n}]
i&[]~Table~{i,n}

Not only do you save the characters for assigning i, you might also be able to reduce the function to a single statement in the process, which allows you to use infix notation on top of it. For reference, Array is also longer in this case, but still shorter than Range:
(i=#;i&[])&~Array~n

When would you actually use Range?
Whenever you don't need a function call to process the values, e.g. when the mapping can be performed via a vectorised operation. For instance:
5#&~Array~n
5Range@n

#^2&~Array~n
Range@n^2

Of course, it's also shorter if you don't want to map any function at all, e.g.
Mean@Array[#&,n]
Mean@Range@n

Finally someone else who uses f/@Range[x] regularly...

Finding the smallest number that satisfies a condition
Some construct like i=1;While[cond[i],i++] is fine as is, but there is an alternative that is two bytes shorter:
1//.i_/;cond[i]:>i+1

The above code repeatedly replaces a number i with i+1 while it meets the condition cond[i]. In this case, i starts at 1.
Note that the default maximum number of iterations is 2^16 (= 65536). If you need more iterations than that, While would be better. (MaxIterations->∞ is too long)

Storing functions and expressions in a variable
If your answer ends up using the same functions or expressions multiple times, you may want to consider storing them in variables.
If your expression is length l and you use it n times, it would normally use up l * n bytes.
However, if you store it in a length-1 variable, it would take only 3 + l + n bytes (or 2 + l + n bytes, if you assign the variable where you won't need CompoundExpression (;) or parentheses).

For example, let's consider a simple problem, finding twin primes less than N.
One could write this 54 byte solution:
Select[Range@#,PrimeQ@#&&(PrimeQ[#+2]||PrimeQ[#-2])&]&

In this example, the function PrimeQ is used three times.
By assigning PrimeQ a variable name, the byte count can be reduced. Both of the following are 48 bytes (54 - 6 bytes):
Select[p=PrimeQ;Range@#,p@#&&(p[#+2]||p[#-2])&]&
Select[Range@#,(p=PrimeQ)@#&&(p[#+2]||p[#-2])&]&

Abuse short-circuit evaluation
You can sometimes replace If with a logical operator.
For instance, let's say you want to make a function that checks whether a number is prime, and print 2*(number) - 1 is if it's true:
If[PrimeQ@#,Print[2#-1]]&

It's shorter if you use && instead:
PrimeQ@#&&Print[2#-1]&

Even when you have multiple expressions, you still save byte(s):
If[PrimeQ@#,a++;Print[2#-1]]&

PrimeQ@#&&a++&&Print[2#-1]&
(* or *)
PrimeQ@#&&(a++;Print[2#-1])&

You can use || for cases when you want the condition to be False:
If[!PrimeQ@#,Print[2#-1]]&
(* or *)
If[PrimeQ@#,,Print[2#-1]]&
(* can become *)
PrimeQ@#||Print[2#-1]&

These tricks work because logical operators can be short-circuited; the second argument and thereafter don't even need to be valid boolean expressions.
Of course, this does not work if you need the return value of If or when you need both truthy and falsy arguments of If.

Special characters
This post is community wiki. Feel free to edit and add more characters that you find useful.
Mathematica has many special named characters. Some of them are helpful for golfing. But these characters are hard to type outside Mathematica. Some are even in the Private Use Areas.
The following is a list of commonly used named characters, so that you can copy and paste.
Other than the 2-byte ° (\[Degree]), all of these characters are 3 bytes long.

: \[Conjugate], conjugate of a complex number
: \[ConjugateTranspose], conjugate transpose of a matrix
: \[Cross], cross product
°: \[Degree], degree, symbol that equals Pi/180
: \[DirectedEdge], directed edges in a graph; -> often works instead
∣: \[Divides], a∣b means b is divisible by a
∈: \[Element], tests membership in a domain or region (e.g. Primes, Ball[])
⧦: \[Equivalent], logical equivalence
: \[Function], anonymous functions; in Mathematica 12.3 or newer versions you can write |->
: \[HermitianConjugate], the same as  (\[ConjugateTranspose])
: \[Implies], logical implication
∞: \[Infinity], infinity
⋂: \[Intersection], set intersection
⌈: \[LeftCeiling], ⌈x⌉ is the ceiling of x
⌊: \[LeftFloor], ⌊x⌋ is the floor of x
⊼: \[Nand], logical nand
⊽: \[Nor], logical nor
: \[Piecewise], {{a,b}...} is mostly equivalent to Which[b,a,...,True,0]
⌉: \[RightCeiling], ⌈x⌉ is the ceiling of x
⌋: \[RightFloor], ⌊x⌋ is the floor of x
√: \[Sqrt], square root
: \[Transpose], transpose of a matrix
: \[UndirectedEdge], undirected edges in a graph; <-> often works instead
⋃: \[Union], set union
: \[VectorLess], xy means x[[i]]<y[[i]] for every i
: \[VectorLessEqual], xy means x[[i]]<=y[[i]] for every i
: \[VectorGreater], xy means x[[i]]>y[[i]] for every i
: \[VectorGreaterEqual], xy means x[[i]]>=y[[i]] for every i
: \[Xnor], logical xnor
⊻: \[Xor], logical xor

More can be found in this link: https://reference.wolfram.com/language/guide/ListingOfNamedCharacters.html

Using Optional (:)
Optional (:) can be used to expand lists in replacements, without having to define a separate rule for the expansion.
This answer by me and this answer by @ngenisis are examples.
Usage
... /. {p___, a_: 0, b_, q___} /; cond[b] :> ...

The above replacement first uses the pattern {p___, a_, b_, q___} and finds a match such that b meets a certain condition.
When no such match is find, it omits a_ and instead searches for {p___, b_, q___}. a is not included in the search and is assumed to have the value 0.
Note that the second pattern search would only work for b that occurs at the beginning of the list; if a b value satisfying a condition is in the middle, then {p___, a_, b_, q___} (which has a higher precedence) would match it instead.
The replacement is equivalent to prepending a 0 when a b satisfying a condition occurs at the beginning of the list. (i.e. there is no need to define a separate rule, {b_, q___} /; cond[b] :> ...)

Know when (and when not) to use named pure function arguments
For code golf, pure Function arguments are most commonly referenced using Slots; e.g. # for the first argument, #2 for the second, etc. (see this answer for more details).
In many cases, you will want to nest Functions. For example, 1##&@@#& is a Function which takes a list as its first argument and outputs the product of its elements. Here is that function in TreeForm:

Arguments passed to the top level Function can only fill Slots and SlotSequences present at the top level, which in this case means that the SlotSequence in the inner Function will not have any way of accessing arguments to the top level Function.
In some cases, though, you may want a Function nested within another Function to be able to reference arguments to the outer Function. For example, you may want something like Array[fun,...]&, where the function fun depends on an argument to the top level Function. For concreteness, let's say that fun should give the remainder of the square of its input modulo the input to the top level Function. One way to accomplish this is to assign the top level argument to a variable:
(x=#;Array[Mod[#^2,x]&,...])&

Wherever x appears in the inner Function Mod[#^2,x]&, it will refer to the first argument to the outer Function, whereas # will refer to the first argument to the inner Function. A better approach is to use the fact that Function has a two argument form where the first argument is a symbol or list of symbols that will represent named arguments to the Function (as opposed to unnamed Slots). This ends up saving us three bytes in this case:
xArray[Mod[#^2,x]&,...]

 is the three byte private use character U+F4A1 representing the binary infix operator \[Function]. You may also use the binary form of Function within another Function:
Array[xMod[x^2,#],...]&

This is equivalent to the above. The reason is that, if you are using named arguments, then Slots and SlotSequences are assumed to belong to next Function above which does not use named arguments.
Now just because we can nest Functions in this way, doesn't mean we always should. For example, if we wanted to pick out those elements of a list that are less than the input, we might be tempted to do something like the following:
Select[...,xx<#]&

It would actually be shorter to use Cases and avoid the need for a nested Function entirely:
Cases[...,x_/;x<#]&

You can save a byte by working around Prepend or PrependTo:
l~Prepend~x
{x}~Join~l
{x,##}&@@l

or
l~PrependTo~x
l={x}~Join~l
l={x,##}&@@l

Unfortunately, this doesn't help for the more common Append, which seems to be the shortest equivalent of an Array.push() in other languages.

To achieve an ascending key-value list, use Sort instead of SortBy
For lists such as list = {{1, "world"}, {0, "universe"}, {2, "country"}}, the following three statements are almost equivalent.
SortBy[list,#[[1]]&]
list~SortBy~First
Sort@list

Combine Select and SortBy
Sometimes we need to pick entries out of a larger set and sort them to find a minimum / maximum. Under some circumstances, two operations could be combined into one.
For example, for a minimum, the following two statements are almost equivalent.
SortBy[Select[l,SomeFormula==SomeConstant&],SortValue&]
SortBy[l,SortValue+99!(SomeFormula-SomeConstant)^2&]

and
SortBy[Select[l,SomeFormula!=SomeConstant&],SortValue&]
SortBy[l,SortValue+1/(SomeFormula-SomeConstant)&]

1/0 is ComplexInfinity, which is "larger" than all real numbers.
For a key-value list, for example:
{SortValue,#}&/@SortBy[Select[l,SomeFormula==SomeConstant],SortValue&]
Sort[{SortValue+99!(SomeFormula-SomeConstant)^2,#})&/@l]

Flattening an Array
When using a multidimensional Array to compute a list of results that needs to be flattened, use a function with the attribute Flat as the fourth argument. The final result will be flattened with the specified head.
There are 23 such built-in functions at the time of this writing, 13 of which are also not Orderless. Some of the more generally applicable of those might be:

Or, if there are no booleans,
Dot, if there are no consecutive vectors with matching dimensions,
Join, if not all elements have the same head.

In addition, ##& will also flatten the array's elements; however, Sequences have special behavior when used in most functions, so the Array may often need to be wrapped in { }.
For comparison,
Array[f,dims,origin,Or]
{Array[f,dims,origin,##&]}
Join@@Array[f,dims,origin]  (*2d array only*)
Flatten@Array[f,dims,origin]

(* origin = 1 *)
Array[f,dims,1,Or]
{Array[f,dims,1,##&]}
Join@@Array[f,dims]         (*2d array only*)
Flatten[f~Array~dims]

If the head is not important, and the values are not Booleans, you can even use Or. Array[f,dims,1,Or] is one byte shorter than Join@@Array[f,dims].

Here is an example: https://codegolf.stackexchange.com/a/119173/9288

@alephalpha I completely overlooked Flat. Thanks!

Default values
Default values deal with missing pattern arguments in an efficient way. For example, if we want to pattern match Exp[c_*x] in a rule for any value of c, the naïve
Exp[x] + Exp[2x] /. {Exp[c_*x] -> f[c], Exp[x] -> f[1]}
(*    f[1] + f[2]    *)

uses many more bytes than if we use the default value for c whenever it is missing:
Exp[x] + Exp[2 x] /. Exp[c_.*x] -> f[c]
(*    f[1] + f[2]    *)

The use of a default is indicated with a dot after the pattern: c_..
Default values are associated with operations: in the above example, the operation is Times in c_.*x, and a missing value for c_ is thus taken from the default value associated with Times, which is 1. For Plus, the default value is 0:
Exp[x] + Exp[x + 2] /. Exp[x + c_.] -> f[c]
(*    f[0] + f[2]    *)

For Power exponents, the default is 1:
x + x^2 /. x^n_. -> p[n]
(*    p[1] + p[2]    *)

Solve and Reduce: automatic list of variables
When the list of variables for Solve and Reduce is omitted, they solve for all free variables in the expression(s). Examples:
Solve[x^4==1]
(*    {{x -> -1}, {x -> -I}, {x -> I}, {x -> 1}}    *)
(*    two bytes saved on Solve[x^4==1,x]            *)

Solve[x^2+y^2==25,Integers]
(*    {{x -> -5, y -> 0}, {x -> -4, y -> -3}, {x -> -4, y -> 3}, {x -> -3, y -> -4},
       {x -> -3, y -> 4}, {x -> 0, y -> -5}, {x -> 0, y -> 5}, {x -> 3, y -> -4},
       {x -> 3, y -> 4}, {x -> 4, y -> -3}, {x -> 4, y -> 3}, {x -> 5, y -> 0}}    *)
(*    six bytes saved on Solve[x^2+y^2==25,{x,y},Integers]                         *)

Reduce[x^2+y^2<25,Reals]
(*    -5 < y < 5 && -Sqrt[25 - y^2] < x < Sqrt[25 - y^2]    *)
(*    six bytes saved on Reduce[x^2+y^2<25,{x,y},Reals]     *)

Particularly Solve over the Integers, NonNegativeIntegers, and PositiveIntegers is extremely powerful for enumeration problems.

Use Alphabet[] instead of FromLetterNumber
The function Alphabet was introduced in version 10.1, and it can reduce byte counts when you need to output lower-case/case-insensitive alphabetic strings.
FromLetterNumber@{8,5,12,12,15}<>"" (* 35 bytes *)
Alphabet[][[{8,5,12,12,15}]]<>""    (* 32 bytes *)

Use anonymous RuleDelayed (:>) instead of defining a single-argument function f@n_:=...
Sometimes an answer cannot be given as an anonymous function ...#...& but must be defined as a regular function f@n_:=... because of slot collisions. Such a definition, for example
f@n_:=Select[Range@n,#~CoprimeQ~n&]

can be shortened by two bytes to an anonymous delayed rule
n_:>Select[Range@n,#~CoprimeQ~n&]

that can be applied to a single argument.

Is this valid? I'd consider the expression to be scored here to be #/. pattern &. Also, \[Function] does the same thing while having lower precedence and the same byte count (counting the blank).

@att I don't see why the application of an anonymous function %[7] (which is usually not part of the scoring) should be treated differently from the application of an anonymous delayed rule 7/.%.

@att yes you're right about \[Function] () having the same byte count.

Consider Set instead of ##&[] and ##2&
Set is equivalent to (#=##2)& - that is, Set[a, ...] is interpreted as a=Sequence[...]. This returns a Sequence of all arguments after the first. Try it online!
As a result, Set@a can be used like ##&[], but without the precedence issues.
a/.b_->Set@c
a/.b_->(##&[])
a/.b_->Nothing

Short forms for function-option combinations
In addition to its extensive list of operator short forms, like /@ for Map, Mathematica also has at least a couple of system-defined short forms for function-option combinations

Log[2, n]=> Log2@n
Log[10, n] => Log10@n

I don't know of any others, so feel free to either mention them in the comments, or edit this post to add more.

/@ for Map?

@att Thanks, I corrected the typo.

Use vector inequalities
Vector inequalities VectorLess, VectorLessEqual, VectorGreater, and VectorGreaterEqual were introduced in 12.0.
Importantly for golfing, they all have 3-byte private-use characters assigned, making them more efficient than, say, threading a comparison or using a difference.
Their respective characters are:

\$\prec\$VectorLess
\$\preceq\$VectorLessEqual
\$\succ\$VectorGreater
\$\succeq\$VectorGreaterEqual

Note that these operators look similar to, but are distinct from the previously-existing \[Precedes], \[PrecedesEqual], \[Succeeds], \[SucceedsEqual].

Like scalar inequalities, the vector inequalities can take any number of arguments and can be chained (into a Developer`VectorInequality). They also thread over scalar arguments, including being able to take only scalar inputs. For the most part, they can be thought of as scalar inequalities that thread over lists and return results with And applied.
Some edge cases: they return unevaluated if there are non-list non-numeric elements (including e.g. \$\{0,a\}\succ\{1,0\}\$), and as far as I can tell, they always return False when the inputs are of different (non-scalar) dimensions.
As a small caveat, the calling syntax is different from that of regular inequalities: \$a\prec b\$ is VectorLess[{a, b}], not VectorLess[a, b].

Change the head when pattern matching subsequences
When pattern matching and replacing a short subsequence in a long list, we usually do something like:
{x___,a_,b_,y___}/;someCond:>{x,someExpr,y}

Sometimes we can change the head before pattern matching to something with the attribute Flat, like Or or Dot.
For example, this simple bubble sort (38 bytes)
#//.{x___,a_,b_,y___}/;a>b:>{x,b,a,y}&

can be written as (34 bytes)
List@@(Or@@#//.a_||b_/;a>b:>b||a)&

or (also 34 bytes)
List@@(Dot@@#//.a_ .b_/;a>b:>b.a)&

Don't forget to add a space between _ and . when you are using Dot, otherwise Mathematica would parse it as an Optional pattern.
But this only works when the input and output both have at least 2 elements.

Finding the product of a list post-processing
A typical golfy way to find the product of a list of values is by applying 1##&:
1##&@@expr

Sometimes, we may need to apply a pure function on all of the values first. In such cases, it's often shorter to wrap the result of that preprocessing in a List and use Dot instead:
Product[bodi,{i,expr}]
1##&@@(body&/@expr)
{body}&/@Dot@@expr

If the list has known arguments:
1##&@@(body&/@{a,b,c})
{body}&/@Dot[a,b,c]
{body}&/@(a.b.c)

(g=body&)[a]g[b]g@c
#@a#@b#@c&[body&]

Localizing temporary expressions
Some function submissions may involve defining a local expression which should not persist between different calls.
For example, this answer uses expressions with head g to build paths, (re-)defining g[#] for each value in the input list. These paths should be reset on each new input.
The canonical way to do this is with Module[{g},...]/Block[{g},...], control structures which localize variables so that definitions made inside them will not propagate outside. For golfing, most of the time we can save a few bytes over these by using Clear@g instead, though it may not play nicely with recursion.
In some cases, we can do even better by setting g=h@# (or g=h@##). However, as subsequent definitions will not be cleared on repeated function calls, care needs to be taken to ensure that the function handles such repeated calls on the same input properly (for example, this answer would fail to do so). Where applicable, though, it not only saves bytes, but also has no issues with recursion.
Comparing these strategies for the linked example:
{g}~Module~Depth[i=0;(g@i=g[++i+#]!)&/@#]-3&
{g}~Block~Depth[i=0;(g@i=g[++i+#]!)&/@#]-3&
Depth[i=0Clear@g;(g@i=g[++i+#]!)&/@#]-3&
Depth[g=h@#;i=0;(g@i=g[++i+#]!)&/@#]-3&

When using two or more such local expressions, Block or Clear are the best bet:
Module[{a,b},...]
Block[{a,b},...]
(a~Clear~b;...)
(a=p@#;b=q@#;...)

PreIncrement/PreDecrement can save parentheses
When called on a non-atomic, non-list argument, PreIncrement/PreDecrement return the incremented/decremented value, albeit with an error message. This can save bytes on increments/decrements that would otherwise require parentheses.
For example, to generate the golden ratio:
(√5+1)/2
√5/2+1/2
++√5/2

Try it online!
Prepending + to an atom or list allows ++/-- to be used on them as well, thanks to the HoldFirst attribute. - works as well if the target is not a literal number. In my experience, this is most often useful when used with #. Try it online!
This is also only possible because, for whatever reason, +++x is interpreted as ++ +x instead of + ++x.

Golfing nested pure functions
This is my first post here, would be grateful for comments and corrections!
Let there is some pure function as criterion in Select, MaximalBy etc.:
Select[list, crit[#]&]

And inside this criterion we need some calculations with Map, Table etc which may also be presented as pure function:
crit[arr_, x_] := Table[f[x, e], {e, arr}]

eq to
crit[arr_, x_] := f[x, #]&/@arr

Sometimes the whole construction may be effectively golfed with Fold, Outer etc.
But sometimes not, and we have troubles with correctly using slots in nested pure functions:
Select[ list, (f[#!!wrong!!, #]&/@arr)& ]

Possible golfing solution (without Table or Map) may be like this (thanks to @att):
Select[list, (x=#;f[x,#]&/@arr)&]

or
Select[list, x|->f[x,#]&/@arr]

or sometimes
(f[x,#]&/@arr)/.x->#&

usually better (x=#;f[x,#]&/@arr)& or x|->f[x,#]&/@arr

Check for duplicates
UnsameQ@@ is 6 bytes shorter than DuplicateFreeQ@.
But if performance matters, UnsameQ is over 1000 times slower.