text:
Play an RTTTL song
User quartata posted this challenge, but he neglected the fact that, for whatever reason, he's not able to play MIDI files on his computer.
Let's help him out by writing a full program that reads a song in RTTTL format from the standard input, prints the song name to the standard output and plays it (at the right speed and pitch).
Format details
RTTTL is a fairly dumb and underspecified ringtone format. It consists of a name, some default values, and a series of notes (only one note at a time) in a simple text format.
Example: fifth: d=4,o=5,b=63: 8P, 8G5, 8G5, 8G5, 2D#5
The name is a string terminated by a colon. Here the name is "fifth". Your program must accept names with at least 15 characters.
Next, the defaults section (also terminated by a colon) lists some default values for duration (d), octave (o) and the beats per minute (b) for the song. They are comma-separated and use a "key=value" syntax. There may be any number of spaces around each "key=value" part. You may assume that default values d, o and b are all present, in this order. The duration and octave will be explained below; the bpm refers to the number of beats (corresponding to quarter notes) that should be played in a minute, and you must support any integer value between 20 and 900 (inclusive).
Then the actual song is listed as a comma-separated series of notes using a "DPO" syntax, where D is the duration, P is the pitch (note) and O is the octave. There may be any number of spaces and newlines around each "DPO" part.
The duration is a power of 2 between 1 and 32 (inclusive), representing a fraction of a whole note. So for example a value of 4 (quarter note) is twice as long as a value of 8 (eighth note). The duration can be missing, in which case the default duration will be used. The duration may also be modified by the presence of a dot (.), specifically the dot makes the note last 50% longer. Since not everybody agrees about where the dot is supposed to be, you must accept a dot after the pitch or after the octave (i.e. both "DP.O" and "DPO." should work).
The pitch is one of A,B,C,D,E,F,G,A#,C#,D#,F#,G#,P where A-G# are the standard musical notes (note: no flats, use the corresponding sharp note) and P is a pause. The pitch is the only part of the note that is required, and is case-insensitive.
And finally, the octave is a number normally from 4 to 8, but you must support any number from 1 to 8 inclusive. For example, C4 is the standard middle C with a frequency of about 261.63Hz. The octave can be missing, in which case the default octave will be used. You can assume that pauses don't have an octave specified (as it has no meaning).
As mentioned in the other challenge, you can use this site to convert RTTTL songs to MIDI format for testing (but note that it may not follow the exact same specification).
Requirements:
Your program must play each note at the right speed and pitch. It can use any kind of sound (sine/triangle/square wave, piano sound, bell sound, whatever; also it can be a standard beep, wave sound or MIDI sound etc) as long as it is audible and the pitch is recognizable.
Each note must be played continuously for the specified duration or no more than a 64th note shorter than that, except if you're using something like an ADSR envelope, in which case the release phase may continue through the next pause or over the next note.
If two consecutive notes have the same pitch, they must be clearly distinguished, either through a short break (using no more than the length of a 64th note, as part of the first note's duration) or by using a non-uniform sound (such as the ADSR envelope mentioned above), or at least through a phase change if it's clear enough. Two consecutive pauses should be treated the same as a single pause with the total duration.
The program must be runnable in Linux using freely available software. It should read the song from the standard input, and print the song name to the standard output.
If the input does not match the specification above, the behavior is unspecified. Your program may ignore errors, or print a message, or play something wrong, hang or crash, it should just not do any damage.
Standard loopholes are not allowed.
Scoring
Code golf, shortest program (measured in UTF-8 bytes) wins.

Do we have a restricted OS (i.e. no Linux-specific languages if running Windows)?

I believe aditsu is trying to be nice to me (:3) and make it only languages that run under Linux. I do have a really crummy old Mac laptop so feel free to make an AppleScript one

You knew exactly what I was going for. ;)

@VTCAKAVSMoACE Linux-specific languages are fine, because the requirement is for the program to run in Linux (both for my and quartata's sake)

I don't have linux and so even if I knew how to write something on linux I couldn't test it.  If I write an exeecutable that uses Windows API can it be run in Wine or is that not allowed?  I think limiting it to linux is really limiting - kind of like those questions that limit answers to a particular programming language...

@JerryJeremiah I think using wine is acceptable, I'll just need a way to compile the code. Basically, you could also post something that can't run in Linux, it just won't be eligible for my upvote or for winning the challenge.

Working on a Perl solution just so that I can imitate the greats (Dennis, Martin) and answer a challenge about me

is it okay to read from a file instead of stdin?

@LiamNoronha only if you can't read from stdin

how should three adjacent 64th-notes be separated? two 64th-gaps would erase the middle note.

@Sparr there can't be any 64th notes in the song according to the spec. Also, the gap should erase part of the current note.

Roger that on 32nd notes being the shortest. Not sure what you mean by "the current note", though. Is that the note before or after the gap? Or should it span the boundary? The spec is unclear.

@Sparr If you have 2 notes with the same pitch, and the duration of the first note is x and the duration a 64th note is y, and you want to use a gap, then you can choose a gap duration z <= y, and you should play the first note for the duration x-z, followed by a z gap. You can do the same thing for all notes, even if they are different.

@aditsu I understand what you're saying in the comments. My point is that the spec doesn't define that detail. if my two notes of the same pitch are of duration W and X, the spec doesn't say whether Z is to be subtracted from W or X or split between them. It just says "the note duration" without specifying WHICH note(s).

@Sparr updated, how's that?

update looks good.

Java, 813
import javax.sound.sampled.*;class R{public static void main(String[]a)throws Exception{Integer k=0;a=new
java.util.Scanner(System.in).useDelimiter("\\A").next().split(":");System.out.println(a[0]);int[]X=new
int[3],N={9,11,0,2,4,5,7};while(k<3)X[k]=k.valueOf(a[1].split(",")[k++].split("=")[1].trim());SourceDataLine
l=AudioSystem.getSourceDataLine(new AudioFormat(48000,8,1,1>0,1<0));l.open();l.start();for(String
t:a[2].toLowerCase().split(",")){a[k=0]=a[1]=a[2]="";for(char
c:t.trim().toCharArray())if(c!=46)a[k+=(c<48|c>57?1:0)^k]+=c;int
D=32/(a[k=0]==""?X[0]:k.valueOf(a[0]))*(t.contains(".")?3:2),m=a[1].charAt(0)-97,P=m>6?0:N[m]+12*(a[2]==""?X[1]:k.valueOf(a[2]))+(t.contains("#")?1:0);int
n=180000*D/X[2];for(;k<n;++k)l.write(new byte[]{(byte)(P>0&k<n-n/D?k*Math.pow(2,P/12.)/22.93:0)},0,1);}l.drain();}}

I'm still working on it.
It's a bit sensitive to CPU speed and busyness when starting.

C++, 15186 bytes
There's a link at the bottom where you can hear a sample
I present one of the least practical ways to play music on your Linux machine:
#include <SFML/Audio.hpp>
#include <cmath>
#include <iostream>
#include <fstream>
#include <string>
namespace N{double a = 440.;double as = 466.16;double b = 493.88;double c = 523.25;double cs = 554.37;double d = 587.33;double ds = 622.25;double e = 659.25;double f =  698.46;double fs = 739.99 ;double g =  783.99;double gs =  830.61;    const unsigned SAMPLES = 10*44100;const unsigned SAMPLE_RATE = 44100;const unsigned AMPLITUDE = 10000;const double TWO_PI = 6.28318;    sf::Int16 a4raw[SAMPLES];sf::Int16 as4raw[SAMPLES];sf::Int16 b4raw[SAMPLES];sf::Int16 c4raw[SAMPLES];sf::Int16 cs4raw[SAMPLES];sf::Int16 d4raw[SAMPLES];sf::Int16 ds4raw[SAMPLES];sf::Int16 e4raw[SAMPLES];sf::Int16 f4raw[SAMPLES];sf::Int16 fs4raw[SAMPLES];sf::Int16 g4raw[SAMPLES];sf::Int16 gs4raw[SAMPLES];sf::Int16 pauseraw[SAMPLES];double inc = a/44100;double x=0;int i=0;void set1(){for(int i=0;i<SAMPLES;i++){a4raw[i]=AMPLITUDE*sin(x*TWO_PI);x+=inc;}inc=as/44100;x=0;for(unsigned i=0;i<SAMPLES;i++){as4raw[i]=AMPLITUDE*sin(x*TWO_PI);x += inc;}inc=b/44100;x=0;for(unsigned i=0;i<SAMPLES;i++){b4raw[i]=AMPLITUDE*sin(x*TWO_PI);x+=inc;}inc=c/44100;x=0;for(unsigned i=0;i<SAMPLES;i++){c4raw[i]=AMPLITUDE * sin(x*TWO_PI);x+=inc;}inc=cs/44100;x=0;for(unsigned i=0;i<SAMPLES;i++){cs4raw[i]=AMPLITUDE*sin(x*TWO_PI);x+=inc;}inc=d/44100;x=0;for(unsigned i=0;i<SAMPLES;i++){d4raw[i]=AMPLITUDE*sin(x*TWO_PI);x+=inc;}inc=ds/44100;x=0;for(unsigned i=0;i<SAMPLES;i++){ds4raw[i]=AMPLITUDE*sin(x*TWO_PI);x+=inc;}inc=e/44100;x=0;for(unsigned i=0;i<SAMPLES;i++){e4raw[i]=AMPLITUDE*sin(x*TWO_PI);x+=inc;}inc=f/44100;x=0;for(unsigned i=0;i<SAMPLES;i++){f4raw[i]=AMPLITUDE*sin(x*TWO_PI);x+=inc;}inc=fs/44100;x=0;for(unsigned i=0;i<SAMPLES;i++){fs4raw[i]=AMPLITUDE*sin(x*TWO_PI);x+=inc;}inc=g/44100;x=0;for(unsigned i=0;i<SAMPLES;i++){g4raw[i]=AMPLITUDE*sin(x*TWO_PI);x+=inc;} inc=gs/44100;x=0;for(unsigned i=0;i<SAMPLES;i++){gs4raw[i]=AMPLITUDE*sin(x*TWO_PI);x+=inc;}}sf::SoundBuffer a3; sf::SoundBuffer a4; sf::SoundBuffer a5; sf::SoundBuffer a6; sf::SoundBuffer a7;sf::SoundBuffer as3; sf::SoundBuffer as4; sf::SoundBuffer as5; sf::SoundBuffer as6; sf::SoundBuffer as7;sf::SoundBuffer b3; sf::SoundBuffer b4; sf::SoundBuffer b5; sf::SoundBuffer b6; sf::SoundBuffer b7;sf::SoundBuffer c3; sf::SoundBuffer c4; sf::SoundBuffer c5; sf::SoundBuffer c6; sf::SoundBuffer c7;sf::SoundBuffer cs3; sf::SoundBuffer cs4; sf::SoundBuffer cs5; sf::SoundBuffer cs6; sf::SoundBuffer cs7;sf::SoundBuffer d3; sf::SoundBuffer d4; sf::SoundBuffer d5; sf::SoundBuffer d6; sf::SoundBuffer d7;sf::SoundBuffer ds3; sf::SoundBuffer ds4; sf::SoundBuffer ds5; sf::SoundBuffer ds6; sf::SoundBuffer ds7;sf::SoundBuffer e3; sf::SoundBuffer e4; sf::SoundBuffer e5; sf::SoundBuffer e6; sf::SoundBuffer e7;sf::SoundBuffer f3; sf::SoundBuffer f4; sf::SoundBuffer f5; sf::SoundBuffer f6; sf::SoundBuffer f7;sf::SoundBuffer fs3; sf::SoundBuffer fs4; sf::SoundBuffer fs5; sf::SoundBuffer fs6; sf::SoundBuffer fs7;sf::SoundBuffer g3; sf::SoundBuffer g4; sf::SoundBuffer g5; sf::SoundBuffer g6; sf::SoundBuffer g7;sf::SoundBuffer gs3; sf::SoundBuffer gs4; sf::SoundBuffer gs5; sf::SoundBuffer gs6; sf::SoundBuffer gs7;sf::SoundBuffer pauseBuffer;void set2(){if (!a3.loadFromSamples(a4raw,SAMPLES,1,SAMPLE_RATE/2)){std::cerr<<"err: load fail";}if(!a4.loadFromSamples(a4raw,SAMPLES,1,SAMPLE_RATE)){std::cerr<<"err: load fail";}if(!a5.loadFromSamples(a4raw, SAMPLES, 1, SAMPLE_RATE*2)){std::cerr<<"err: load fail";}if(!a6.loadFromSamples(a4raw,SAMPLES,1,SAMPLE_RATE*4)){std::cerr<<"err: load fail";}if(!a7.loadFromSamples(a4raw,SAMPLES,1, SAMPLE_RATE*8)){std::cerr<<"err: load fail";}  if (!as3.loadFromSamples(as4raw, SAMPLES, 1, SAMPLE_RATE/2)){std::cerr<<"err: load fail";}if (!as4.loadFromSamples(as4raw, SAMPLES, 1, SAMPLE_RATE)){std::cerr<<"err: load fail";}if (!as5.loadFromSamples(as4raw, SAMPLES, 1, SAMPLE_RATE*2)){std::cerr<<"err: load fail";}if (!as6.loadFromSamples(as4raw, SAMPLES, 1, SAMPLE_RATE*4)){std::cerr<<"err: load fail";}if (!as7.loadFromSamples(as4raw, SAMPLES, 1, SAMPLE_RATE*8)){std::cerr<<"err: load fail";}if (!b3.loadFromSamples(b4raw, SAMPLES, 1, SAMPLE_RATE/2)){std::cerr<<"err: load fail";}if (!b4.loadFromSamples(b4raw, SAMPLES, 1, SAMPLE_RATE)){std::cerr<<"err: load fail";}if (!b5.loadFromSamples(b4raw, SAMPLES, 1, SAMPLE_RATE*2)){std::cerr<<"err: load fail";}if (!b6.loadFromSamples(b4raw, SAMPLES, 1, SAMPLE_RATE*4)){std::cerr<<"err: load fail";}if (!b7.loadFromSamples(b4raw, SAMPLES, 1, SAMPLE_RATE*8)){std::cerr<<"err: load fail";}if (!c3.loadFromSamples(c4raw, SAMPLES, 1, SAMPLE_RATE/2)){std::cerr<<"err: load fail";}if (!c4.loadFromSamples(c4raw, SAMPLES, 1, SAMPLE_RATE)){std::cerr<<"err: load fail";}if (!c5.loadFromSamples(c4raw, SAMPLES, 1, SAMPLE_RATE*2)){std::cerr<<"err: load fail";}if (!c6.loadFromSamples(c4raw, SAMPLES, 1, SAMPLE_RATE*4)){std::cerr<<"err: load fail";}if (!c7.loadFromSamples(c4raw, SAMPLES, 1, SAMPLE_RATE*8)){std::cerr<<"err: load fail";}if (!cs3.loadFromSamples(cs4raw, SAMPLES, 1, SAMPLE_RATE/2)){std::cerr<<"err: load fail";}if (!cs4.loadFromSamples(cs4raw, SAMPLES, 1, SAMPLE_RATE)){std::cerr<<"err: load fail";}if (!cs5.loadFromSamples(cs4raw, SAMPLES, 1, SAMPLE_RATE*2)){std::cerr<<"err: load fail";}if (!cs6.loadFromSamples(cs4raw, SAMPLES, 1, SAMPLE_RATE*4)){std::cerr<<"err: load fail";}if (!cs7.loadFromSamples(cs4raw, SAMPLES, 1, SAMPLE_RATE*8)){std::cerr<<"err: load fail";}if (!d3.loadFromSamples(d4raw, SAMPLES, 1, SAMPLE_RATE/2)){std::cerr<<"err: load fail";}if (!d4.loadFromSamples(d4raw, SAMPLES, 1, SAMPLE_RATE)){std::cerr<<"err: load fail";}if (!d5.loadFromSamples(d4raw, SAMPLES, 1, SAMPLE_RATE*2)){std::cerr<<"err: load fail";}if (!d6.loadFromSamples(d4raw, SAMPLES, 1, SAMPLE_RATE*4)){std::cerr<<"err: load fail";}if (!d7.loadFromSamples(d4raw, SAMPLES, 1, SAMPLE_RATE*8)){std::cerr<<"err: load fail";}if (!ds3.loadFromSamples(ds4raw, SAMPLES, 1, SAMPLE_RATE/2)){std::cerr<<"err: load fail";}if (!ds4.loadFromSamples(ds4raw, SAMPLES, 1, SAMPLE_RATE)){std::cerr<<"err: load fail";}if (!ds5.loadFromSamples(ds4raw, SAMPLES, 1, SAMPLE_RATE*2)){std::cerr<<"err: load fail";}if (!ds6.loadFromSamples(ds4raw, SAMPLES, 1, SAMPLE_RATE*4)){std::cerr<<"err: load fail";}if (!ds7.loadFromSamples(ds4raw, SAMPLES, 1, SAMPLE_RATE*8)){std::cerr<<"err: load fail";}    if (!e3.loadFromSamples(e4raw, SAMPLES, 1, SAMPLE_RATE/2)){std::cerr<<"err: load fail";}if (!e4.loadFromSamples(e4raw, SAMPLES, 1, SAMPLE_RATE)){std::cerr<<"err: load fail";}if (!e5.loadFromSamples(e4raw, SAMPLES, 1, SAMPLE_RATE*2)){std::cerr<<"err: load fail";}if (!e6.loadFromSamples(e4raw, SAMPLES, 1, SAMPLE_RATE*4)){std::cerr<<"err: load fail";}if (!e7.loadFromSamples(e4raw, SAMPLES, 1, SAMPLE_RATE*8)){std::cerr<<"err: load fail";}if (!f3.loadFromSamples(f4raw, SAMPLES, 1, SAMPLE_RATE/2)){std::cerr<<"err: load fail";}if (!f4.loadFromSamples(f4raw, SAMPLES, 1, SAMPLE_RATE)){std::cerr<<"err: load fail";}if (!f5.loadFromSamples(f4raw, SAMPLES, 1, SAMPLE_RATE*2)){std::cerr<<"err: load fail";}if (!f6.loadFromSamples(f4raw, SAMPLES, 1, SAMPLE_RATE*4)){std::cerr<<"err: load fail";}if (!f7.loadFromSamples(f4raw, SAMPLES, 1, SAMPLE_RATE*8)){std::cerr<<"err: load fail";}if (!fs3.loadFromSamples(fs4raw, SAMPLES, 1, SAMPLE_RATE/2)){std::cerr<<"err: load fail";}if (!fs4.loadFromSamples(fs4raw, SAMPLES, 1, SAMPLE_RATE)){std::cerr<<"err: load fail";}if (!fs5.loadFromSamples(fs4raw, SAMPLES, 1, SAMPLE_RATE*2)){std::cerr<<"err: load fail";}if (!fs6.loadFromSamples(fs4raw, SAMPLES, 1, SAMPLE_RATE*4)){std::cerr<<"err: load fail";}if (!fs7.loadFromSamples(fs4raw, SAMPLES, 1, SAMPLE_RATE*8)){std::cerr<<"err: load fail";}if (!g3.loadFromSamples(g4raw, SAMPLES, 1, SAMPLE_RATE/2)){std::cerr<<"err: load fail";}if (!g4.loadFromSamples(g4raw, SAMPLES, 1, SAMPLE_RATE)){std::cerr<<"err: load fail";}if (!g5.loadFromSamples(g4raw, SAMPLES, 1, SAMPLE_RATE*2)){std::cerr<<"err: load fail";}if (!g6.loadFromSamples(g4raw, SAMPLES, 1, SAMPLE_RATE*4)){std::cerr<<"err: load fail";}if (!g7.loadFromSamples(g4raw, SAMPLES, 1, SAMPLE_RATE*8)){std::cerr<<"err: load fail";}if (!gs3.loadFromSamples(gs4raw, SAMPLES, 1, SAMPLE_RATE/2)){std::cerr<<"err: load fail";}if (!gs4.loadFromSamples(gs4raw, SAMPLES, 1, SAMPLE_RATE)){std::cerr<<"err: load fail";}if (!gs5.loadFromSamples(gs4raw, SAMPLES, 1, SAMPLE_RATE*2)){std::cerr<<"err: load fail";}if (!gs6.loadFromSamples(gs4raw, SAMPLES, 1, SAMPLE_RATE*4)){std::cerr<<"err: load fail";}if (!gs7.loadFromSamples(gs4raw, SAMPLES, 1, SAMPLE_RATE*8)){std::cerr<<"err: load fail";}if(!pauseBuffer.loadFromSamples(pauseraw, SAMPLES, 1, SAMPLE_RATE)){std::cerr<<"err: load fail";}}sf::Sound A3; sf::Sound A4;sf::Sound A5;sf::Sound A6;sf::Sound A7;sf::Sound AS3; sf::Sound AS4;sf::Sound AS5;sf::Sound AS6;sf::Sound AS7;sf::Sound B3; sf::Sound B4;sf::Sound B5;sf::Sound B6;sf::Sound B7;sf::Sound C3; sf::Sound C4;sf::Sound C5;sf::Sound C6;sf::Sound C7;sf::Sound CS3; sf::Sound CS4;sf::Sound CS5;sf::Sound CS6;sf::Sound CS7;sf::Sound D3; sf::Sound D4;sf::Sound D5;sf::Sound D6;sf::Sound D7;sf::Sound DS3; sf::Sound DS4;sf::Sound DS5;sf::Sound DS6;sf::Sound DS7;sf::Sound E3; sf::Sound E4;sf::Sound E5;sf::Sound E6;sf::Sound E7;sf::Sound F3; sf::Sound F4;sf::Sound F5;sf::Sound F6;sf::Sound F7;sf::Sound FS3; sf::Sound FS4;sf::Sound FS5;sf::Sound FS6;sf::Sound FS7;sf::Sound G3; sf::Sound G4;sf::Sound G5;sf::Sound G6;sf::Sound G7;sf::Sound GS3; sf::Sound GS4;sf::Sound GS5;sf::Sound GS6;sf::Sound GS7;sf::Sound pause;void set3(){A3.setBuffer(a3);A3.setLoop(true);A4.setBuffer(a4);A4.setLoop(true);A5.setBuffer(a5);A5.setLoop(true);A6.setBuffer(a6);A6.setLoop(true);A7.setBuffer(a7);A7.setLoop(true);AS3.setBuffer(as3);AS3.setLoop(true);AS4.setBuffer(as4);AS4.setLoop(true);AS5.setBuffer(as5);AS5.setLoop(true);AS6.setBuffer(as6);AS6.setLoop(true);AS7.setBuffer(as7);AS7.setLoop(true);B3.setBuffer(b3);B3.setLoop(true);B4.setBuffer(b4);B4.setLoop(true);B5.setBuffer(b5);B5.setLoop(true);B6.setBuffer(b6);B6.setLoop(true);B7.setBuffer(b7);B7.setLoop(true);C3.setBuffer(c3);C3.setLoop(true);C4.setBuffer(c4);C4.setLoop(true);C5.setBuffer(c5);C5.setLoop(true);C6.setBuffer(c6);C6.setLoop(true);C7.setBuffer(c7);C7.setLoop(true);D3.setBuffer(d3);D3.setLoop(true);D4.setBuffer(d4);D4.setLoop(true);D5.setBuffer(d5);D5.setLoop(true);D6.setBuffer(d6);D6.setLoop(true);D7.setBuffer(d7);D7.setLoop(true);DS3.setBuffer(ds3);DS3.setLoop(true);DS4.setBuffer(ds4);DS4.setLoop(true);DS5.setBuffer(ds5);DS5.setLoop(true);DS6.setBuffer(ds6);DS6.setLoop(true);DS7.setBuffer(ds7);DS7.setLoop(true);E3.setBuffer(e3);E3.setLoop(true);E4.setBuffer(e4);E4.setLoop(true);E5.setBuffer(e5);E5.setLoop(true);E6.setBuffer(e6);E6.setLoop(true);E7.setBuffer(e7);E7.setLoop(true);F3.setBuffer(f3);F3.setLoop(true);F4.setBuffer(f4);F4.setLoop(true);F5.setBuffer(f5);F5.setLoop(true);F6.setBuffer(f6);F6.setLoop(true);F7.setBuffer(f7);F7.setLoop(true);FS3.setBuffer(fs3);FS3.setLoop(true);FS4.setBuffer(fs4);FS4.setLoop(true);FS5.setBuffer(fs5);FS5.setLoop(true);FS6.setBuffer(fs6);FS6.setLoop(true);FS7.setBuffer(fs7);FS7.setLoop(true);G3.setBuffer(g3);G3.setLoop(true);G4.setBuffer(g4);G4.setLoop(true);G5.setBuffer(g5);G5.setLoop(true);G6.setBuffer(g6);G6.setLoop(true);G7.setBuffer(g7);G7.setLoop(true);GS3.setBuffer(gs3);GS3.setLoop(true);GS4.setBuffer(gs4);GS4.setLoop(true);GS5.setBuffer(gs5);GS5.setLoop(true);GS6.setBuffer(gs6);GS6.setLoop(true);GS7.setBuffer(gs7);GS7.setLoop(true);pause.setBuffer(pauseBuffer);pause.setLoop(true);}sf::Sound* naturalNotePtrs[7][5] = {{&A3,&A4,&A5,&A6,&A7}, {&B3,&B4,&B5,&B6,&B7}, {&C3,&C4,&C5,&C6,&C7}, {&D3,&D4,&D5,&D6,&D7}, {&E3,&E4,&E5,&E6,&E7}, {&F3,&F4,&F5,&F6,&F7}, {&G3,&G4,&G5,&G6,&G7}};sf::Sound* sharpNotePtrs[5][5]={   {&AS3,&AS4,&AS5,&AS6,&AS7}, {&CS3,&CS4,&CS5,&CS6,&CS7},  {&DS3,&DS4,&DS5,&DS6,&DS7},{&FS3,&FS4,&FS5,&FS6,&FS7},{&GS3,&GS4,&GS5,&GS6,&GS7}};sf::Sound getNote(char value, int octave, bool sharp){if (value =='p' || value=='P'){return A4;}if(sharp){switch(value){case 'a':return (*sharpNotePtrs[0][octave-3]);break;case 'c':return (*sharpNotePtrs[1][octave-3]);break;case 'd':return *sharpNotePtrs[2][octave-3];break;case 'f':return *sharpNotePtrs[3][octave-3];break;case 'g':return *sharpNotePtrs[4][octave-3];break;default:std::cerr<<"Invalid sharp\n";}}else {return *naturalNotePtrs[value-97][octave-3];}}void playNote(float duration,int bpm, char value, int octave, bool sharp) {sf::Clock clock;sf::Time time;sf::Sound sound;sound = getNote(value, octave,sharp);double beats=4/duration;double bps = bpm/60.;double trueTimeSecs = beats/bps;int sleepTime =trueTimeSecs*1000+1;while(1) {if(value!='p' && value!= 'P') {sound.play();}sf::sleep(sf::milliseconds(sleepTime));time = clock.getElapsedTime();if(time.asSeconds()>trueTimeSecs){sound.stop();clock.restart();break;}}}}char upperToLower(char input) {if(input>='A'&&input<='Z') {return input+32;}else {return input;}}int main(){using namespace std;using namespace N;using namespace sf;set1();set2();set3();bool delFile=false;ifstream test("x.rtttl"); if(test.good()) {cout<<"no input necessary, 'x.rtttl' already exists and will be read, as is.\n";}else {ofstream outf("x.rtttl");string in;cout<<"Please enter your rtttl file manually, in one line:\n";getline(cin,in);outf<<in<<endl;outf.close();delFile=true;}ifstream song("x.rtttl");song.seekg(0,ios::beg);float duration=0.;int octave=4;int bpm=0;float noteDuration =0.;int noteOctave =0;char noteValue='a';bool sharp = false;bool readIntro = false;bool readData = false;char c;std::cout<< "Now Playing: ";while(song){song>>c;if(c==':'&& !readIntro){readIntro=true;}else if (c==':') { readIntro=false; readData=true;}if(!readIntro && !readData){std::cout<<c;}c=upperToLower(c);if(readIntro) {if(c=='d') {song>>c;c=upperToLower(c);song>>c;c=upperToLower(c);duration = c-48;}if(c=='o'){song>>c;c=upperToLower(c);song>>c;c=upperToLower(c);octave = c-48;}if(c=='b') {song>>c;c=upperToLower(c);song>>c;c=upperToLower(c);int steps=0;while(c!=':'&&steps<5) {song>>c;steps++;}song.seekg(-steps-1, ios::cur);song>>c;c=upperToLower(c);if(steps==3) {bpm+=100*(c-48);song>>c;bpm+=10*(c-48);song>>c;bpm+=c-48;}if(steps==2){bpm+=10*(c-48);song>>c;bpm+=(c-48);}}}else if (readData){if(c<='9' && c>='0') {switch(c){case '1': song>>c;if(c=='6'){ noteDuration=16.;}else {noteDuration = 1.;}break;case '2': noteDuration = 2.;break;case '4':noteDuration = 4.;break;case'8':noteDuration =8.; break;case '3':noteDuration = 32.; song>>c; break;default:cerr<<"\nBad Duration:"<<c;return 1;}song>>c;c=upperToLower(c);noteValue = c;song>>c;c=upperToLower(c);if(c=='#'){sharp = true;song>>c;c=upperToLower(c);}else {sharp =false;}if(c<='9' && c>= '0' ) { noteOctave = c-48;song>>c;c=upperToLower(c); }else {noteOctave = octave;}if(c=='.'){noteDuration*=1.5; song>>c;c=upperToLower(c);}playNote(noteDuration,bpm, noteValue, noteOctave,sharp);}else if(c<='z' && c>='a') {noteDuration = duration;noteValue = c;song>>c;c=upperToLower(c);if(c=='#') { sharp = true;song>>c;c=upperToLower(c);}else {sharp =false;}if(c<='9' && c>= '0' ) { noteOctave = c-48;song>>c;c=upperToLower(c); }else {noteOctave = octave;}if(c=='.') { noteDuration*=1.5; song>>c;c=upperToLower(c);}playNote(noteDuration,bpm, noteValue, noteOctave,sharp);}}}if(delFile) {song.close();remove("x.rtttl");}return 0;}

I unfortunately I cannot include both the golfed and ungolfed code (space constraints), and the code could be golfed further.
A large part of the reason that the file is so long is that it has to create every pitch (12 notes * 5 octaves) individually using sine waves.
Compiling I compiled using the dev cmd prompt for visual studio, but it is very similar with g++ on Linux.
cl music.cpp /I SFML\SFML-2.3.1\include /link SFML\SFML-2.3.1\lib\sfml-system.lib SFML\SFML-2.3.1\lib\sfml-audio.lib

You just need to link things properly.
credit to SFML and this post for the idea.
I think the timings are correct, let me know if they are not.
Give it a listen
Here (Link to DropBox) is a screen recording of it playing a quick rendition of the Morrowind Theme that I whipped up. Note that in the video it doesn't ask for input because the file already exists.
MorrowindTheme: d=4,o=4,b=100: 8a, 8b, 2c, 8c, 8d, 2e, 8e, 8g, 2d, 16e, 16d, 8c, 8b, a, p,  8a, 8b, 2c, 8c, 8d, 2e, 8e, 8g, 2a5, g, 8b5, a5, 8a5, 8b5, c5, b5, a5, g, f, e, 2d, c, 8e, 2d, 8c, 8b, 1a

http://meta.codegolf.stackexchange.com/questions/7159/way-too-long-allowed-or-disallowed?cb=1

added accurate byte count

Still, you are supposed to make some effort to golf your code. And have you heard of input redirection?

First, I have heard of input redirection, but have never used it, so I opted to do something I was more familiar with. Is there a resource that indicates that code should be golfed? All I could find is this(http://meta.codegolf.stackexchange.com/questions/714/should-we-establish-rules-etiquette-for-posting-non-winning-answers/716#716 ). To be perfectly honest, I don't want to spend hours golfing this. If it isn't acceptable, I will remove it.

Actually I found this (http://meta.codegolf.stackexchange.com/questions/25/code-golf-answers-that-arent-golfing-attempts)

Just saw your comments now. There is some relevant wording in the help center, but indeed it's not very easy to find. There's a general expectation here that code golf answers should be golfed. But I don't think you need to delete it (if you don't want to golf it).

Thank you for pointing that out to me. I wasn't aware of that

Btw, you could draw my attention by writing "@aditsu"; normally only you get comment notifications on your own answer.

You don't need spaces between #include and the library. You can also use #import instead.

Oh no, not Morrowind... Now it won't stop playing in my head... once again... xD


text:
The Light Up Game
The Challenge
The game Light Up! is a simple puzzle game where the objective is to light up every cell in an n-by-n array with light bulbs. However, there are blocks in the way that will prevent light from traveling, and no lightbulb can be places such that another lightbulb shines light on it. Each light bulb has light coming from it in only the horizontal and vertical directions.
You must make a program that takes in an array of 5 numbers. Your program must convert each numbers into a 5-bit binary number, which will define at what places in the array there are blocks. If there is a 1, there is a block at the spot, but if there is a 0, there is not a block. Each number converted to binary defines a row, like:
[5,6,5,6,5] -> [00101, 00110, 00101, 00110, 00101] ->
. . B . B
. . B B .
. . B . B
. . B B .
. . B . B

Where B = blocks that block light
Your program must take this array and find the solutions (places where you need to put light) and give it back as an array of 5 numbers.
Example:
Input: [1,5,9,13,17]
Which translates to [00001, 00101, 01001, 01101, 10001]
Making the array:
. . . . B
. . B . B
. B . . B
. B B . B
B . . . B

A solution for this array is
L ~ ~ ~ B
~ L B ~ B
~ B ~ L B
~ B B ~ B
B L ~ ~ B

~ = Light
L = Lightbulb
Which gives the binary array of lights [10000, 01000, 00010, 00000, 01000]
And translates back to [16, 8, 2, 0, 8]
Output: [16, 8, 2, 0, 8]
Rules

Two lightbulbs can not be in the same row or column if there is no block between them.
A lightbulb's light can only travel horizontally and vertically, and will stop if there is a block in the way
Your program must take in an array [a,b,c,d,e] and output in the same form
If there are no way the array can be solved, your program must not give output or state "No Output."
This is a [code-golf] challenge, lowest amount in bytes wins!

I think the example solution is wrong, you have two L in the column two.

@RomanMik Thank you for telling me that! I should have specified it's ok if they're in the same column as long as a block is between them.

ok, should the solution with the fewest light bulbs used be the best solution too ?

I presume that a light can't be placed on top of a block?

@RomanMik no, it does not have to be, as long as each solution follows the rules.

@PeterTaylor no, a light can't be placed on a block.

CJam, 79 73 68 bytes
32q~:Q,m*{Q.&:|!},{Q]{2b5Ue[}f%~..-_z]{Wa/_1fb.f|1a*}f%~z..|:|1a=}=p

This will work only using the Java interpreter. It should terminate eventually with default switches, but it becomes reasonably fast by increasing the maximum heap size.
At the cost of 7 more bytes (for a total of 75 bytes), we can speed up the code significantly.
q~32b:Q;Y25#{Q&!},{Q]{2b25Ue[}/.m5/_z]{Wa/_1fb.f|1a*}f%~z..|:|1a=}=32bU5e[p

It still requires a little patience, but you can this version online in the CJam interpreter.
Test run
$ alias='java -jar -Xmx4G /usr/local/share/cjam/cjam-0.6.5.jar'
$ time cjam lights-short.cjam <<< '[1 5 9 13 17]'
[2 8 4 16 4]

real    0m44.287s
user    3m47.426s
sys     0m1.821s
$ time cjam lights-fast.cjam <<< '[1 5 9 13 17]'
[2 8 4 16 4]

real    0m1.926s
user    0m2.383s
sys     0m0.098s

This gives us the following solution for the test case:
. . . L B
. L B . B
. B L . B
L B B . B
B . L . B

Idea
For a given vector of wall placements, we iterate over all 33,554,432 vectors of light bulb placements, searching for one that satisfies the criteria.
If the bitwise AND of any pair of corresponding integers is non-zero, the spot is occupied by both a wall and a light bulb. We immediately discard such vectors.
We now convert the integers of wall and bulb placements to binary and subtract the resulting two-dimensional arrays. The result is a single 5 × 5 array, where 0 indices an empty space, 1 indicates a light bulb and -1 indicates a wall.
We take this array and its transpose, and do the following for each row of each of them:

For all runs of non-walls, we replace each 0 or 1 with the number of 1s in this run.
Then, we replace the -1s with 1s.

We transpose the second array again (effectively applying the above to its columns) and take the element-wise bitwise OR of both arrays.
If there is any 0 left, the corresponding spot is not reached by light. Likewise, if there is any number greater than 1, the are two non-separated light bulbs in the same row or column. Thus, a valid solution with produce an array that consists entirely of 1s.
Code
32q~:Q   e# Push 32, evaluate the input, and store the result in Q.
,m*      e# Get the length of Q (5) and push the vectors of {0, ..., 31}^5.
{        e# Filter; for each vector V:
  Q.&    e#   Take the bitwise and of the elements of V and Q.
  :|!    e#   Bitwise OR the results, and apply logical NOT.
},       e# Keep V if the result was 1.
{        e# Find; for each vector V:
  Q]     e#   Push Q and wrap V and Q in a array.
  {      e#   Map the following block over each of them:
    2b   e#     Convert the component to base 2.
    5Ue[ e#     Left-pad with 0s to a length of 5.
  }f%    e#
  ~      e#   Dump the modified V and Q on the stack.
  ..-    e#   Apply doubly vectorized subtraction.
  _z]    e#   Push a transposed copy of the result. Wrap both in an array.
  {      e#   Map the following block over each of them:
    Wa/  e#     Split at -1.
    _1fb e#     Add the integers of each chunk to count the number of 1s.
    .f|  e#     Vectorized mapped bitwise OR to replace each integer with the
         e#     number of 1s (possibly incremented).
    1a*  e#     Rejoin the chunks, separating by 1s.
  }f%    e#
  ~      e#   Dump both results on the stack.
  z      e#   Transpose the second one.
  ..|    e#   Doubly vectorized bitwise OR.
  :|     e#   Reduce the array by set union.
  1a=    e#   Check if the result is [1].
}=       e# If it is, push the vector and terminate the loop.
p        e# Print the item on the stack.

If there is no solution, p will be called on an empty stack, throwing an error and producing no output.

source: Stack Exchange

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

sort: votes


text:
Illustrate the square of a binomial
Given (by any means) two different natural numbers (of any reasonable size), output (by any means) the square of their sum as in the examples below:
Given 4 and 3, output:
12 12 12 12  9  9  9
12 12 12 12  9  9  9
12 12 12 12  9  9  9
16 16 16 16 12 12 12
16 16 16 16 12 12 12
16 16 16 16 12 12 12
16 16 16 16 12 12 12

Given 1 and 3, output:
3 9 9 9
3 9 9 9
3 9 9 9
1 3 3 3

Whitespace may vary within reason but the columns must be left-aligned, right-aligned, or (pseudo-)centered.
A trailing newline is fine, but standard loopholes are not.
This is code-golf so include a header like # LanguageName, 123 in your answer, where the number is chars (bytes for languages that are not text-based). Packing code to large Unicode chars is not allowed.

Bonus: -3 if your code outputs just one square when one of the numbers is 0; e.g. given 0 and 3, output:
9 9 9
9 9 9
9 9 9

what is the maximum value of the input numbers? thanks.

@donbright No artificial limit. Only limit is what your computer and language can handle when it comes to representation, computation (with your chosen algorithm) and result. Potentially, a modern computer equipped with a printer that accepts data line by line, would have almost no limit... :-)

Is the square orientation a given, or can we rotate it 90 degrees?

Why the bonus for 0 values though? What would the expected output be if not just one square?

@MarchHo That's why the bonus is so small. Still, some languages may not be able to handle empty arrays.

@JanDvorak The orientation must be as shown: First input's square in lower left corner, second input's in upper right.

J, 9 bytes - 3 = 6
#~@|.*/#~

Inspired by @NBZ's APL answer, golfed down by @randomra.
This defines a verb that takes in an array of numbers. It's used as follows:
   (#~@|.*/#~) 4 3
12 12 12 12  9  9  9
12 12 12 12  9  9  9
12 12 12 12  9  9  9
16 16 16 16 12 12 12
16 16 16 16 12 12 12
16 16 16 16 12 12 12
16 16 16 16 12 12 12

I also claim the 3-byte bonus, since an input of 0 produces sub-matrices of size zero:
   (#~@|.*/#~) 4 0
16 16 16 16
16 16 16 16
16 16 16 16
16 16 16 16
   (#~@|.*/#~) 0 3
9 9 9
9 9 9
9 9 9

Explanation
J has a definite edge in this challenge.
In addition to eating array manipulation problems for breakfast, it prints 2D matrices in the correct format by default.
       #~  Replicate each number n in input n times
#~@|.      The same for reversed input
     */    Compute their multiplication table

This makes me feel right at home.

This solution looks like an obscure variation of the table flipper ASCII emoticon (╯°□°）╯︵ ┻━┻

Octave, 45 bytes - 3 = 42
s=@(m,n)[a=ones(n,1)*n;b=ones(m,1)*m].*[b;a]'

Explanation
This constructs two vectors (let's assume m = 4 and n = 3):
ones(n, 1) constructs an array of ones of size n x 1, so multiplying the ones by n we get:
ones(n, 1) * n => [3 3 3]' (where ' is transpose... n x 1 is a column vector)

a = [3 3 3  4 4 4 4]'   %// a is a column vector
b = [4 4 4 4  3 3 3]    %// b is a row vector

Then the vectors are multiplied in an element-wise fashion, with automatic broadcast expansion so that the 7-element vectors produce a 7x7-element matrix:
    [3] .* [4 4 4 4 3 3 3]
    [3]
    [3]
    [4]
    [4]
    [4]
    [4]

For example, multiplication of the first row of a by b gives:
    [3] .* [4 4 4 4 3 3 3] = [12 12 12 12  9  9  9]

And similarly for the remaining rows of a.
Output:
>> s(4,3)
ans =

   12   12   12   12    9    9    9
   12   12   12   12    9    9    9
   12   12   12   12    9    9    9
   16   16   16   16   12   12   12
   16   16   16   16   12   12   12
   16   16   16   16   12   12   12
   16   16   16   16   12   12   12

>> s(3,0)
ans =

   9   9   9
   9   9   9
   9   9   9

You can try it here on ideone

You can remove the s=. We have the convention that anonymous functions/lambdas do not have to be stored in a variable.

@flawr but then the answer wouldn't be 42...

OK.

Dyalog APL, 10-3 = 7
Inspired* by this answer where the arguments are replicated and then used in a multiplication table:
⊖∘.×⍨(/⍨⎕)

⎕ Issues a prompt (⎕:) and evaluates any expression entered then. (For security reasons, this doesn't work on TryAPL but it does work on NGN/APL.)
/⍨ Replicates its argument itself times (/⍨4 3 ⇔ 3 3 3 4 4 4 4)
∘.×⍨ Creates a multiplication table.
⊖ Flips upside down.
This happens to work on any length input (input is indented 6 spaces, output is at left margin):
      ⊖∘.×⍨(/⍨⎕)
⎕:
      ⍬      ⍝ Empty list (the square of nothing)
      ⊖∘.×⍨(/⍨⎕)
⎕:
      0      ⍝ 0² = 0
      ⊖∘.×⍨(/⍨⎕)
⎕:
      0 1      ⍝ (0+1)² = 1²
1
      ⊖∘.×⍨(/⍨⎕)
⎕:
      2 3      ⍝ (2+3)² = 2² + 3²
6 6 9 9 9
6 6 9 9 9
6 6 9 9 9
4 4 6 6 6
4 4 6 6 6
      ⊖∘.×⍨(/⍨⎕)
⎕:
      1 2 3      ⍝ (1+2+3)² = 1² + 2(1×2) + 2(1×3) + 2² + 2(2×3) + 3²
3 6 6 9 9 9
3 6 6 9 9 9
3 6 6 9 9 9
2 4 4 6 6 6
2 4 4 6 6 6
1 2 2 3 3 3
      ⊖∘.×⍨(/⍨⎕)
⎕:
      ⍳4    ⍝ Integers 1 through 4
4 8 8 12 12 12 16 16 16 16
4 8 8 12 12 12 16 16 16 16
4 8 8 12 12 12 16 16 16 16
4 8 8 12 12 12 16 16 16 16
3 6 6  9  9  9 12 12 12 12
3 6 6  9  9  9 12 12 12 12
3 6 6  9  9  9 12 12 12 12
2 4 4  6  6  6  8  8  8  8
2 4 4  6  6  6  8  8  8  8
1 2 2  3  3  3  4  4  4  4

*Originally, I had a different solution in mind: Each rectangle is created separately by creating a multiplication table for each combination of the two arguments. Then the four squares are mended together vertically and horizontally. It looks like this:
,/⍪⌿⊖∘.(,⍴×)⍨⎕

⎕ Prompt, as above.
,⍴×< Combine (,) the args and use that to shape (⍴) a rectangle filled with their product (×).
∘.(…)⍨ Create a table where each cell is whatever is specified in (…)
⊖ Flip vertically.
⍪⌿ Combine cells vertically.
,/ Combine cells horizontally.

Nice! Same idea in J with equal score: (|.*/])@#~

@Zgarb Update your answer and put a footnote like mine. J deserves it!

R, 31 - 3 = 28
rev(b<-rep(a<-scan(),a))%*%t(b)

Explanation:
           a<-scan()            # take numeric input and store as vector a
    b<-rep(         ,a)         # repeat each numeric input by itself and store as vector b
rev(                   )        # the reverse of vector b
                        %*%     # matrix multiplication
                           t(b) # the transposed of vector b

This also works for more than two numbers. For example, the output for (5,3,2) looks like this:
      [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
 [1,]   10   10   10   10   10    6    6    6    4     4
 [2,]   10   10   10   10   10    6    6    6    4     4
 [3,]   15   15   15   15   15    9    9    9    6     6
 [4,]   15   15   15   15   15    9    9    9    6     6
 [5,]   15   15   15   15   15    9    9    9    6     6
 [6,]   25   25   25   25   25   15   15   15   10    10
 [7,]   25   25   25   25   25   15   15   15   10    10
 [8,]   25   25   25   25   25   15   15   15   10    10
 [9,]   25   25   25   25   25   15   15   15   10    10
[10,]   25   25   25   25   25   15   15   15   10    10

You will probably need to wrap it up into cat or write in order for it to be a valid answer.

@DavidArenburg I don't see why? It says "Output (by any means)". It took me only one mean to output so that puts me within requirements.

Yeah maybe you are right. Not sure what they mean by that.

@DavidArenburg Yeah, it's fine. This is a data/text challenge, not an input/output challenge.

Haskell, 153 125 bytes - 3 = 122
(#)=replicate
d=length.show
y%x=unlines$(>>= \n->(1+d(x*x+y*y)-d n)#' '++show n)<$>x#(y#(x*y)++x#(x*x))++y#(y#(y*y)++x#(x*y))

Half of the code is for output formatting. It works for arbitrary large integers. Example output:
> putStrLn $ 4 % 3
12 12 12 12  9  9  9
12 12 12 12  9  9  9
12 12 12 12  9  9  9
16 16 16 16 12 12 12
16 16 16 16 12 12 12
16 16 16 16 12 12 12
16 16 16 16 12 12 12

> putStrLn $ 6 % 0
36 36 36 36 36 36
36 36 36 36 36 36
36 36 36 36 36 36
36 36 36 36 36 36
36 36 36 36 36 36
36 36 36 36 36 36

Sometimes there's an additional whitespace between the numbers, because I'm calculating the space needed based on x*x+y*y instead of max (x*x) (y*y), e.g.
> putStrLn $ 2 % 3
  6  6  9  9  9
  6  6  9  9  9
  6  6  9  9  9
  4  4  6  6  6
  4  4  6  6  6

But it's at most one whitespace.

CJam, 27 bytes - 3 = 24
q:L~_]ze~_ff{*sL,2*Se[}W%N*

Takes input as a CJam style array. It uses a bit more spacing than necessary, but I think it's "within reason", and it's always properly right aligned.
Test it here.
Explanation
q:L    e# Read the input and store it in L.
~_     e# Evaluate the input, pushing [A B] onto the stack and duplicate it.
]z     e# Wrap both in an array and transpose it to get [[A A] [B B]].
e~     e# Run-length decode, getting A copies of A and B copies of B.
_ff{   e# Double map over each pair of entries in this new array...
  *s   e#   Multiply the two values.
  L,2* e#   Push twice the length of the input string.
  Se[  e#   Pad the result to this width with spaces (from the left).
}
W%     e# Reverse the resulting matrix to get the correct orientation.
N*     e# Join the rows with linefeed characters.

Nice, but what causes that much white-space, and what would be needed to reduce it?

@NBZ The shortest way I've found so far to compute a reliable upper bound on the cell width is to use twice the length of the input string (because the larger number squared won't have more than twice as many digits as the number itself). Of course I could compute the actual amount necessary based on the resulting numbers, but that would be a fair bit longer.

Mathematica 56-3 = 53
Update:
I added a second method, of precisely the same code size, that uses a named function.    It employs an Array rather than a Table but follows the same logic.  (See below.)
Method 1
This makes a table of products, the factors of which depend on the row, column values.  The pair of numbers is entered as a list of integers.  Anonymous functions such as the following, are most useful if they are used only once in a program. Otherwise it makes more sense to use a named function.
Grid@Table[If[r>#2,#,#2]If[c>#,#2,#],{r,#+#2},{c,#+#2}]&

Each factor is an If-then statement:

If[r>#2,#,#2] means, "If the row number is greater than the second input, use the first input as the factor, otherwise use the second input.
If[c>#,#2,#] means, "If the column number is greater than the first input, use the second input as the factor, otherwise use the first input.

Example 1
 Grid@Table[If[r>#2,#,#2]If[c>#,#2,#],{r,#+#2},{c,#+#2}]&@@{5,3}

Example 2
Grid@Table[If[r>#2,#,#2]If[c>#,#2,#],{r,#+#2},{c,#+#2}]&@@{0,3}

Method 2 (Also 56-3 = 53)
This works similarly to Method 1.  But it requires less code when called.  And the cells are addressable, unlike cells in a table.  This method is better to use if the function will be used more than once.
a_~f~b_:=Grid@Array[If[#>a,a,b]If[#2>a,b,a]&,{a+b,a+b}]

The examples from above are produced by the following:
Ex 1:
f[4,3]

Ex 2:
f[0,3]

That is ingenious. With that method I can reduce my own solution by 4 characters.

Thanks.  I just realised that the same approach works with a named function.  See Method 2 above.

C function (using glibc), 122 bytes - 3 = 119
Mostly straightforward implementation with 2 loops.  I expect there are some golfing opportunities I have missed here:
f(n,m,x,y){for(x=0;x<n+m;x+=puts(""))for(y=0;y<n+m;y++)printf(" %*d",snprintf(0,0,"%d",n>m?n*n:m*m),(x<m?m:n)*(y<n?n:m));}

Inputs are passed in the first two parameters of the function, the other two are dummies.  Columns are right-aligned.
Note glibc puts() always seems to return the number of bytes written including implicit trailing newline, which is what we need here.  No guarantees this will work with any other libc.
In a full program:
f(n,m,x,y){for(x=0;x<n+m;x+=puts(""))for(y=0;y<n+m;y++)printf(" %*d",snprintf(0,0,"%d",n>m?n*n:m*m),(x<m?m:n)*(y<n?n:m));}

int main (int argc, char **argv) {
    if (argc == 3) {
        f(atoi(argv[1]),atoi(argv[2]));
    }
}

Compile as gcc sqrbin.c -o sqrbin (or make sqrbin).  Warnings may safely be ignored.
Example output:
$ ./sqrbin 4 3
 12 12 12 12  9  9  9
 12 12 12 12  9  9  9
 12 12 12 12  9  9  9
 16 16 16 16 12 12 12
 16 16 16 16 12 12 12
 16 16 16 16 12 12 12
 16 16 16 16 12 12 12
$ ./sqrbin 4 0
 16 16 16 16
 16 16 16 16
 16 16 16 16
 16 16 16 16
$

Based on my experience, the return value of puts() is machine dependent. It's 10 on mine for instance. Also, here's a tip: you can usually compress two loops into one if you conditionally increment the counter in the external loop. My solution demonstrates how it can be done.

@xsot Yes, puts() return code is only guaranteed to be +ve for success.  However my testing with glibc seems show that the return value is number of bytes written.  As for the loop consolidation - yes, I'm aware of that technique and have tried that here, so far with no shortening in this case.

Octave, 34 - 3 = 31
@(a)rot90(b=repelems(a,[1,2;a]))*b

Examples:
octave:1> f = @(a)rot90(b=repelems(a,[1,2;a]))*b;
octave:2> f([4,3])
ans =

   12   12   12   12    9    9    9
   12   12   12   12    9    9    9
   12   12   12   12    9    9    9
   16   16   16   16   12   12   12
   16   16   16   16   12   12   12
   16   16   16   16   12   12   12
   16   16   16   16   12   12   12

octave:3> f([0,3])
ans =

   9   9   9
   9   9   9
   9   9   9

Wow, I had no idea repelems existed. Awesome!

Python 2, 176 bytes - 3 = 173
def g(m,n):
 y,x,z,l,f='y','x','z','l','%'+str(len(str(max(m*m,n*n))))+'s'
 d={y:m*n,x:n*n,z:m*m,l:'\n'}
 for i in map(lambda x:d[x],(y*m+x*n+l)*n+(z*m+y*n+l)*m): print f % i,

This uses Python string functions to create a character grid, then replaces the characters with integers and prints formatted output.

Interesting method.

Ruby, (133 - 3) = 130 bytes
s=1
a=ARGV.map{|e|s*=(e=e.to_i);[e]*e}.flatten
s=s.to_s.size
a.reverse.each{|i|a.each{|j|print (i*j).to_s.rjust(s).ljust(s+3)};puts}

for 4,3
12   12   12   12    9    9    9
12   12   12   12    9    9    9
12   12   12   12    9    9    9
16   16   16   16   12   12   12
16   16   16   16   12   12   12
16   16   16   16   12   12   12
16   16   16   16   12   12   12

for 1,3
3   9   9   9
3   9   9   9
3   9   9   9
1   3   3   3

for 0,3
9   9   9
9   9   9
9   9   9

Welcome to PPCG! I don't think your padding is sufficient for large numbers. Consider having a 1 and a large number like 9999. Than s will come out as 4, so you're padding to a width of s+3 = 7 but 9999^2 needs 8 digits. You might want to use 2*s instead.

Regardless, here are some golfing tips: I don't see why you need the rjust before doing ljust. You can shorten print to $><< (and get rid of the space after it). ARGV has an alias $*. You might be able to avoid the flatten by building your array with something like this: http://codegolf.stackexchange.com/a/19493/8478. Also, function-only answers are definitely allowed around here (even unnamed functions), so that function could take the integers as inputs, and you wouldn't have to do any .to_i.

@MartinBüttner, thank you for the tips.

Blocks, 52 62 82 87 51 bytes
::`+`1|U;{`*`1}|A;`+`1,0+`1={`1^2}|;0+`,`1+`={`^2}|

Ungolfed:
::
  ` + `1                    | Expand;
  {` * `1}                  | SetAll;
  ` + `1, 0 + `1 = {`1 ^ 2} | Set;
  0 + `, `1 + `  = {` ^ 2}  | Set

Try it

C, (125 - 3) bytes
i,j,a;main(b,s){for(sscanf(gets(s),"%d %d",&a,&b);j<a+b;)printf(++i>a+b?i=!++j,"\n":"%*d",strlen(s)*2,(i<a?a:b)*(j<b?b:a));}

Input is taken as two space-separated integers on the same line. Each cell is padded with spaces to twice length of the input string.

im having trouble getting this to compile with gcc (4.8.4)...

I tested this on http://golf.shinh.org/check.rb which uses the debian package gcc-4.6.1-2. What compile errors are you getting?

sorry i tried again as all one line and it worked,... but when i run i get a segfault. i entered the string 2 3 and hit return and it says Segmentation fault (core dumped)

Sorry but I don't know why it won't work for you. At least you can still try out the code at the site I linked earlier :)

Matlab, 58 − 3 = 55
Using an anonymous function:
@(a,b)flipud(blkdiag(a^2*ones(a)-a*b,b^2*ones(b)-a*b)+a*b)

Example:
>> @(a,b)flipud(blkdiag(a^2*ones(a)-a*b,b^2*ones(b)-a*b)+a*b)
ans =
    @(a,b)flipud(blkdiag(a^2*ones(a)-a*b,b^2*ones(b)-a*b)+a*b)
>> ans(4,3)
ans =
    12    12    12    12     9     9     9
    12    12    12    12     9     9     9
    12    12    12    12     9     9     9
    16    16    16    16    12    12    12
    16    16    16    16    12    12    12
    16    16    16    16    12    12    12
    16    16    16    16    12    12    12

>> @(a,b)flipud(blkdiag(a^2*ones(a)-a*b,b^2*ones(b)-a*b)+a*b)
ans =
    @(a,b)flipud(blkdiag(a^2*ones(a)-a*b,b^2*ones(b)-a*b)+a*b)
>> ans(0,3)
ans =
     9     9     9
     9     9     9
     9     9     9

(Old solution) 59 − 3 = 56
Using an anonymous function:
@(a,b)[b*a*ones(b,a) b^2*ones(b);a^2*ones(a) a*b*ones(a,b)]

Pyth, 39 − 3 = 36
Pyth doesn't have built-in matrix formatting, which greatly increases the size, as one has to manually pad the output numbers. Here's what I came up with.
JAQL*b]jdm.[`d\ l`eS^R2Jsm*d]*bdJj+yHyG

Try it online.

Jelly, \$6 - 3 = 3\$ bytes
x`×þU$

Try it online!
A port of the APL and J answers. Takes input as [a, b]
How it works
x`×þU$ - Main link. Takes a pair `[a, b]` on the left
 `     - Using [a, b] as both arguments:
x      -   Repeat a a times and b b times
     $ - To this repeated array:
    U  -   Reverse the array
  ×þ   -   Generate a multiplication table

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:
What's my math assignment?
The Challenge
I always write my math assignments down in the same way. For example:
pg. 420: #25, 50-56, 90
pg. 26: #50-60 evens, 70-80 odds, 90-99 3s
pg. 69: #12, 16, 18, 37

But I need you to tell me the individual problem numbers. For example:
input:
pg. 420: #25, 50-56, 90

output:
25, 50, 51, 52, 53, 54, 55, 56, 90

Here are the rules for telling me my problem numbers:
The assignment always starts with pg. (number): #, feel free to discard it.
Each group of problems is separated by a comma, and different patterns mean different things.
A single number (4, 6, 7438, 698236) just means that one problem is in the assignment.
Two numbers with a dash between them means those two numbers and all integers between. For example, 1-6 would become 1, 2, 3, 4, 5, 6
If two numbers have a dash between them, then there's a word, there is a special rule for the numbers.
If the word is evens, then all even numbers between the two are included (1-6 evens -> 2, 4, 6).
If the word is odds, then all odd numbers between the two are included (1-6 odds -> 1, 3, 5).
If the word is 3s, then all numbers where n mod 3 = 0 between the two are included (1-6 3s -> 3, 6);
Test Examples: (inputs then outputs)
pg. 1: #1, 2, 3
1, 2, 3

pg. 82: #76, 84-87, 91, 94-100 evens, 103-112 3s
76, 84, 85, 86, 87, 91, 94, 96, 98, 100, 103, 106, 109, 112

pg. 9001: #9000-9002 odds
9001

This is code-golf, so your score is the number of bytes.

Would stuff like "every other odd/even" be a valid input? Or "every other problem"?

@CᴏɴᴏʀO'Bʀɪᴇɴ Those wouldn't be valid input currently; do you think they should be?

No, just wondering.

I feel like we've had this challenge before.

Closely related: Tell me how many math problems I have to do!

@Dennis TBH, that's just straight up a duplicate. This question does not differ significantly enough IMO.

JavaScript (ES7), 138 bytes
F=s=>s.replace(/.*#|(\d+)-?(\d+)? ?(\d|\w*)s?/g,(_,a,b,c)=>b?[for(i of Array(b-a--+1))if(++a*c?(b-a)%c<1:!c||a%2==c>'f')a].join`, `:a||'')

F=s=>s.replace(/.*#|(\d+)-?(\d+)? ?(\d|\w*)s?/g,(_,a,b,c)=>b?[for(i of Array(b-a--+1))if(++a*c?(b-a)%c<1:!c||a%2==c>'f')a].join`, `:a||'')
button.onclick=()=>output.innerHTML=F(range.value)
button, textarea {
  display: block;
  width: 100%;
  margin-bottom: 0.5em;
  box-sizing: border-box;
}
<textarea id="range"></textarea>
<button id="button">submit</button>


text:
Insert a given pattern at a given point
The challenge
Insert one string into another at a given index.
Given a string input in the format:
#:Pattern:Word

Where:

# is a positive integer marking the index
Pattern is the string (whose length is undefined) to insert
: is a delimiter
Word is the string to insert into.

Assume that a : will not be used in either string.
For example, if your input was
3:A2C:Hello World!

The output would be
HelA2Clo World!

If an invalid index is provided, the program must respond with an error. For example
12:!*!:Hello

is a valid input and must be explicitly handled somehow. For example, printing "Invalid input!" (or nothing at all!) is a valid way to catch, however crashing is not valid.

Does invalid index just refer to indexes that are too high, or do we have to worry about negative indexes, non-integers or just non-numeric garbage?

How do you define "respond with an error"? In many languages, this is done by crashing, so how strict is the rule on "crashing is not considered handling"? For example, when Java errors it stops execution and prints the stacktrace. Is this for or against the rules?

@Dennis Just indexes that are too high. Assume the # is a valid, positive integer.

@GamrCorps I tired to be more specific. Basically your code has to explicitly do something, you can't rely on the language to deal with it for you.

@Chipperyman got it. thanks!

Does 3:x:ABC gives ABCx, or is it invalid?

@xnor ABCx

@Chipperyman Bah, no I have to rewrite the whole thing... (Also, that's appending, not inserting. :P)

I've found a typo! 12:!*!:Hello is a valid input, not an invalid input!

@wizzwizz4 it says a valid already, doesn't it?

@Chipperyman Sorry, I wasn't clear! It says above the example that 12:!*!:Hello is an invalid input, but below the example it says that it is valid. I think the a valid is a typo.

CJam, 20 bytes
q':/~La+@~/(@@_{];}|

Try it online in the CJam interpreter.
How it works
q':/                e# Read all input and split it at colons.
    ~                e# Dump index, pattern and word on the stack.
     La+             e# Append the array [""] to the word.
                     e#   This increases the word's length by 1 (to deal with the
                     e#   highest index possible index) without affecting output.
        @~           e# Rotate the index on top and evaluate it.
          /          e# Split the word into chunks of that length.
           (         e# Shift out the first chunk.
            @@       e# Rotate pattern and remaining chunks on top.
              _      e# Copy the array of remaining chunks.
                     e#   This array will be empty if the index was too high.
               {];}| e# If the array if falsy, clear the stack.

Python 3, 65 bytes
a,b,c=input().split(':')
a=int(a)
if c[a-1:]:print(c[:a]+b+c[a:])

Does nothing if the index is past the end of the string. Try it online.

Based on this clarification that the insertion can happen at the end, the a<len(c) should be a<=len(c).

It's a bit shorter to do if c[a-1:].

CJam, 34 bytes
Terribly ungolfed, but its my first CJam golf ever! Thanks to sp3000 for helping me with this on The Nineteenth Byte chat!
l':/~_,W$i>{W$i/(:+-2$+-3$+:+p}&];

EDIT: oops, I was in the process of posting this and I didn't see Dennis' CJam post. If the answers do end up using the same process, just count mine as a non-competitive answer. Sorry for the confusion.

JavaScript ES6, 49 bytes
s=>([a,b,c]=s.split`:`,c.slice(0,a)+b+c.slice(a))

Very straightforward. Slices the string and inserts the new substring in the middle

Ruby, 43 bytes
37 bytes of code:
G,O,L=$F
$_=(L[G.to_i,0]=O;L)rescue p

and 6 bytes of flags:
$ ruby -apF: code.rb < input
       ^^^^^^

Pyth, 33
=Ycw\:JvhYp?>leYJjk[<eYJ@Y1>eYJ)Z

Prints 0 if the index is past the end of the string
Try is online

Perl 5, 41 Bytes (40 + 1)
Outputs 0 when a replacement couldn't be made.
($n,$s,$_)=split/:/;$_=0if!s/.{$n}/$&$s/

Test
$ echo "6:Online :Hello World!" |perl -p -e '($n,$s,$_)=split/:/;$_=0if!s/.{$n}/$&$s/'
$ Hello Online World!

Why that , in front of if? Works without too. And as the -e command line option is for free and you only need 1 more character if you write it as -pe, your code could be 40 + 1 = 41 bytes.

Corrected.  Yeah well, was counting 2 bytes for using -p, since in another solution the - was also counted. But it should indeed be only 1 penalty for -p.  Thanks for noticing the comma.  It's often needed with that post-notation, but I didn't check if it was needed this time.

Pyth, 32 bytes
Beats the other Pyth answer! Still needs a lot of golfing though. Took the naïve approach.
?gleJcz":"KvhJ++:eJ0KhtJ:eJKleJ"

 Try it online.

Based on a comment, you should be able to add the value at the end. This can be fixed at no cost by using g instead of >. With some additional golf changes I get 26 bytes. PM me if you are curious about any of the changes, most are just aliases. Happy Pyth golfing! :)

Pyth, 23
*sX0ceJcz\:KvhJhtJgleJK

Unfortunately (in this scenario anyway), Pyth doesn't error on chopping a string by too large a value. Otherwise the check would go from 6 bytes to 2.
I'm unsure if this is the most optimal approach, but this chops the word after the number of characters from the input. Then it does a += on the first element of the list and returns the sum. It multiplies the resulting string by a boolean representing if the value was out of range.
Also note that this does not work if the input is 0. The OP said we could assume the number is positive, so I believe this is ok.
Try it online

Perl, 34 bytes
(includes 1 switch)
perl -pe '$x="."x$_;s/.*:(.*):($x)|.*/$2$1/'

Prints an empty line on error.

C++11, 186 bytes
Golfed
#include<iostream>
#include<regex>
int main(){std::string p,w;int i,j;std::getline(std::cin>>i,p);j=p.find(58,1);w=p.substr(j+1);if(i<=w.length())std::cout<<w.insert(i,p.substr(1,j-1));}

Ungolfed
#include <iostream>
#include <regex>

int main()
{
    std::string p, w;
    int i, j;
    std::getline(std::cin >> i, p);
    j = p.find(':', 1);
    w = p.substr(j + 1);
    if (i <= w.length())
        std::cout << w.insert(i, p.substr(1, j - 1));
}

Looking for: Improvements and someone who can do Shakespear, so that I am not last again :)

Retina, 38 bytes
(()1)*:(.+):((?<-2>.)*)(?!\2)|^.+
$4$3

Run the code from a single file with the -s flag. This takes input in unary, e.g.
111:A2C:Hello World!

yields
HelA2Clo World!

If the index is too large, an empty line will be printed.

Haskell, 97 bytes
a=fmap tail.span(/=':')
m!(n,e)|m>length e=""|0<1=take m e++n++drop m e
f l|(o,r)<-a l=read o!a r

Defines f, a function that takes a string like "2:x:ABC" and returns "ABxC".

Julia, 66 bytes
s->(x=split(s,":");i=parse(Int,x[1]);x[3][1:i]*x[2]*x[3][i+1:end])

This creates an unnamed function that accepts a string and returns a string. It errors if the index is out of bounds.
Ungolfed:
function f(s::AbstractString)
    # Split the input on the colon
    x = split(s, ":")

    # Convert the first element of x to an integer
    i = parse(Int, x[1])

    # Join the pieces
    return x[3][1:i] * x[2] * x[3][i+1:end]
end

Ruby, 55 bytes
a,b,c=gets.split ?:;(c[a,0]=b;p c)if c.size>=(a=a.to_i)

It's been a while since I've golfed in Ruby... this feels a bit suboptimal.

Gema: 47 characters
*\:*\:*=@subst{<U$1>\*=\$1@quote{$2}\*\;\*=;$3}

Sample run:
bash-4.3$ gema '*\:*\:*=@subst{<U$1>\*=\$1@quote{$2}\*\;\*=;$3}' <<< '3:!*!:Hello'
Hel!*!lo

bash-4.3$ gema '*\:*\:*=@subst{<U$1>\*=\$1@quote{$2}\*\;\*=;$3}' <<< '13:!*!:Hello'

(If you want an explicit error message, just insert it after the last = sign.)

MUMPS, 70 bytes
a(s) s w=$P(s,":",3) q:s>$L(w)  w $E(w,1,s)_$P(s,":",2)_$E(w,s+1,9**9)

There is no output if an invalid index is provided.
This code is basically ANSI-compliant; the only issue is that I've saved a byte by taking advantage of the fact that the maximum length of a string on the two major surviving MUMPS platforms is less than 99 bytes: InterSystems Caché caps strings at 32 KiB, and GT.M caps strings at 1 MiB. Nonetheless, in principle, some jerk could write an implementation that allows strings over ~369 MiB, in which case there would be valid inputs for which this code fails.
We can save 3 additional bytes, bringing us down to 67, if we use non-ANSI Caché ObjectScript-specific extensions to $EXTRACT:
a(s) s w=$P(s,":",3) q:s>$L(w)  w $E(w,1,s)_$P(s,":",2)_$E(w,s+1,*)

Perl 6, 58 bytes
$_=[split ':',@*ARGS];substr-rw(.[2],.[0],0)=.[1];.[2].say


text:
Monday Mini-Golf #5: <s>Don't</s> DO try this at home
Monday Mini-Golf: A series of short code-golf questions, posted (hopefully!) every Monday.
Sometimes folks get tired of life's rules: "don't do this", "you can't do that", "we won't let you do this". It can seem really restricting at times! But every now and then, it's good to have a little fun, so let's write some code to modify these rules. And while we're at it, might as well modify other negativity as well. (Of course, these modifications won't WILL be only temporary, so we'll leave the original wording too.)
Challenge
Your challenge is to write a program or function that puts HTML <s>strikethroughs</s> around restrictive words—that is, words ending in n't or followed by not—and after each of these, inserts its positive equivalent in ALL CAPS. At the end, after a space, the number of replacements made should be included. For example:
Please don't jump into the pool.

becomes
Please <s>don't</s> DO jump into the pool. 1

For words ending in n't or followed by not (as well as cannot), the positive equivalent is everything up to the aforementioned not (excluding spaces). Here's what I mean:

do not speak becomes <s>do not</s> DO speak
it doesn't work becomes it <s>doesn't</s> DOES work
we cannot becomes we <s>cannot</s> CAN

However, there are a few exceptions. Make sure these are handled properly.
can't -> <s>can't</s> CAN
won't -> <s>won't</s> WILL
ain't -> <s>ain't</s> AM
shan't -> <s>shan't</s> SHALL
I'm not -> <s>I'm not</s> I AM
you're not -> <s>you're not</s> YOU ARE

Details

The input will never contain any whitespace except normal spaces (no tabs, newlines, etc.).
The input will never contain any double negatives (e.g. we can't not do this).
If a not appears immediately after a punctuation mark, or as part of another word, leave it be.
Be sure to preserve the original text, including upper/lowercase, between the <s></s> tags.
If you wish, you may use  in place of <s></s>.

Test-cases
Inputs:
I'm sorry, but you can't do that.
Driving on the beach isn't allowed.
Driving on the beach is not allowed.
Please don't jump in; I cannot imagine what might come of that.
Don't worry; we won't get into trouble.
I'm not perfect, but you're not either.
You shan't do it 'cause I ain't doin' it!
Can't we capitalize special cases?
I don't like the words can't, shan't, won't, don't, ain't, or ppcgn't.
Oh, this? It's nothing.
Tie a slipknot in the rope.
Would you like Pinot Noir?
This sentence contains none of the replacement words. Not even knot or ca't.
This sentence doesn't contain one of the replacement words.

Outputs:
I'm sorry, but you <s>can't</s> CAN do that. 1
Driving on the beach <s>isn't</s> IS allowed. 1
Driving on the beach <s>is not</s> IS allowed. 1
Please <s>don't</s> DO jump in; I <s>cannot</s> CAN imagine what might come of that. 2
<s>Don't</s> DO worry; we <s>won't</s> WILL get into trouble. 2
<s>I'm not</s> I AM perfect, but <s>you're not</s> YOU ARE either. 2
You <s>shan't</s> SHALL do it 'cause I <s>ain't</s> AM doin' it! 2
<s>Can't</s> CAN we capitalize special cases? 1
I <s>don't</s> DO like the words <s>can't</s> CAN, <s>shan't</s> SHALL, <s>won't</s> WILL, <s>don't</s> DO, <s>ain't</s> AM, or <s>ppcgn't</s> PPCG. 7
Oh, this? It's nothing. 0
Tie a slipknot in the rope. 0
Would you like Pinot Noir? 0
This sentence contains none of the replacement words. Not even knot or ca't. 0
This sentence <s>doesn't</s> DOES contain one of the replacement words. 1

Scoring
This is code-golf, so shortest valid code in bytes wins. Tiebreaker goes to submission that reached its final byte count first. The winner will not WILL be chosen next Monday, Oct 26. Good luck!

@FryAmTheEggman Yes, unless there are some others worth adding to the list. I'd rather keep it short, but do you have any suggestions?

Nope, just didn't want this to suffer from the "you changed the spec now it sucks" challenge syndrome :P

Suggested test case: Can't we capitalize special cases?

Do we need to be careful with strings like: Oh this? It's nothing... or I wonder if we'll notice any words like this??

@DomHastings Yes; the not should match the regex /\bnot\b/ to be replaced. I'll add another test case for that.

Is  acceptable?

@DLosc added some further excellent test cases in a comment to me:
Tie a slipknot in the rope. and Would you like Pinot Noir?

@Mwr247 Sure, although I don't see how that would be shorter.

@DomHastings Thanks! I'll add those in as well.

@FryAmTheEggman Now that I think about it, there are a bunch more words along the lines of "I'm" and "you're" ("we'll", "it's", "I've", etc.) I'm not going to add those words in, but now it seems kind of pointless having two of them as special cases and none of the rest. Should I remove them, or would it be better to just leave it the way it is?

@ETHproductions Just exploring the options. While deprecated, JavaScript allows a.strike() (which creates  around the string), which is slightly shorter than '<s>'+a+'</s>' , among other potential benefits.

I think it would be better to leave it. Changing the spec never really goes over well, and I don't think it causes much of a problem, besides obviously producing some nonsensical English (but then again you didn't ask for an English parser, so I don't think there is a problem anyway :P )

Perhaps I should have chosen a simpler language ;)

One does not DOES simply convert memes into contests!

Pip, 138 140 bytes
Yeesh, that cannot/knot distinction is tricky.
x:"ca wo ai sha i'm you're"^sY"CAN0WILL0AM0SHALL0I AM0YOU ARE"^0OqR-`([\w']+)( no|n'|(?<=can)no)t\b`{++i"<s>".a."</s>".s.((yx@?LCb)|UCb)}s.i

Reads a line from stdin, outputs to stdout. The regex:
`([\w']+)( no|n'|(?<=can)no)t\b`

matches a word (including apostrophes) followed by one of three things:

 not
n't
not without a space, provided the first half of the word was can

The - operator on a regex makes it case-insensitive.
Matches are replaced with the result of the following function. (Note: within the function, a is the whole match and b is capture group 1.)
{++i"<s>".a."</s>".s.((yx@?LCb)|UCb)}
 ++i                                   Increment counter
    "<s>".a."</s>"                     Return entire match wrapped in HTML tags...
                  .s.(             )   plus space, plus the following:
                           LCb         Lowercase first capture group
                        x@?            Find its index in list x of special cases (nil if
                                         not in list)
                      (y      )        Use that as index into list y of replacements
                               |UCb    If it wasn't a special case, this is nil, and we
                                         instead use uppercase(b)

Once the modified string is done, we also output a space and the number of replacements i.

GNU Sed, 321 bytes
(including +1 for -r)
:
s!(can('|no)t)([^<])!<s>\1</s> CAN\3!i
s!(won't)([^<])!<s>\1</s> WILL\2!i
s!(ain't)([^<])!<s>\1</s> AM\2!i
s!(shan't)([^<])!<s>\1</s> SHALL\2!i
s!(I'm not)([^<])!<s>\1</s> I AM\2!i
s!(you're not)([^<])!<s>\1</s> YOU ARE\2!i
t
s!(([^ .!?]+)(n't| not))([^<])!<s>\1</s> \U\2\4!i
t
h
s/1//g
s/<s>/1/g
s/[^1]//g
x
G
s/\n/ /

"String replacement - a job for sed!" I thought.  But this was surprisingly hard, and I kept inflooping with the substitution of the original text.  And the counting!  At least there's no prohibition on unary in the question...

Perl, 153 bytes
150 script + 3 for -p
$c=0|s!\b((ca)nnot|([\w']+)(?: not|n't))\b!"<s>$&</s> ".uc({ai,AM,ca,CAN,wo,WILL,sha,SHALL,"i'm","I AM","you're","YOU ARE"}->{lc$+}||$+)!egi;s/
/ $c
/

So whilst I match all the test cases now but that regex has cost me dearly... I'll think on it!
Example output:
$perl -p can.pl <<< "I'm sorry, but you can't do that.
Driving on the beach isn't allowed.
Driving on the beach is not allowed.
Please don't jump in; I cannot imagine what might come of that.
Don't worry; we won't get into trouble.
I'm not perfect, but you're not either.
You shan't do it 'cause I ain't doin' it!
Can't we capitalize special cases?
I don't like the words can't, shan't, won't, don't, ain't, or ppcgn't.
Oh, this? It's nothing.
This sentence contains none of the replacement words. Not even knot or ca't.
This sentence doesn't contain one of the replacement words.
Tie a slipknot in the rope.
Would you like Pinot Noir?
You cannot be serious\!"

I'm sorry, but you <s>can't</s> CAN do that. 1
Driving on the beach <s>isn't</s> IS allowed. 1
Driving on the beach <s>is not</s> IS allowed. 1
Please <s>don't</s> DO jump in; I <s>cannot</s> CAN imagine what might come of that. 2
<s>Don't</s> DO worry; we <s>won't</s> WILL get into trouble. 2
<s>I'm not</s> I AM perfect, but <s>you're not</s> YOU ARE either. 2
You <s>shan't</s> SHALL do it 'cause I <s>ain't</s> AM doin' it! 2
<s>Can't</s> CAN we capitalize special cases? 1
I <s>don't</s> DO like the words <s>can't</s> CAN, <s>shan't</s> SHALL, <s>won't</s> WILL, <s>don't</s> DO, <s>ain't</s> AM, or <s>ppcgn't</s> PPCG. 7
Oh, this? It's nothing. 0
This sentence contains none of the replacement words. Not even knot or ca't. 0
This sentence <s>doesn't</s> DOES contain one of the replacement words. 1
Tie a slipknot in the rope. 0
Would you like Pinot Noir? 0
You <s>cannot</s> CAN be serious\! 1

Wow, this is compact!  One issue: I'm not isn't working properly--it should be I AM instead of I'M. But I think you just need to change I'm to i'm in the code to fix it.

Oh--also, try it on sentences like Tie a slipknot in the rope. or Would you like Pinot Noir?. They're not in the test cases yet, but the OP's intention was to exclude any word ending in not except cannot.

@DLosc Excellent test cases! I couldn't think of any longer words ending in not! The I'm was a bad miss, thanks for the spot!


text:
Align the text to a block
Task
Your task is to write whole program, which will align given input to a block of given size.
Input:
40
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

Output:
Lorem  ipsum dolor sit amet, consectetur
adipiscing  elit,  sed do eiusmod tempor
incididunt  ut  labore  et  dolore magna
aliqua.  Ut  enim  ad minim veniam, quis
nostrud   exercitation  ullamco  laboris
nisi ut aliquip ex ea commodo consequat.
Duis  aute  irure dolor in reprehenderit
in voluptate velit esse cillum dolore eu
fugiat  nulla  pariatur.  Excepteur sint
occaecat cupidatat non proident, sunt in
culpa  qui  officia deserunt mollit anim
id est laborum.
                <-- note the linebreak

Input Details

You have to write whole executable/interpretable program.
You may suppose, that the input contains only printable ASCII characters and does not contain tab \t.
The input can contain line breaks. If it does so, they are given as \n, \r, or \r\n depending on what you expect. They are however united throughout whole input.
The input can be given in STDIN, or as command line arguments. You can use both of them if it suits your needs (for example, read block size from command args and input as stdin). You may not, however, hardcode any part of the input to your program.
You may suppose that the block size is given as valid positive (> 0) number.
Line break in the input is treated the same way as a space (thus being word separator)
If the input contains multiple concurrent spaces they are treated as one.

Output details

The output has to be formatted into a block of given size. The formatting is done by adding spaces between words.
The number of spaces between words on a line has to be equal for that line. If it is not possible, additional spaces must be added one by one after words starting from the left.
If the word is longer that given block size, it will stand alone on a single line (and will exceed the block size).
If the output should contain only one word, it will be aligned to the left.
The last line of the output has to be aligned to the left, with only one space between words. The last line of the output has to end with trailing line break.

The answer, with shortest number of bytes after some time, wins.
If you need additional information, leave a comment.
Test cases
Input:
10
Lorem ipsum dolor sit amet,
consectetur adipiscing elit, sed do eiusmod tempor

Output:
Lorem
ipsum
dolor  sit
amet,
consectetur
adipiscing
elit,  sed
do eiusmod
tempor

Input:
20
Lorem     ipsum

dolor  sit amet,

Output:
Lorem   ipsum  dolor
sit amet,

Input:
1
Lorem ipsum dolor sit amet

Output:
Lorem
ipsum
dolor
sit
amet

Related. (Finally a second challenge for my [tag:typography] tag which already got auto-deleted. ;))

@MartinBüttner I didn't know that such tag exists.

@Vɪʜᴀɴ You have to write whole executable/interpretable program.

Duplicate of Justify a text by adding spaces.

@ppperry Interesting, for some reason, it avoided my search skills

@ppperry The rules for space insertion are quite substantially different though.

Pyth, 60 57 54 51 50 52 bytes
2015-10-22: fixing a bug took 2 bytes.
=HfTcjd.zdWHAcH]f|qTlH>jd<HhTQ1s.iGcJ|tlG1*d?H-QlsGJ

Try it online.

Ruby, 179 chars
n=gets.to_i
s=t=''
$<.read.split.map{|w|if(t+w).size>=n
0while t.size<n&&(1..n).any?{|i|t.sub!(/[^ ]#{' '*i}(?=[^ ])/){|x|x+' '}}
s+=t+?\n
t=w
else
t+=' '+w
t.strip!
end}
puts s,t

Way too long...
Semi-ungolfed version:
n = gets.to_i
s = t = ''
$<.read.split.map{|w|
    if (t + w).size >= n
        0 while t.size < n && (1..n).any?{|i|t.sub!(/[^ ]#{' '*i}(?=[^ ])/){|x|x+' '}}
        s += t + ?\n
        t = w
    else
        t += ' ' + w
        t.strip!  # this is only necessary because of the very first word >:(
    end
}
puts s,t

CJam, 87 bytes
l~:LS*qNSerS%{(2$1$a+_S*,L>{;a\}{\;@;\}?}h;S*a]1>{I1>{LIs,-I,(md1b\aI,(*.+Sf*I.\}I?N}fI

This should still be golfable. Try it online in the CJam interpreter.

Retina, 133 bytes
\s+

+`((1)*1 )((?<-2>.)*\S|\S+)
:$3<LF>$1
m+`^(?=.(.)+$[^<TB>]*^(?>(?<-1>1)+)1)((.*):(\S+ +)|(\S+ +)(.*):)
$3$4$5 :$6
+`:|<LF>1+| (?= .*$)
<empty>

The <empty> represents an empty trailing line. To run the code, put each line in a separate file, replace <LF> with linefeed characters (0x0A) and <TB> with a tab (0x09). I'll add an explanation when I'm done golfing.


text:
Arbitrary Clock Time Calculator
Create a routine to calculate the position of each unit of a clock with an arbitrary number of units (minutes, hours, half-days, days, years, parsecs, quarter-quells, etc), where each unit can be equally sub-divided into an arbitrary number of sub-units; after n base units have elapsed.
Basically, figure out what a clock would show after n seconds given user defined lengths for minutes, hours, days, etc.
For example, after 86,400 seconds on a clock that has 60 seconds in a minute, 60 minutes in an hour, 12 hours per half day, 2 half days per day, and 365 days in a year; you get the following:
clockFunction(86400,[60,60,12,2,365]) = 0,0,0,0,1

(Standard Clock)
clockFunction(86400,[60,60,12,2]) = 0,0,0,0

(Standard Clock - Rolling Over)
clockFunction(7430201,[100,100,10,10,3,12]) = 1,2,3,4,1,2

(French Republican Calendar [sec / min, min / hr, hrs / day, days / wk, wks / mo, mo / yr])
clockFunction(2443332,[60,60,24,365]) = 12,42,6,28

(Standard Clock - Donnie Darko)
clockFunction(63570500940,[60,60,12,2,365,10000]) = 0, 29, 4, 1, 294, 2015

(Standard Clock - Back to the Future)
Shortest code that works wins!
Clarifications:

All Units are integer
All Units are greater than 0

In none of the test cases does the last conversion seem to matter at all (eg days/year on the standard clocks). Is this intentional?

I think that's more how I designed the problems. I used that space as a catch all and made it really big so the biggest unit wouldn't roll over. Final unit does matter. I'll add another example.

Parsecs measure as much time as light-years...none.

@brandaemon its a dorky tongue-in-cheek reference to Star Wars :-P

It's in Star Wars all right, but parsecs are a real thing.  I'm very particular about my units.

Dyalog APL, 9 7 5 bytes
⌽⊤⍨∘⌽

This is a dyadic function train that expects seconds and lengths as left and right arguments. It is equivalent to the following, train-less function:
{⌽⍺⊤⍨⌽⍵}

Verify all test cases at once on TryAPL.
How it works
    ⌽ Reverse the right argument...
   ∘    and...
 ⊤⍨     perform mixed base encoding on the left argument with those bases.
⌽     Reverse the order of the result.

Unless someone can get in under 5, winner! Can you explain what your code is doing?

What encoding does this use?

@Mwr247 There are APL code pages (that predate Unicode by a few decades) where each character is a single byte.

@Dennis I figured it was single byte, but for the life of me couldn't find any charset that fit them all. Thanks for clearing that up!

CJam, 10 bytes
{{md\}%W<}

Verify all test cases at once in the CJam interpreter.
How it works
{        }  Define a code block:
 {   }%     For each unit length:
  md          Perform modular division with the topmost integers on the stack.
    \         Swap quotient and residue.
            Collect the results in an array.
       W<   Discard the last quotient.

Javascript ES6, 34 bytes
F=(q,a)=>a.map(u=>[q%u|0,q/=u][0])

Explanation:
F=(q,a)=>a.map(u=>
  // For each unit
  [
    q%u|0, // floored remainder of q / u
    q/=u // set q to quotient of q / u
  ][0] // return remainder
)

C – 166 176 bytes
The Back to the Future test case necessitated using long long types! The output format is not consistent in the specs, sometimes there are spaces after the comma, sometimes not, I assumed this meant the space was discretionary. Handles units of zero by outputting -1.
#include<stdlib.h>
#include<stdio.h>
int main(int c,char**v){long long x=atoll(*++v),m;while(--c>1){m=atoll(*++v);printf("%lld%c",x%m,c>2?',':'\n');x/=m;}return 0;}

To use, save as units.c, compile via gcc -o units units.c, and run on the command line as follows:
$ ./units 63570500940 60 60 12 2 365 10000
0,29,4,1,294,2015

Depending on compiler options, you may be able to remove int  and return 0; for 153 bytes.

MATLAB, 66
function a=d(t,L);a=[];for s=L;a=[a mod(t,s)];t=floor(t/s);end;end

And an explanation
function a=d(t,L)
    a=[];
    for s=L %For each of the input blocks
       a=[a mod(t,s)]; %Append the number in this block
       t=floor(t/s); %And divide by the size of this block ignoring the remainder
    end
end

It's a pretty standard approach. I'll see if I can reduce the length.
It also works with Octave, so you can try it here.

I did literally the same thing in javaScript. Was curious if anyone had anything fancier or some obscure math trick (https://en.wikipedia.org/wiki/Fast_inverse_square_root) to do it with.

Wolfram Language (Mathematica), 47 bytes
#~NumberDecompose~Reverse@FoldList[Times,1,#2]&

Try it online!

><>, 12 bytes
:{:}%:nao-{,

Expect (units...,seconds) on the stack.
><> has the oddball property of supporting floating point division but not integer division, so the verbous stack shifting {} and copying : here is in order to subtract the remainder before performing division.