text:
Fastest Approximate Common Divisor
Overview
In this challenge, you will be given two numbers which are both a small offset larger than a multiple of a medium-size number. You must output a medium-sized number that is almost a divisor of both of the numbers, except for a small offset.
The size of the numbers involved will be parameterized by a difficulty parameter, l. Your objective is to solve the problem for the largest possible l in under 1 minute.

Setup
In a given problem, there will be a secret number, p, which will be a random l^2 (l*l) bit number. There will be two multipliers, q1, q2, which will be random l^3 bit numbers, and there will be two offsets, r1, r2, which will be random l bit numbers.
The input to your program will be x1, x2, defined as:
x1 = p * q1 + r1
x2 = p * q2 + r2

Here's a program to generate test cases, in Python:
from random import randrange
from sys import argv

l = int(argv[1])

def randbits(bits):
    return randrange(2 ** (bits - 1), 2 ** bits)

p = randbits(l ** 2)
print(p)
for i in range(2):
    q_i = randbits(l ** 3)
    r_i = randbits(l)
    print(q_i * p + r_i)

The first line of output is a possible solution, while the second and third lines are the input that your program will be given.

Your Program
Given x1, x2 and l, you must find a l^2 bit number p' such that x1 % p' and x2 % p' are both l bit numbers. p will always work, though there may be other possibilities. Here's a function to verify a solution:
def is_correct(x1, x2, l, p_prime):
    p_prime_is_good = p_prime >> (l**2 - 1) and not p_prime >> l ** 2
    x1_is_good = (x1 % p_prime) >> (l-1) and not (x1 % p_prime) >> l
    x2_is_good = (x2 % p_prime) >> (l-1) and not (x2 % p_prime) >> l
    return bool(p_prime_is_good and x1_is_good and x2_is_good)

Example
Suppose l is 3. The generator program picks a 9-bit number for p, which in this case is 442. The generator picks two 3 bit numbers for r1, r2, which are 4, 7. The generator picks two 27 bit numbers for q1, q2, which are 117964803, 101808039. Because of these choices, x1, x2 are 52140442930, 44999153245.
Your program would be given 52140442930, 44999153245 as input, and must output a 9-bit number (in the range [256, 511]) such that 52140442930 and 44999153245 modulo that number give 3 bit numbers (in the range [4, 7]). 442 is the only such value in this case, so your program would have to output 442.

More examples
l = 2
x1 = 1894
x2 = 2060
p = 11
No other p'.

l = 3
x1 = 56007668599
x2 = 30611458895
p = 424
No other p'.

l = 6
x1 = 4365435975875889219149338064474396898067189178953471159903352227492495111071
x2 = 6466809655659049447127736275529851894657569985804963410176865782113074947167
p = 68101195620
I don't know whether there are other p'.

l = 12
x1 = 132503538560485423319724633262218262792296147003813662398252348727558616998821387759658729802732555377599590456096450977511271450086857949046098328487779612488702544062780731169071526325427862701033062986918854245283037892816922645703778218888876645148150396130125974518827547039720412359298502758101864465267219269598121846675000819173555118275197412936184329860639224312426860362491131729109976241526141192634523046343361089218776687819810873911761177080056675776644326080790638190845283447304699879671516831798277084926941086929776037986892223389603958335825223
x2 = 131643270083452525545713630444392174853686642378302602432151533578354175874660202842105881983788182087244225335788180044756143002547651778418104898394856368040582966040636443591550863800820890232349510212502022967044635049530630094703200089437589000344385691841539471759564428710508659169951391360884974854486267690231936418935298696990496810984630182864946252125857984234200409883080311780173125332191068011865349489020080749633049912518609380810021976861585063983190710264511339441915235691015858985314705640801109163008926275586193293353829677264797719957439635
p = 12920503469397123671484716106535636962543473
I don't know whether there are other p'.

l = 12
x1 = 202682323504122627687421150801262260096036559509855209647629958481910539332845439801686105377638207777951377858833355315514789392768449139095245989465034831121409966815913228535487871119596033570221780568122582453813989896850354963963579404589216380209702064994881800638095974725735826187029705991851861437712496046570494304535548139347915753682466465910703584162857986211423274841044480134909827293577782500978784365107166584993093904666548341384683749686200216537120741867400554787359905811760833689989323176213658734291045194879271258061845641982134589988950037
x2 = 181061672413088057213056735163589264228345385049856782741314216892873615377401934633944987733964053303318802550909800629914413353049208324641813340834741135897326747139541660984388998099026320957569795775586586220775707569049815466134899066365036389427046307790466751981020951925232623622327618223732816807936229082125018442471614910956092251885124883253591153056364654734271407552319665257904066307163047533658914884519547950787163679609742158608089946055315496165960274610016198230291033540306847172592039765417365770579502834927831791804602945514484791644440788
p = 21705376375228755718179424140760701489963164

Scoring
As mentioned above, your program's score is the highest l that the program completes in under 1 minute. More specifically, your program will be run on 5 random instances with that l, and it must output a correct answer on all 5, with an average time under 1 minute. A program's score will be the highest l that it succeeds on. Tiebreaker will be average time on that l.
To give you an idea of what scores to aim for, I wrote a very simple brute-force solver. It got a score of 5. I wrote a much fancier solver. It got a score of 12 or 13, depending on luck.

Details
For perfect comparability across answers, I will time submissions on my laptop to give canonical scores. I will also run the same randomly chosen instances on all submissions, to alleviate luck somewhat. My laptop has 4 CPUs, i5-4300U CPU @ 1.9 GHz, 7.5G of RAM.
Feel free to post a provisional score based on your own timing, just make it clear whether it's provisional or canonical.

May the fastest program win!

Does the approximation have to be the closest one?

@TuukkaX Any l^2 bit number that's l-bits away from being a factor of both numbers works. There's typically only one, however.

Here's a dissertation with some algorithm ideas: http://tigerprints.clemson.edu/cgi/viewcontent.cgi?article=2281&context=all_dissertations. Particularly nice and simple is the one in section 5.1.1

The i5-4300U has 2 cores (4 threads), not 4 cores.

Rust, L=13
src/main.rs
extern crate gmp;
extern crate rayon;

use gmp::mpz::Mpz;
use gmp::rand::RandState;
use rayon::prelude::*;
use std::cmp::max;
use std::env;
use std::mem::swap;

// Solver

fn solve(x1: &Mpz, x2: &Mpz, l: usize) -> Option<Mpz> {
    let m = l*l - 1;
    let r = -1i64 << l-2 .. 1 << l-2;
    let (mut x1, mut x2) = (x1 - (3 << l-2), x2 - (3 << l-2));
    let (mut a1, mut a2, mut b1, mut b2) = (Mpz::one(), Mpz::zero(), Mpz::zero(), Mpz::one());
    while !x2.is_zero() &&
        &(max(a1.abs(), b1.abs()) << l-2) < &x1 &&
        &(max(a2.abs(), b2.abs()) << l-2) < &x2
    {
        let q = &x1/&x2;
        swap(&mut x1, &mut x2);
        x2 -= &q*&x1;
        swap(&mut a1, &mut a2);
        a2 -= &q*&a1;
        swap(&mut b1, &mut b2);
        b2 -= &q*&b1;
    }
    r.clone().into_par_iter().map(|u| {
        let (mut y1, mut y2) = (&x1 - &a1*u + (&b1 << l-2), &x2 - &a2*u + (&b2 << l-2));
        for _ in r.clone() {
            let d = Mpz::gcd(&y1, &y2);
            if d.bit_length() >= m {
                let d = d.abs();
                let (mut k, k1) = (&d >> l*l, &d >> l*l-1);
                while k < k1 {
                    k += 1;
                    if (&d%&k).is_zero() {
                        return Some(&d/&k)
                    }
                }
            }
            y1 -= &b1;
            y2 -= &b2;
        }
        None
    }).find_any(|o| o.is_some()).unwrap_or(None)
}

// Test harness

fn randbits(rnd: &mut RandState, bits: usize) -> Mpz {
    rnd.urandom(&(Mpz::one() << bits - 1)) + (Mpz::one() << bits - 1)
}

fn gen(rnd: &mut RandState, l: usize) -> (Mpz, Mpz, Mpz) {
    let p = randbits(rnd, l*l);
    (randbits(rnd, l*l*l)*&p + randbits(rnd, l),
     randbits(rnd, l*l*l)*&p + randbits(rnd, l),
     p)
}

fn is_correct(x1: &Mpz, x2: &Mpz, l: usize, p_prime: &Mpz) -> bool {
    p_prime.bit_length() == l*l &&
        (x1 % p_prime).bit_length() == l &&
        (x2 % p_prime).bit_length() == l
}

fn random_test(l: usize, n: usize) {
    let mut rnd = RandState::new();  // deterministic seed
    for _ in 0..n {
        let (x1, x2, p) = gen(&mut rnd, l);
        println!("x1 = {}", x1);
        println!("x2 = {}", x2);
        println!("l = {}", l);
        println!("p = {}", p);
        println!("x1 % p = {}", &x1 % &p);
        println!("x2 % p = {}", &x2 % &p);
        assert!(is_correct(&x1, &x2, l, &p));
        let p_prime = solve(&x1, &x2, l).expect("no solution found!");
        println!("p' = {}", p_prime);
        assert!(is_correct(&x1, &x2, l, &p_prime));
        println!("correct");
    }
}

// Command line interface

fn main() {
    let args = &env::args().collect::<Vec<_>>();
    if args.len() == 4 && args[1] == "--random" {
        if let (Ok(l), Ok(n)) = (args[2].parse(), args[3].parse()) {
            return random_test(l, n);
        }
    }
    if args.len() == 4 {
        if let (Ok(x1), Ok(x2), Ok(l)) = (args[1].parse(), args[2].parse(), args[3].parse()) {
            match solve(&x1, &x2, l) {
                None => println!("no solution found"),
                Some(p_prime) => println!("{}", p_prime),
            }
            return;
        }
    }
    println!("Usage:");
    println!("    {} --random L N", args[0]);
    println!("    {} X1 X2 L", args[0]);
}

Cargo.toml
[package]
name = "agcd"
version = "0.1.0"
authors = ["Anders Kaseorg <andersk@mit.edu>"]

[dependencies]
rayon = "0.7.1"
rust-gmp = "0.5.0"

To run
cargo build --release
target/release/agcd 56007668599 30611458895 3
target/release/agcd --random 13 5

Official result is l=13, with an average time of 41.53s. l=14 took a little over 2m on average.

Mathematica, L=5
here is a quick 5 solution
(l = #3;
a = #1 - Range[2^(l - 1), 2^l];
b = #2 - Range[2^(l - 1), 2^l];
Last@Intersection[
Flatten[Table[Select[Divisors@a[[i]], # < 2^l^2 &], {i, Length@a}],
 1],
Flatten[Table[Select[Divisors@b[[i]], # < 2^l^2 &], {i, Length@b}],
 1]]
) &

Input
[x1,x2,L]
in order that anybody can test this, here is the key generator
l = 5;
a = RandomInteger[{2^(l^2 - 1), 2^(l^2)}]
b = RandomInteger[{2^(l^3 - 1), 2^(l^3)}];
c = RandomInteger[{2^(l - 1), 2^l - 1}];
f = RandomInteger[{2^(l^3 - 1), 2^(l^3)}];
g = RandomInteger[{2^(l - 1), 2^l - 1}];
x = a*b + c
y = a*f + g

choose the L value run, the code and you will get three numbers.
place the last two along with L as input, and you should get the first one

I've verified this solution as getting a score of l=5. I'll time it if timing is needed as a tiebreaker.

Python, L=15, average time 39.9s
from sys import argv
from random import seed, randrange

from gmpy2 import gcd, mpz
import gmpy2

def mult_buckets(buckets):
    if len(buckets) == 1:
        return buckets[0]
    new_buckets = []
    for i in range(0, len(buckets), 2):
        if i == len(buckets) - 1:
            new_buckets.append(buckets[i])
        else:
            new_buckets.append(buckets[i] * buckets[i+1])
    return mult_buckets(new_buckets)

def get_products(xs, l):
    num_buckets = 1000
    lower_r = 1 << l - 1
    upper_r = 1 << l
    products = []
    bucket_size = (upper_r - lower_r)//num_buckets + 1
    for x in xs:
        buckets = []
        for bucket_num in range(num_buckets):
            product = mpz(1)
            for r in range(lower_r + bucket_num * bucket_size,
                           min(upper_r, lower_r + (bucket_num + 1) * bucket_size)):
                product *= x - mpz(r)
            buckets.append(product)
        products.append(mult_buckets(buckets))
    return products

def solve(xs, l):
    lower_r = 2**(l - 1)
    upper_r = 2**l
    lower_p = 2**(l**2 - 1)
    upper_p = 2**(l**2)

    products = get_products(xs, l)
    overlap = gcd(*products)
    candidate_lists = []
    for x in xs:
        candidates = []
        candidate_lists.append(candidates)
        for r in range(lower_r, upper_r):
            common_divisor = gcd(x-r, overlap)
            if common_divisor >= lower_p:
                candidates.append(common_divisor)
    to_reduce = []
    for l_candidate in candidate_lists[0]:
        for r_candidate in candidate_lists[1]:
            best_divisor = gcd(l_candidate, r_candidate)
            if lower_p <= best_divisor < upper_p:
                return best_divisor
            elif best_divisor > upper_p:
                to_reduce.append(best_divisor)
    for divisor in to_reduce:
        cutoff = divisor // lower_p
        non_divisors = []
        for sub_divisor in range(2, cutoff + 1):
            if any(sub_divisor % non_divisor == 0 for non_divisor in non_divisors):
                continue
            quotient, remainder = gmpy2.c_divmod(divisor, sub_divisor)
            if remainder == 0 and lower_p <= quotient < upper_p:
                return quotient
            if quotient < lower_p:
                break
            if remainder != 0:
                non_divisors.append(sub_divisor)

def is_correct(x1, x2, l, p_prime):
    p_prime_is_good = p_prime >> (l**2 - 1) and not p_prime >> l ** 2
    x1_is_good = (x1 % p_prime) >> (l-1) and not (x1 % p_prime) >> l
    x2_is_good = (x2 % p_prime) >> (l-1) and not (x2 % p_prime) >> l
    return bool(p_prime_is_good and x1_is_good and x2_is_good)

if __name__ == '__main__':
    seed(0)

    l = int(argv[1])
    reps = int(argv[2])

    def randbits(bits):
        return randrange(2 ** (bits - 1), 2 ** bits)

    for _ in range(reps):
        p = randbits(l ** 2)
        print("p = ", p)
        xs = []
        for i in range(2):
            q_i = randbits(l ** 3)
            print("q", i, "=", q_i)
            r_i = randbits(l)
            print("r", i, "=", r_i)
            x_i = q_i * p + r_i
            print("x", i, "=", x_i)
            xs.append(x_i)

        res = solve(xs, l)
        print("answer = ", res)
        print("Correct?", is_correct(xs[0], xs[1], l, res))

This code is based on the fact that the product of x1 - r for all possible values of r must be a multiple of p, and the product of x2 - r must be as well. Most of the time is spent taking the gcd of the two products, each of which has about 60,000,000 bits. The gcd, which only has about 250,000 bits, is then compared to each of the x-r values once again, to extract p' candidates. If they're a bit too large, trial division is used to reduce them to the appropriate range.
This is based on the gmpy2 library for Python, which is a thin wrapper for the GNU MP library, which in particular has a really good gcd routine.
This code is single-threaded.

Mathematica, L=12
ClearAll[l, a, b, k, m];
(l = #3;
a = #1 - Range[2^(l - 1), 2^l];
b = #2 - Range[2^(l - 1), 2^l];
k = Length@a;
m = Length@b;
For[i = 1, i <= k, i++,
For[j = 1, j <= m, j++, If[2^(l^2 - 1) < GCD[a[[i]], b[[j]]],
 If[GCD[a[[i]], b[[j]]] > 2^l^2,
  Print@Max@
    Select[Divisors[GCD[a[[i]], b[[j]]]],
     2^(l^2 - 1) < # < 2^l^2 &]; Abort[],
  Print[GCD[a[[i]], b[[j]]]];
  Abort[]]]]]) &

input
[x1,x2,L]
in order that anybody can test this, here is the key generator
l = 12;
a = RandomInteger[{2^(l^2 - 1), 2^(l^2)}]
b = RandomInteger[{2^(l^3 - 1), 2^(l^3)}];
c = RandomInteger[{2^(l - 1), 2^l - 1}];
f = RandomInteger[{2^(l^3 - 1), 2^(l^3)}];
g = RandomInteger[{2^(l - 1), 2^l - 1}];
x = a*b + c
y = a*f + g

choose the L value, run the code and you will get three numbers.
place the last two along with L as input, and you should get the first one

When I tested this with l = 12, it gave an incorrect result. Specifically, the resulting divisor was a 146-bit number, which is too large. I think you'll only need a small change to fix this.

I added the failing case as the final example above. Your solver gave an answer equal to 3*p, which was a little bit too big. Looking at your code, it looks like you only check that your output has at least l^2 bits, but you also need to check that it has at most l^2 bits.

On the same test case that it failed before, it's still not working. I'm not super familiar with Mathematica, but it looked like it exited with no output. I think the problem is that it's finding a factor that's too large, and then instead of finding a divisor of the factor in the desired range, it's just skipping past it.

Let us continue this discussion in chat.

Official score is L=12, with an average time of 52.7s. Well done!

haha ok! thanks again for everything!


text:
Straddling Checkerboard Cipher
The Straddling Checkerboard is a method for converting letters to numbers and was part of a pencil an paper cipher known as VIC
To convert letters to numbers first you have to make a checkboard like this:
    0   1   2   3   4   5   6   7   8   9
   ---------------------------------------
    E   T       A   O   N       R   I   S
2 | B   C   D   F   G   H   J   K   L   M
6 | P   Q   #   U   V   W   X   Y   Z   .

Is a 10 x 3 table filled with 28 different simbols and two blanks on the first row.
The labels of second and third row are the position of the blanks on the first one.
To cipher a message you have to replace each letter with the column label.
If it is not on the first row, prepend row label:
G -> 24
O -> 4
L -> 28
F -> 23

The extra simbols # and . are used to escape numbers and to indicate full-stop.
Task
Input:

0 to 26 unsorted unique letters (key)
4 digits, #1 != #2 and #3 != #4
Alphanumeric message to be encoded

Output:

Digits representing the encoded message

Implementation:
The table will be filled with the 26 character recived by input. If lengh is less than 26, the remaining spaces will be filled with the missing letters in alphabetical order.
The first two integers represent the blank spaces on the first row (and labels for second and third row).Next two integers represent the position of # and . on the third row.

Example:
Input: codeglf , 4 6 8 9 , "programming puzzles are gr8."
Yields this table:
   0 1 2 3 4 5 6 7 8 9
   -------------------
   c o d e   g   l f a
4| b h i j k m n p q r
6| s t u v w x y z # .

Output: 47491549945454246547727777637094935496886869

Note1: Spaces are not encoded and not included in the output.
Note2: Original message may contain letters, numbers, spaces and . (assume same capitalisation as the key)
Note3: If there is a number in the original message you have to output the corresponding code number for # followed by the number then another # code (68 in the example) and then continue with the letters.

Example2:
Input: toearly , 2 8 6 1 , "wake up at 06.am"
   0 1 2 3 4 5 6 7 8 9
   -------------------
   t o   e a r l y   b
2| c d f g h i j k m n
8| p . q s u v # w x z

w  a  k e  u  p a t  # 0 6  #  . a  m
87 4 27 3 84 80 4 0 86 0 6 86 81 4 28

Output: 87427384804086068681428

This is the complete VIC cipher question.

In the example . is encoded as 69

Under "Implementation", it might be worth reiterating that the first 2 integers are also used as the row labels. Also, it looks like you might be missing the gr before the 8 from your output, if I'm reading it right.

It looks to me like your output is wrong. It decodes into 'programmingpldllllvlcaregr8.'

The first half is encoded with 4 7 8 9 but the last half uses 4 6 8 9.

PHP>=7.1, 226 Bytes
for([,$c,$a,$b,$d,$e,$t]=$argv,$c.=join(preg_grep("#[^$c]#",range(a,z)));$p<30;)$x[in_array($y=["",$a,$b][$p/10].$p++%10,[$a,$b,$b.$d,$b.$e])?"__#."[$m++]:$c[$i++]]=$y;for(;a&$w=$t[$k++];)echo is_numeric($w)?$x["#"].$w:$x[$w];

Online Version
Expanded
for([,$c,$a,$b,$d,$e,$t]=$argv #short variables in input array
,$c.=join(preg_grep("#[^$c]#",range(a,z))) # join the rest of alphabet
;$p<30;) # loop 30 times
  $x[in_array($y=["",$a,$b][$p/10].$p++%10 # is actual position reserved?
  ,[$a,$b,$b.$d,$b.$e]) # reserved positions
    ?"__#."[$m++] # set reserved positions with chars underscore instead spaces to avoid encoding
    :$c[$i++]] # set alpabetic characters
  =$y; # make encoding array
for(;a&$w=$t[$k++];) # loop through string which shall be encoded
  echo is_numeric($w)
    ?$x["#"].$w # printing for digits
    :$x[$w]; #printing for the other characters

JavaScript (ES6), 236 bytes
(k,s,t,h,d,m)=>m.replace(/./g,c=>1/c?c>' '?''+t+h+c:'':(c=a.indexOf(c))>9?''+(c>19?t:s)+c%10:c,l=[...'zyxwvutsrqponmlkjihgfedcba'].filter(c=>k.search(c)<0),i=0,a=[...Array(30)].map((_,n)=>n-s&&n-t&&n-h-20?n-d-20?k[i++]||l.pop():'.':''))

Creates the checkboard a (except for the #, which is special-cased), then replaces letters and . in the message with the appropriately translated index while digits are prefixed with the code for #.

R, 286 281 261 bytes

Bit horrible looking and I am sure there is room for improvement, but I wanted to make sure I was doing it correctly before really getting into it.
Have changed it a bit to use 2 arrays and handle the numbers differently.  Hopefully this makes it easier to golf.
Implemented as an unnamed function that take 4 parameters
 - k the key for the table
 - x a vector containing the row name integers
 - y a vector containing the "#",'.' locations
 - s the string to encode
function(k,x,y,s){W=which
S=strsplit
P=paste0
L=letters
m=rep(NA,40)
m[c(1:10,x+11,y+31)]=c(0:9,'','','#','.')
m[is.na(m)]=c(d<-el(S(k,'')),L[-W(L%in%d)])
i=t(outer(c(P(x[2],y[1]),'',x),0:9,P));cat(sapply(el(S(gsub(' ','',s),'')),function(x)i[W(m==x)]),sep='')}

Try it online!
I have loaded the library methods in TIO example to get el() to work, however this is not required on my version of R.

source: Stack Exchange

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

sort: votes


text:
Buzzby Berkeley Robot Hokey Pokey
Buzzby Berkeley Robot Hokey Pokey
Task
Write a program or function to produce an ASCII art animation depicting a line of robots dancing to the lyrics of the Hokey Pokey (or Cokey, if you prefer) in the style of a Busby Berkeley number!
Example Output

Input
Accepts three arguments (assumed to be valid):
N = number of robots in the line (Min=6)
B = duration of one "beat" in milliseconds (Min=10)
D = delay in ms between successive robots (Min=0)
(In the example output above: N=8, B=380, C=75)
Specifications

N robots are shown in a row upon a stage.
One line of text from "the verse" is shown at a time beneath the stage (centred to within 1 character, and enclosed in quotation marks.)
The robots perform the actions for each line as it is shown until the verse has been repeated 5 times.
An action is performed by depicting a robot using a set of ASCII characters and waiting a specified duration before performing the next action. The duration of an action is measured in "beats". The duration of 1 beat is a number of milliseconds, B.
The first robot starts performing the actions for each line of verse immediately when the line's text is displayed.
Each subsequent robot delays starting its actions until a specific time (D) after the robot to its right (your left!) begins its actions.
Robots' depictions vary by the ASCII characters which represent a robot's "antenna", of which there are 5 possible types, distributed randomly every time the program is run.
Each type of antenna must be used by at least one robot, but the same type must not appear on any robots separated by fewer than 3 other robots.  The amounts of any two types of antennae may differ by no more than 1 (e.g. 1xType_4 and 3xType_5's is illegal since 3-1>1 )

Verse and Actions
The whole verse is repeated 5 times, 1 line at  a time...
Line  Text                            Action/Beats,
----  -----------------------------   ------------------------------------
1     You put your ? in               ??/4
2     You take your ? out             AA/4
3     You put your ? in               ??/4
4     And you shake it all about      AA/1, ??/1, AA/1, ??/1
5     You do the Hokey Pokey and...
      ...you turn yourself around     AA/1, H[1-7]/1
6     That's what it's all about!     AA/4, ZZ/4

For each repetition (R) of the verse, substitute ? and ??...
R   ?=           ??=
--  -----------  ---
1.  right foot   RF
2.  left foot    LF
3.  right hand   RH
4.  left hand    LH
5.  whole self   WS

Actions and ASCII patterns
Each labelled action is represented by 5 lines of 8 ASCII symbols.
The representation of each action is as follows...
1 |   12     12        12    12        12     12      12
2 |  ['']   ['']      ['']  ['']      ['']   ['']   \[*-]
3 | └[__]┘ └[__]┘    └[__]┘┌[__]┘    └[__]┐ ┌[__]┐   [__]\
4 |   ||     /<        >\    <\        />    /  \     /|
5 |--------------------------------------------------------
  |\__AA__/\__RF__/\__LF__/\__RH__/\__LH__/\__WS__/\__ZZ__/

1 |   12     12_     34_      34      _34     _12     12
2 |  ['']    [" ]    [ _]    [__]    [_ ]    [ "]    ['']
3 | >[__]<   [_<]    [<.]   <[..]>   [.>]    [>_]   <[__]>
4 |   ||      |\      ||      /|      ||      |\      ||
5 |--------------------------------------------------------
  |\__H1__/\__H2__/\__H3__/\__H4__/\__H5__/\__H6__/\__H7__/

In row 1, replace "1-4" with corresponding symbol for each antenna type...
1 | 1234 1234 1234 1234 1234
  | \/\/ |┌┐| )||( |||| ┐/\┌ <-- Symbols 1-4 for...
  | 1    2    3    4    5    <-- ...antenna types 1-5

Output
The entire scene must be rendered at least once immediately whenever the content of the scene changes in any way. (I.e. assuming the delay between robots' actions is > 0, the output may be rendered no less than N times per action.)
Ideally, for an animation the console or equivalent output area is cleared before each update is rendered.  To provide for languages unable to clear the console, output may also be rendered in a continuous stream, subject to the same requirement described above.
Scoring
Winners are the shortest programs in each language, as well as the shortest overall.
Exception 1 Because clearing the console each render is preferable though not required, bytes used exclusively for this luxurious purpose do not count towards the total bytes. This includes commands to clear the console, and padding output with blank lines to scroll the console contents out of view.
Exception 2 CSS or effectively similar means used exclusively for the purpose of styling the output beyond the minimum requirements do not count towards the total bytes.  E.g. *{color:blue;text-align:center;} counts as only 32-10=22 bytes since color:blue; doesn't serve to satisfy any specification, whereas centred text is specified.
Meta
Inspired by (showing my age) the TRS-80 Dancing Demon, Android Nim, and of course Busby Berkeley (and no, I'm not that old).

Great... last thing I need before I am already tired is a challenge to grab my attention. Are the tags on the top necessary?

@Matt, well the whole challenge isn't strictly "necessary", but I've removed the duplicate tags. ;-)

I've removed the maximum limit for input parameter 'D'. It was "D < B/N" to make sure each robot down the line had at least started the action while the first robot was still performing it (to avoid too much chaos), but by error, my own example broke that rule, and it seems to look okay anyway so I've removed the max delay limit. Apologies for that late change.

I've updated the section on scoring CSS and the like.

That is the most adorable thing I've ever seen.

Ladies and Gentlemen, please welcome our lovely
Full Frontend-Stack Dance Group, 1,320 1,378 1,425 1,495 bytes
JavaScript: 1,195 bytes | CSS: 103 bytes | HTML: 22 bytes

This is a cute challenge. It also has lots of special cases. Oh boy, so many special cases. And those antennas …
It will run forever and restart after all actions (left foot, right foot etc.) are completed.
You can try it on jsFiddle or by using the code snippet thingy below:

t=setTimeout
c=l=a=i=0
_=(x,y,z)=>{if(!i)for(;++i<=x;q=~~(Math.random()*10))s.append(document.createElement('pre'))
for(i=l=0,c=a+1;i<33;)(i=>{t($=>{if(4==i){c=0
l=1}if(8==i){c=a+1
l=0}if(12==i|14==i){c=0
l=2}if(13==i|15==i)c=a+1
if(16==i){c=0
l=3}if(16i)c=i-10
if(24==i){c=0
l=4}if(28==i)c=6
if(31<i){a=++a%5
_(x,y,z)}for(j=0;j<x;)(j=>{t($=>s.childNodes[j][h]=(-1<[1,3,8,9].indexOf(c)?'  ':2==c||4==c?'    ' :'   ')+(11==c||12==c?'_':'')+['\\/\\/','|┌┐|',')||(','||||','┐/\\┌'][(q+j)%4].substring($=8<c&12>c?2:0,$+2)+(8==c||9==c?'_':'')+'\n'+[`  ['']
 └[__]┘
   ||`,` ['']
└[__]┘
  /<`,`   ['']
  └[__]┘
    >\\`,` ['']
┌[__]┘
  <\\`,`   ['']
  └[__]┐
    />`,`  ['']
 ┌[__]┐
  /  \\`,` \\[*-]
  [__]\\
   <\\`,`  ['']
 >[__]<
   ||`,`  [" ]
  [_<]
   |\\`,`  [ _]
  [<.]
   ||`,`  [__]
 <[..]>
   /|`,`  [_ ]
  [.>]
   ||`,`  [ "]
  [>_]
   |\\`,`  ['']
 <[__]>
   ||`][c]+'\n-------',j*z)})(j++)
p[h='innerText']='"'+["You put your $ in","You take your $ out","And you shake it all about","You do the Hokey Pokey and you turn yourself around","That's what it's all about!"][l].replace('$',['right foot','left foot','right hand','left hand','whole self'][a])+'"'},i*y)})(i++)}

// let's dance (not included in the byte count – as if it would make any difference)
_(8, 400, 50)
*{text-align:center}x pre{display:inline-block;width:55px;text-align:left}pre{line-height:16px;margin:0
<x id=s></x>

Tested in Chrome and Firefox on macOS, Windows 10 and Ubuntu

Edits

Saved 70 bytes by removing the extra container to hold the antennas. Thanks to Bumpy. Also found some more whitespaces, removed the now unnecessary caching of createElement and removed the long access to .firstChild.
Saved 47 bytes – just realized that I actually don't need to call getElementById. This also makes the caching of document unnecessary.
Saved 4 bytes by replacing || and && with bitwise & and |. Thanks to TheLethalCoder.
Saved 54 bytes by simplifying lots of small things and by optimizing the CSS.

Bravo!!!  The Full Frontend-Stack Dance Group's a hit!!  Apologies for the amount of special cases; I chose the antennae combinations specifically to frustrate, but the rest of the symbols were all in service of the animation - I didn't plan it to be SO fiddly. Now, I feel churlish criticising such a brilliant performance, but I think the underscores/antenna are slightly out of whack when they turn around (1 character too far to the left, possibly?)   But whatever - it's great!  Thanks for taking up my challenge!

@Bumpy Thanks. You're right, I mixed up some magic numbers. The antennas are now perfectly in order. I also managed to get the same line-height for all figures. Really  a fun challenge.

Thanks again, and for your final comment; I'm so glad it amused someone :-)  I made a naive implementation just to get the animation, but we took very different approaches to rendering (just 1 element
, then ```O.innerHTML=o````) which your proggy could easily do to save tonnes, and I wouldn't count the CSS anyway (I'll update the question to say so, thx.)  But I haven't pondered much on how I'd compress the rest, so it's interesting to see how other people tackle the problem you've set.  Thanks again!

@Bumpy Of course, I added the antennas to the actual elements and saved a whole lot of bytes. Thanks. I was writing the original around 2 o'clock in the morning and I totally overlooked the simplicity.

Fiddling with dancing robots at 2 o'clock you say? Wonderful, bwahaha!

|| and && to | and &?

@TheLethalCoder Absolutely. Your suggestion is already in the source and reflected in the edits. Thanks a lot.

C#, 1188 1376 1382 bytes after exceptions
Compacted:
namespace System.Threading{using S=String;void H(int n,int b,int d){Console.CursorVisible=false;int t,u=0,v=5,w,x,y,z;S[]i=",That's what it's all about!,,You do the Hokey Pokey and you turn yourself around,And you shake it all about,,You take? out,You put? in".Split(',');i[0]=i[1];i[2]=i[3];i[5]=i[7];for(b=b<d*n?0:b-d*n;v-->0;)for(w=32;w-->0;Thread.Sleep(b))for(t=u,z=0;z++<n;Thread.Sleep(d)){S s="",r=i[w/4].Replace("?"," your "+(v<1?"whole self":(v%2<1?"right ":"left ")+(v/3<1?"hand":"foot")));u="88880000765432109090999900009999"[w];u=u>56?9+v:u-48;for(y=4;y-->0;s+="\n")for(x=0;x<n;x++)s+=S.Format(@"{0}{0}   |\   {0}   /|   {0}   |\   {0}   /|{4} /  \{4}  />{4}<\{4}{4}>\{4}/<{4} └{1}┘  >{1}<   [_<]{4}[<.]   <[..]>   [.>]{4}[>_]   <{1}>   {1}\  ┌{1}┐   └{1}┐┌{1}┘{4}└{1}┘└{1}┘   {2}  {2}   ["" ]{4}[ _]{4}{1}{4}[_ ]{4}[ ""]   {2}  \[*-]   {2}   {2}{2}{4}{2}{2}  {3}{3}  12_{4} 34_{4}  34{4}  _34{4} _12  {3}{3}{3} {3} 12{4} {3} 12{4}", "   ||   ","[__]"," [''] ","   12   ","    ").Substring(y*14+(x<z?u:t)<<3,8).Replace("12",@"\/|┌)|||┐/".Substring(x%5*2,2)).Replace("34",@"\/┐||(||\┌".Substring(x%5*2,2));Console.Clear();Console.Write(s+new S('-',n*8)+"\n"+new S(' ',n*4-r.Length/2)+r);}}}

Slightly nicer formatting and wrapped in an executable program:
namespace System.Threading{
    using S=String;

    //** Not counted towards score: execution wrapper
    class P{
        static void Main(S[]a){
            new P().H(int.Parse(a[0]),int.Parse(a[1]),int.Parse(a[2]));
        }
    //** End not counted towards score

        void H(int n,int b,int d){
            Console.CursorVisible=false;  // Not counted under exception 2
            int t,u=0,v=5,w,x,y,z;
            S[]i=",That's what it's all about!,,You do the Hokey Pokey and you turn yourself around,And you shake it all about,,You take? out,You put? in".Split(',');
            i[0]=i[1];
            i[2]=i[3];
            i[5]=i[7];
            for(b=b<d*n?0:b-d*n;v-->0;)
                for(w=32;w-->0;Thread.Sleep(b))
                    for(t=u,z=0;z++<n;Thread.Sleep(d)){
                        S s="",r=i[w/4].Replace("?"," your "+(v<1?"whole self":(v%2<1?"right ":"left ")+(v/3<1?"hand":"foot")));
                        u="88880000765432109090999900009999"[w];
                        u=u>56?9+v:u-48;
                        for(y=4;y-->0;s+="\n")
                            for(x=0;x<n;x++)
                                s+=S.Format(@"{0}{0}   |\   {0}   /|   {0}   |\   {0}   /|{4} /  \{4}  />{4}<\{4}{4}>\{4}/<{4} └{1}┘  >{1}<   [_<]{4}[<.]   <[..]>   [.>]{4}[>_]   <{1}>   {1}\  ┌{1}┐   └{1}┐┌{1}┘{4}└{1}┘└{1}┘   {2}  {2}   ["" ]{4}[ _]{4}{1}{4}[_ ]{4}[ ""]   {2}  \[*-]   {2}   {2}{2}{4}{2}{2}  {3}{3}  12_{4} 34_{4}  34{4}  _34{4} _12  {3}{3}{3} {3} 12{4} {3} 12{4}", "   ||   ","[__]"," [''] ","   12   ","    ").Substring(y*14+(x<z?u:t)<<3,8).Replace("12",@"\/|┌)|||┐/".Substring(x%5*2,2)).Replace("34",@"\/┐||(||\┌".Substring(x%5*2,2));
                        Console.Clear(); // Not counted under exception 1
                        Console.Write(s+new S('-',n*8)+"\n"+new S(' ',n*4-r.Length/2)+r);
                    }
        }
    } // Not counted towards score: end class
}

Try it online!

Visit this link: tutorialspoint.com
In the Default Term tab at the bottom of the screen, type:
mono main.exe 8 400 40

Edit 1
Replaced string.Format(i,j) with i.Replace("?",j) saving 6 bytes overall.
Edit 2
Complete revamp with suggestions from the comments.

Yay! Is there an easy way to run it online somewhere?

@Bumpy, added a link in the answer!

Convert to an anonymous function to save a lot of bytes i.e. Action<int, int, int> or similar. Some of the verbatim strings are unnecessary. creating an array from splitting a string is usually shorter than the array itself. Use Console.Clear() as you said yourself this is [tag:code-golf].

Really nice solution. You encouraged me to golf off a few more bytes off of my answer. Maybe you find room to get rid of another 57 bytes. :)

@insertusernamehere By compiling to a anonymous function and some minor golfing I've got it to under 1300.

I think you should be able to remove c but I can't see how at the moment. You should also be able to declare i inline if you can combine the same lines together, or work out the index easier.

Compile to an Action<int, int, int> to save more bytes. "".PadLeft(count) is usually shorter than new string. I'm not sure if there's anything else.

@insertusernamehere, done!  Your turn!  :-D

@TheLethalCoder, thanks for that!  I got rid of c for a small saving.  I knew I'd forgotten a better way than new string(c,n).  However, now that I've aliased S=String, new S(c,n) is shorter still.

JavaScript, 948 bytes
Probably poor form to answer your own question, but anyway...
Tried all sorts of ways to compress the text, but most ended up longer than the original with the key+algorithm included. I'm certain there's still a more optimal way to compress it all down, but I have to draw the line somewhere.
Interestingly, the search yielded one or two ideas for some other challenges which I might refine and post later.

f=(N,B,D)=>{Q=c=>(K={},k='~',[...c].map(v=>v<k?K[k=v]='':K[k]+=K[v]||v),K[k])
x=``,A=`//,||,)||(,,/`.split(',').sort(new Date)
r=new Array(N).fill(0),t=i=v=0,n=`\n`,T=setTimeout
C=_=>(w=Q(`ouhand t t's ake Y y all abtokey righlefwhole fooself ,${v+1},,1yr ${x[v*2]+x[v*2+1]}puintt,,Ashi,do the HPaturn yrarnd,,7,8,90123,Twi!,,6,`).split(',')[i++])<'A'?(r.map((_,m)=>T((a,b)=>R(r[N-a]=b),m*D,m,w)),i>22?(v++,i=0):0,v<3?T(C,B*(i<7||i>21?4:1)):0):C(t=w),R=_=>{for(o='',m=4;m--;o+=n){for(w=N;w--;)o+=Q(`┌┐└┘\\/||/${A[w%5]}   [__] [''] ||] _ __ _  [*-][" ][ _][_ ][ "] ┐ ┐><[_<] [<.]<[..]>[.>] [>_]<> /<></>/ //`).substr(r[w]*8+(3-m)*112,8)}
O.innerHTML=o+'-'.repeat(N*8)+' '.repeat(((N*8)-t.length)/2)+t}
C()}

(NB: Contains some characters in the range 1-31 whose representations are a bit odd when posted here)
Watch the full psychedelic dance cycle on CodePen!

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


text:
Better Hex Color Codes for Your Internet
Hex triplets such as #ffffff (white) or #3764ef (blueish) are often used to denote RGB colors. They consist of # followed by six hexadecimal digits (0-f), or sometimes three digits where the real color is obtained by doubling each digit. For example, #fff is #ffffff and #1a8 is #11aa88.
Sadly, that three digit shorthand was the golfiest the internet had to offer, until now.
Write a program or function that takes in a string of 1 to 7 characters:

The first character will always be #.
The other characters will always be hexadecimal digits: 0123456789abcdef.

The input is a shorthand form of a hex triplet (or the full form if 7 characters are given).
You need to output a full hex triplet that expands the input shorthand based on these patterns:
Input   -> Output
#       -> #000000    (black)
#U      -> #UUUUUU
#UV     -> #UVUVUV
#UVW    -> #UUVVWW    (usual 3-digit shorthand)
#UVWX   -> #UXVXWX
#UVWXY  -> #UVWXYY
#UVWXYZ -> #UVWXYZ    (not shorthand)

Each of U, V, W, X, Y, and Z may be any hexadecimal digit. The output is always 7 characters.
For example:
Input -> Output
# -> #000000
#0 -> #000000
#4 -> #444444
#f -> #ffffff
#a1 -> #a1a1a1
#0f -> #0f0f0f
#99 -> #999999
#1a8 -> #11aa88
#223 -> #222233
#fff -> #ffffff
#1230 -> #102030
#d767 -> #d77767
#bbb5 -> #b5b5b5
#aabbc -> #aabbcc
#00000 -> #000000
#3764e -> #3764ee
#3764ef -> #3764ef
#123456 -> #123456
#f8f8f8 -> #f8f8f8

Notes

The input will always start with # and so must the output.
You may assume all input letters are lowercase (abcdef) or uppercase (ABCDEF) as you prefer.
Letters in the output may be in either case as you prefer. You can even mix cases.
Alpha/transparency is not dealt with here (though there are hex versions of RGBA colors).

The shortest code in bytes wins.

"Sadly, that three digit shorthand was the golfiest the internet had to offer, until now." - Uh, not exactly. HTML, 0 bytes - it works out of the box

The reverse of this would be a cool challenge too

I am unsatisfied with the #UVWXY  -> #UVWXYY entry because it allows for a single-value representation for the Blue channel, but there's no similar expression for Red and Green (e.g. if I wanted #889071 I can't abbreviate, but #907188 can be...as #90718) the others all work great.

@Draco18s I love it. That one and the #UVWX   -> #UXVXWX. It's such an inconsistent and arbitrary behaviour that it's hard to believe there isn't a couple of browser that actually currently implement it.

@xDaizu CSS specification has #RGBA and #RRGGBBAA, so #1234 should be read as rgba(17, 34, 51, 0.25)

@tsh Boy oh boy, conflicting interpretations? In HTML/CSS? Loving it more and more!

@xDaizu it's hard to believe there isn't a couple of browsers that actually currently implement it Ha! Point to you sir. (I do like #UVWX -> #UXVXWX though, that's clever).

@Draco18s The 5-digit one is weird but I'm not sure there's a nice way to make it symmetric, except for awkward stuff like #U(X+Y)V(X+Y)W(X+Y).

Oh agreed, I was just voicing my displeasure. More at the fact that there isn't a good solution rather than your particular one.

#UVWXYY makes sense because blue is the color that looks the darkest, and has the least effect on the output. It's also pretty common to store colors in 16 bits with 6 bits for green and 5 each for red and blue.

JavaScript, 86 82 77 bytes
x=>([s,a=0,b=a,c,d,e,f]=x,f?x:e?x+e:[s,a,d||a,c?b:a,d||b,v=c||b,d||v].join``)

just find out that remove recursive save 4 bytes...
idea from @Arnauld save 4 bytes, +1 more bytes

([s,a=0,b=a,c,d,e,f]=x)=>f?x:e?x+e:d?s+a+d+b+d+c+d:c?s+a+a+b+b+c+c:s+a+a+a+b+b+b for 80 bytes

@Luke I just got ReferenceError: x is not defined

Jelly, 24 bytes

x2
j0ị$
m0

0
Ḣ;LĿṁ6$$

A full program (the empty lines are actually empty lines).
Try it online! or see a test suite*
How?
     - Link 1 (0 bytes), returns its input (e.g. "U" -> "U")
     - Link 2 (0 bytes), returns its input (e.g. "UV" -> "UV")
x2   - Link 3, doubles up (e.g. "UVW" -> "UUVVWW")
j0ị$ - Link 4, joins with final element (e.g. "UVWX" -> "UXVXWXX")
m0   - Link 5, reflects its input (e.g. "UVWXY" -> "UVWXYYXWVU")
     - Link 6 (0 bytes), returns its input (e.g. "UVWXYZ" -> "UVWXYX")
0    - Link 7, returns zero (link 7 is also link 0 since there are 7 links)
Ḣ;LĿṁ6$$ - Main link: string
Ḣ        - head (get the '#')
       $ - last two links as a monad:
   Ŀ     -   call link at index:
  L      -     length
      $  -   last two links as a monad:
    ṁ6   -     mould like 6 (e.g. "UVWXYYXWVU" -> "UVWXYY"
         -                    or  "UV" -> "UVUVUV")
 ;       - concatenate (prepend the '#' again)
         - implicit print

* the test-suite program had to be altered by swapping the order of what were the Main link and Link 7, while the footer became the Main Link. Furthermore the # had to be manually replaced, since the program as-is heads it.

CJam, 45  44  42 40 36 35 bytes
q(\0se|_,("6* 3* 2e* )f+ _W=+ "S/=~

Runs various code snippets based on the length of the input.

Some formatting not required.... <s></s>

@SteveFest But crossed out 44 is still regular 44...

Aw! You got me! I forgot that!

PHP 7.1, 88 bytes
#<?for(;$i<6;)echo@$argn[_22222232532233423355224462[5*$i+++strlen($argn|aa)*.85]-1]?:0;

PHP 5, 90 88 bytes
#<?for(;$i<6;)echo$argn[_10311001122011333002244012345[6*$i+++strlen($argn|aa)-8]+1]?:0;

I have no Idea how you get this idea but it works. Work _21422112233122444113355123456[6*$i+++strlen($argn|aa)-8] ?

could you please explain how this works?

This one is nice ! It stores the offset in $argn in 21422112233122444113355123456and selects the correct one based on strlen. aa pads the string to at least 2 chars. On input # there is no $argn[1] so ?:0 outputs a 0. This also works for on 0 in the string. One of the best answers I've seen! Sadly it doesn't pay of too much (got Jörg's answer golfed down to 95).

Haha, this is the best abuse of PHP's automatic strings I've seen in a while. +1

@JörgHülsermann It works, but the digits have to be decreased by 1 and then changed back. Otherwise _ would lead to zero index.

Sadly your latest version (while having an awesome trick again!) results in a warning which does get printed by PHP (and therefore results in the wrong output). Usally we need surpress it with @. Your second version sadly fails for everything I tested.

@Christoph The second version seems to work (PHP 5.6.29). As far as I understand, STDERR is allowed to be ignored.

PHP doesn't print errors to stderr on default but rather to stdout. ini_set('display_errors','stderr'); can be used to change this since PHP 5.2.4. The second version not working for me might of course be a simple PHP version problem :)

@Christoph The Second version needs a PHP Version under 7.1 and a PHP Version over 5.6 I think add this should make this clearer

PHP, 95 93 89 87
<?=strtr(_1.intval([a6n,sot,c8c,lba,vf1,vf2][strlen($argn|aa)-2],33),_134256,$argn.=0);

Basically @JörgHülsermann's answer but greatly golfed down so I decided to post it as a seperate answer. I'd count this answer as an collective effort of me and Jörg.
-4 bytes thanks to @JörgHülsermann
-1 bytes thanks to @JörgHülsermann's base 33 numbers

Java 10, 228 227 224 182 bytes
s->{var x="$1$1";int l=s.length();return l>6?s:l>5?s+s.charAt(5):l<2?"#000000":s.replaceAll(l>4?"(.)(.)(.)(.)$":l==3?"([^#]{2})":"([^#])",l>4?"$1$4$2$4$3$4":l>3?x:l>2?x+"$1":x+x+x);}

Try it online.
Explanation:
s->{                      // Method with String as both parameter and return-type
  var x="$1$1";         //  Create a temp String to repeat a match
  int l=s.length();     //  Length of the String
  return l>6?           //  If the length is 7:
    s                   //   Return the input-String as is
   :l>5?                //  Else-if the length is 6:
    s+s.charAt(5)       //   Return the input-String with the last character repeated
   :l<2?                //  Else-if the length is 1:
    "#000000";          //   Simply return the literal String #000000
   :                    //  Else (the length is 2, 3, 4, or 5):
    s.replaceAll(       //   Return the input-String after a regex replace:
                        //    With as match:
     l>4?               //     If the length is 5:
      "(.)(.)(.)(.)$",  //      Use a match for pattern #(A)(B)(C)(D)
     :l==3?             //     Else-if the length is 3:
      "([^#]{2})"       //      Use a match for pattern #(AB)
     :                  //     Else (the length is 2 or 4):
      "([^#])",         //      Use a match for pattern #(A) or #(A)(B)(C)
                        //    And as replacement:
     l>4?               //     If the length is 5:
      "$1$4$2$4$3$4"    //      Change #ABCD to #ADBDCD
     :l>3?              //     Else-if the length is 4:
      x                 //      Change #ABC to #AABBCC
     :l>2?              //     Else-if the length is 3:
      x+"$1"            //      Change #AB to #ABABAB
     :                  //     Else (the length is 2):
      x+x+x);}          //      Change #A to #AAAAAA

Python 3, 166 162 160 152 bytes
import re
lambda x,d='(.)$',b=r'\1':re.sub(*[('$','0'*6),(d,b*6),('(..)$',b*3),('(\w)',b*2),('.'+'(.)'*4,r'#\1\4\2\4\3\4'),(d,b*2),('','')][len(x)-1],x)

I construct a list of regex replacement tuples for each pattern, and then extract the tuple at index len(x)-1, finally splatting (*) it into the arguments of re.sub:
lambda x, d='(.)$', b=r'\1':   # lambda expression, save often used strings
  re.sub(   # regex replacement of:
         *  # expand what follows into arguments, i.e. f(*(1,2)) -> f(1,2)
         [  # list of replacement patterns:
            # 1 character: replace the end with 6 zeroes
            ('$', '0'*6),
            # 2 chars: repeat the last character 6 times
            (d, b*6),
            # 3 chars: repeat the two non-#s 3 times.
            ('(..)$', b*3),
            # 4 chars: replace every non-# with twice itself
            ('(\w)', b*2),
            # 5 chars: has to be somewhat verbose..
            ('.'+'(.)'*4, r'#\1\4\2\4\3\4'),
            # 6 chars: repeat the last character
            (d, b*2),
            # 7 chars: complete already, replace nothing with nothing
            ('', '')
         ][len(x)-1], # select the element from the list that has the right length
        x)  # replace in argument x

saved 8 bytes by memorizing r'\1' (thanks, Gábor Fekete)

Wouldn't using r'\1' as a named parameter save some bytes?

You wrote o=r'\1' but use b in your code :D

@GáborFekete Whoops :D

Haskell, 130 127 122 118 109 95 bytes (by user1472751)
y a|l<-[last a]=[y"0",y$a++a,a++a++a,do c<-a;[c,c],(:l)=<<init a,a++l,a]!!length a
f(h:r)=h:y r

Try it online!

There is a superfluous space behind g .

Also (x:r)!(y:t)=x:y:r!t;e!_=e is shorter than a!b=id=<<[[x,y]|(x,y)<-zip a b].

As the first char is always # you can do g(a:t)|l<-last t=a:[ ...

@Laikoni indeed, those are great improvements!

I found a 95 byte solution that uses a similar approach to yours (great minds think alike, huh?). You can use it or I can post a separate answer.

I replaced my solution with yours. It is much nicer!

PHP, 87 Bytes
use Base 35 Numbers

<?=strtr(_2.intval([i4w,qdi,j1y,apg,ruu,ruv][strlen($argn|aa)-2],35),_234156,$argn.=0);

Try it online!
or use Base 33 Numbers

<?=strtr(_1.intval([a6n,sot,c8c,lba,vf1,vf2][strlen($argn|aa)-2],33),_134256,$argn.=0);

Try it online!
PHP, 89 Bytes
<?=strtr(_1.[11111,21212,12233,42434,23455,23456][strlen($argn|aa)-2],_123456,$argn."0");

Try it online!
intval(["8kn",gd8,"9ft",wqq,i3j,i3k][strlen($argn|aa)-2],36) + 3 Bytes using a 36 Base
PHP, 102 Bytes
<?=strtr("01".substr("11111111112121212233424342345523456",5*strlen($argn)-5,5),str_split($argn."0"));

Try it online!
PHP, 180 Bytes
<?=[str_pad("#",7,($l=strlen($p=substr($argn,1)))?$p:0),"#$p[0]$p[0]$p[1]$p[1]$p[2]$p[2]","#$p[0]$p[3]$p[1]$p[3]$p[2]$p[3]","#$p[0]$p[1]$p[2]$p[3]$p[4]$p[4]",$argn][($l>2)*($l-2)];

Try it online!

I golfed down this version to 95 bytes but I thought it was to different so I posted it as an own answer. Hope you like it :)

@Christoph In the moment I am here with my version Try it online!

Base 33 is an awesome idea! I've been sitting here a while but didn't come up with it damn.

@Christoph it is very similar with your golfing of my first version. It was not easy to golf my approch under your approach

Saved another byte: $argn."0" to $argn.=0.

@Christoph Thanks and the base 35 Number system is my approach in our Teamwork

Sed, 119 (118 Bytes + -E)
s/#//
s/^$/0/
s/^.$/&&/
s/^..$/&&&/
s/^(.)(.)(.)$/\1\1\2\2\3\3/
s/^(.)(.)(.)(.)$/\1\4\2\4\3\4/
s/^....(.)$/&\1/
s/^/#/

Straightforward text substitution.

APL (Dyalog), 43 bytes
Requires ⎕IO←0 which is default on many systems.
'#',{6⍴(≢⍵)⊃'0'⍵ ⍵(2/⍵)(∊⍵,¨⊃⌽⍵)(⍵,⌽⍵)⍵}1↓⍞

Try it online!
1↓⍞ drop the first character (the hash)
{ apply the following anonymous function
 (≢⍵)⊃ use the length of the argument to pick one of the following seven values:
  '0' a zero
  ⍵ the argument
  ⍵ the argument
  2/⍵ two (2) of each (/) of the argument (⍵)
  ∊⍵,¨⊃⌽⍵ the flattened (∊) argument (⍵) followed each (,¨) by the first (⊃) of the reversed (⌽) argument (⍵)
  ⍵,⌽⍵ the argument (⍵) prepended (,) to the reversed (⌽) argument (⍵)
  ⍵ the argument
 6⍴ repeat elements from that until a length of six is achieved
} end of anonymous function
'#', prepend a hash to that

Python 2, 167 165 bytes
-2 bytes thanks to Trelzevir
z=zip
lambda s:'#'+''.join([reduce(lambda x,y:x+y,c)for c in['0'*6,s[1:2]*6,z(s[1:2],s[2:3])*3,z(*z(s[1:2],s[2:3],s[3:4]))*2,z(s[1:4],s[-1]*3),s+s[-1],s][len(s)-1]])

It creates a list of strings and chooses based on the length of the string.

You can save 2 bytes using z=zip.

Retina, 90 bytes
#(..)$
#$1$1$1
#(.)(.)(.)$
#$1$1$2$2$3
#(.)(.)(.(.))$
#$1$4$2$4$3
#$
#0
+`#.{0,4}(.)$
$&$1

Try it online! Includes test cases.
Explanation: The first translation handles two digits, the second one three, the third one four, and the fourth one zero. However, neither the second and fourth translations repeat the (last) digit, as that is done at the end anyway to cover all the remaining cases.

Powershell, 113 111 bytes
param($s)-join($s+='0'*($s-eq'#'))[0,1+((,1*5),(2,1*2+2),(1,2,2,3,3),(4,2,4,3,4),(2..5+5),(2..6))[$s.Length-2]]

Explaned test script:
$f = {

param($s)           # parameter string
$s+='0'*($s-eq'#')  # append '0' if $s equal to '#'
$i=(                # get indexes from array
    (,1*5),         # $i = 1,1,1,1,1 if $s.length-2 = 0
    (2,1*2+2),      # $i = 2,1,2,1,2 if $s.length-2 = 1
    (1,2,2,3,3),    # $i = 1,2,2,3,3 if $s.length-2 = 2
    (4,2,4,3,4),    # $i = 4,2,4,3,4 if $s.length-2 = 3
    (2..5+5),       # $i = 2,3,4,5,5 if $s.length-2 = 4
    (2..6)          # $i = 2,3,4,5,6 if $s.length-2 = 5
)[$s.Length-2]
-join$s[0,1+$i]     # join chars from $s by indexes 0, 1 and $i

}

@(
    , ("#", "#000000")
    , ("#0", "#000000")
    , ("#4", "#444444")
    , ("#f", "#ffffff")
    , ("#a1", "#a1a1a1")
    , ("#0f", "#0f0f0f")
    , ("#99", "#999999")
    , ("#1a8", "#11aa88")
    , ("#223", "#222233")
    , ("#fff", "#ffffff")
    , ("#1230", "#102030")
    , ("#d767", "#d77767")
    , ("#bbb5", "#b5b5b5")
    , ("#aabbc", "#aabbcc")
    , ("#00000", "#000000")
    , ("#3764e", "#3764ee")
    , ("#3764ef", "#3764ef")
    , ("#123456", "#123456")
    , ("#f8f8f8", "#f8f8f8")
) |% {
    $s, $e = $_
    $r = &$f $s
    "$($e-eq$r): $r"
}

Output:
True: #000000
True: #000000
True: #444444
True: #ffffff
True: #a1a1a1
True: #0f0f0f
True: #999999
True: #11aa88
True: #222233
True: #ffffff
True: #102030
True: #d77767
True: #b5b5b5
True: #aabbcc
True: #000000
True: #3764ee
True: #3764ef
True: #123456
True: #f8f8f8

Perl, 61 bytes
say+(/./g,0)[0,1,(unpack+S7,"g+g+ÜRÉ/Â¥[ [")[y/#//c]=~/./g]

Run with perl -nE. Assumes that the input is exactly as described (gives incorrect results if the input has a trailing newline).
The string "g+g+ÜRÉ/Â¥[ [" encodes the 7 16-bit numbers 11111,11111,21212,12233,42434,23455,23456 as 14 latin1 characters. Here’s a hexdump for clarity:
0000001d: 672b 672b dc52 c92f c2a5 9f5b a05b       g+g+.R./...[.[

I replaced the Latin-1 string with a call to pack(), and got: perl -nE 'say+(/./g,0)[0,1,(unpack+S7,pack "H*","672b672bdc52c92fc2a59f5ba05b")[y/#//c]=~/./g]' .  But when I type "#a", I get "#a0a0a0" which I think is wrong.  It should be "#aaaaaa".  (Maybe I made a mistake in the pack() call.)

This time I replaced the unpack() & pack() calls with the literal shorts, and got: perl -nE 'say+(/./g,0)[0,1,(11111,11111,21212,12233,42434,23455,23456)[y/#//c]=~/./g]'.  It still appears to be wrong, as "#a" still yields the incorrect answer of "#a0a0a0" (instead of "#aaaaaa").

Ah!  I figured it out!  I needed to use the -l switch (that's "ell" as in the "letter L") with the -nE switch, like this:  perl -lnE 'say+(/./g,0)[0,1,(11111,11111,21212,12233,42434,23455,23456)[y/#//c]=~/./g]' .  Now it works correctly.

The warning that says "(gives incorrect results if the input has a trailing newline)" can be eliminated by changing "Run with perl -nE" to "Run with perl -lnE".  (The -l part of the switch gets rid of the trailing newline for you.)

Using -F on the command line lets you change this to say+(@F,0)[0,1,(unpack+S7,"g+g+ÜRÉ/Â¥[ [")[$#F]=~/./g] saving 5 bytes in the code.

JavaScript (ES6), 96 bytes
s=>'#'+(c=[u,v,w,x,y,z]=s.slice(1)||'0',z?c:y?c+y:(x?u+x+v+x+w+x:w?u+u+v+v+w+w:c.repeat(v?3:6)))

f=
s=>'#'+(c=[u,v,w,x,y,z]=s.slice(1)||'0',z?c:y?c+y:(x?u+x+v+x+w+x:w?u+u+v+v+w+w:c.repeat(v?3:6)))

console.log(
  f('#'),
  f('#U'),
  f('#UV'),
  f('#UVW'),
  f('#UVWX'),
  f('#UVWXY'),
  f('#UVWXYZ')
)

Windows batch, 389 372 362 349 231 bytes
I totally copied @Neil code...
@call:c %s:~1,1% %s:~2,1% %s:~3,1% %s:~4,1% %s:~5,1% %s:~6,1%
@exit/b
:c
@for %%r in (#%1%2%3%4%5%6.%6 #%1%2%3%4%5%5.%5 #%1%4%2%4%3%4.%4 %s%%1%2%3.%3
%s%%1%2%1%2.%2 %s%%1%1%1%1%1.%1 #000000.0)do @if not %%~xr.==. @echo %%~nr&exit/b

replacing %s% with %1 should save you a few bytes.

%s:~3,1%%s:~4,1% can be replaced with %s:~3,2%. Also I'm not sure that this works for an input of #.

By the way, I tried a different algorithm, and it came out at 243 bytes.

May I know what's the algorithm?

(Sorry, I didn't see your comment due to a lack of @Neil.) There's some boilerplate but the two lines of interest are call:c %s:~1,1% %s:~2,1% %s:~3,1% %s:~4,1% %s:~5,1% %s:~6,1% and for %%r in (#%1%2%3%4%5%6.%6 #%1%2%3%4%5%5.%5 #%1%4%2%4%3%4.%4 %s%%1%2%3.%3 %s%%1%2%1%2.%2 %s%%1%1%1%1%1.%1 #000000.0)do if not %%~xr.==. echo %%~nr&exit/b.

@Neil Can the first one be golfed down to call:c %s~1,6%?

@SteveFest No, I want the 6 characters as separate %N variables.

@Neil Can I use exit instead of exit /b?

It will close your command prompt...

Does that matter? I thought we only needed the code working.

Pyth, 35 bytes
+\#@<R6[J|tQ\0K*6JKKs*R2JjeJJ+JeJ)l

Try it online here, or verify all test cases here.
+\#@<R6[J|tQ\0K*6JKKs*R2JjeJJ+JeJ)lQ   Implicit: Q=eval(input())
                                       Trailing Q inferred
          tQ                           Remove first char of input
         |  \0                         The above, or "0" if empty
        J                             *Store in J (also yields stored value)
              K*6J                    *Repeat J 6 times, store in K
                  KK                  *2 more copies of the above
                    s*R2J             *Duplicate each char of J in place
                         jeJJ         *Join chars of J on last char of J
                             +JeJ     *Append last char of J to J
       [                         )     Wrap the 5 starred results in an array
    <R6                                Trim each to length 6
   @                              lQ   Choose result at index of length of input
                                       (Modular indexing, so length 7 selects 0th element)
+\#                                    Prepend #, implicit print

Python 2, 99 bytes
def a(s):s=s[1:]or'0';l=len(s);print('#'+(l/4*s[-1]).join(i+i*(l==3)for i in(l<5)*6*s)+s+s[-1])[:7]

Try it online!

Nice first post. As an aside, Try it online! is an optional but recommended site that runs code to include in your answer. It can generate CG&CC posts and gives an accurate byte count to boot.

Very cool, thanks!

Python 2 - 179 bytes
n=raw_input()                                #prompts for string
t=len(n)                                     #the length of the string is stored to 't'
if t==1:n+="0"*6                             #if t is only one char long, it needs to be black, so n is assigned 6 zeroes
if t==2:n+=n[1]*5                            #if t is two chars long, it adds the last character times 5 at the end
if t==3:n+=n[1:3]*2                          #if t is 3 chars, it multiplies the last two digits times 3
if t==4:n="#"+n[1]*2+n[2]*2+n[3]*2           #if t is 4 chars, it multiplies each char by two
if t==5:n=n[:2]+n[4]+n[2]+n[4]+n[3]+n[4]     #if t is 5 chars, it makes it work
if t==6:n+=n[t-1]                            #if t is 6 chars, it adds the last character to the end
print n                                      #it prints out n

Can anyone help me save some bytes? All of the if statements seem like they could be shortened into something shorter, I just don't know what.

Try putting each snippet in a list and indexing. Also, switching to Python 3 will most likely save bytes and list[len(list)-x] is the same as list[-x].

If you want to squeeze out some bytes, consider converting if t==1: to if t<2: (and if t==2: to if t<3:, etc.).  It's less readable, to be sure, but more code-golf-able!

TXR Lisp: 171 bytes
Indented:
(do let ((s (cdr @1)))
  (caseql (length s)
    (0 "#000000")
    (1 `#@s@s@s@s@s@s`)
    (2 `#@s@s@s`)
    (3 `#@[mappend list s s]`)
    (4 `#@[s 0]@[s 3]@[s 1]@[s 3]@[s 2]@[s 3]`)
    (5 `#@s@[s 4]`)
    (6 `#@s`))))

This is an anonymous function: the do macro generates a (lambda ...) form.
It is idiomatic coding style, suitable for production; the only golfing is squashing whitespace:
(do let((s(cdr @1)))(caseql(length s)(0"#000000")(1`#@s@s@s@s@s@s`)(2`#@s@s@s`)(3`#@[mappend list s s]`)(4`#@[s 0]@[s 3]@[s 1]@[s 3]@[s 2]@[s 3]`)(5`#@s@[s 4]`)(6`#@s`))))

Braingolf, 95 bytes
l1-.1e$_!&@4>[!@]|.2e$_!&@!@2!@2|.3e$_<@V2[R<!@!@v]|.4e$_<@VRM&,2>[@v!@R]|.5e$_<@!&@@|.6e$_&@|;

Try it online!
This is effectively Braingolf's equivalent of a switch-case on the amount of characters after the # in the input.
Explanation
Stuff that always runs:
l1-.1  Implicit input to stack
l      Push length of stack
 1-    Decrement last item in stack
   .   Duplicate last item in stack
    1  Push 1

If #X:
e$_!&@4>[!@]|
e              If last 2 items (input length - 1 and 1) are equal..
 $_            ..Pop last item silently
   !&@         ..Print entire stack as chars without popping
      4>       ..Push 4 and move it to start of stack
        [..]   ..While loop, decrements first item in stack when it reaches ]
               ..If first item in stack is 0 when reaching ], exit loop
               ..This loop will run 5 times
         !@    ....Print last char without popping
            |  endif

If #XX
This one may be golfable a little, I might look at it when I get home
.2e$_!&@!@2!@2|
.2               Duplicate last item and push 2
  e              If last 2 items (input length - 1 and 2) are equal..
   $_            ..Pop last item silently
     !&@         ..Print entire stack as chars without popping
        !@2      ..Print last 2 items as chars without popping
           !@2   ..Print last 2 items as chars without popping
              |  Endif

If #XXX
.3e$_<@V2[R<!@!@v]|
.3                   Duplicate last item and push 3
  e                  If last 2 items (input length - 1 and 3) are equal..
   $_                ..Pop last item silently
     <@              ..Move first item in stack to the end, then pop and print
       V2            ..Create new stack and push 2 to it
         [.......]   ..While loop, see above for explanation
          R<         ....Switch to stack1 and move first item to end of stack
            !@!@     ....Print last item on stack twice without popping
                v    ....Move to stack2 for loop counting
                  |  Endif

You get the idea

Ruby, 127 bytes
c=~/#(.)?(.)?(.)?(.)?(.)?(.)?/
$6?c:'#'+($5?$1+$2+$3+$4+$5*2:$4?$1+$4+$2+$4+$3+$4:$3?$1*2+$2*2+$3*2:$2?($1+$2)*3:$1?$1*6:"0"*6)

Try it online!

Ruby, 118 bytes
def f c
c.sub!'#',''
s=c.size
t=c[3]
s>5?'#'+c:f(s<1?'0':s<2?c*6:s<3?c*3:s<4?c*2:s<5?c[0]+t+c[1]+t+c[2]+t:c+c[-1])
end

Try it online!

05AB1E, 24 bytes
ćU©0®Ð€D®S¤ý®¤«)JIgè6∍Xì

Try it online or verify all test cases.
Explanation:
ć           # Extract the head of the (implicit) input-string;
            # pop and push remainder and head
 U          # Pop and store the head in variable `X`
  ©         # Store the remainder in variable `®` (without popping)
  0         # Push a 0
  ®Ð        # Push `®` three times
    €D      # Duplicate each character in the last copy (which becomes a character-list)
  ®S        # Push variable `®` again, converted to a character-list
    ¤       # Get its last character (without popping the list itself)
     ý      # Join the list by this character
  ®         # Push variable `®` once again
   ¤        # Get its last character (without popping the string itself)
    «       # Append it to the string
  )         # Wrap all values into a list
   J        # Join the inner list from `€D` together to a list,
            # or in case of input `#`, join everything together to string "0"
            #  i.e. "#" → (["","0","","","",""] → ) "0"
            #  i.e. "#4" → ["4","0","4","4","44","4","44"]
            #  i.e. "#a1" → ["a1","0","a1","a1","aa11","a11","a11"]
            #  i.e. "#1a8" → ["1a8","0","1a8","1a8","11aa88","18a88","1a88"]
            #  i.e. "#abcd" → ["abcd","0","abcd","abcd","aabbccdd","adbdcdd","abcdd"]
            #  i.e. "#3764e" → ["3764e","0","3764e","3764e","33776644ee","3e7e6e4ee","3764ee"]
            #  i.e. #123456 → ["123456","0","123456","123456","112233445566","16263646566","1234566"]
    Ig      # Push the length of the input
      è     # Index (0-based) this into the list (with automatic wraparound for length=7)
       6∍   # Extend/shorten the string to length 6
         Xì # And prepend variable `X` (the "#")
            # (after which the result is output implicitly)

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


text:
CCC 2016: Circle of Life
Before I begin, this challenge was not mine originally
Credits to The University of Waterloo. This came from the Canadian Computing Competition 2016, Senior Problem 5. Here is a clickable link to the contest PDF:
http://cemc.uwaterloo.ca/contests/computing/2016/stage%201/seniorEn.pdf
Here is a link to the site:
http://cemc.uwaterloo.ca/contests/past_contests.html
Challenge
Given a wrapping array of two constant values, determine the configuration after n evolutions for positive integer input n. These two values represent a living cell and a dead cell. Evolutions work like this:
Evolution!
After each iteration, a cell is alive if it had exactly one living neighbor in the previous iteration. Any less and it dies of loneliness; any more and it dies of overcrowding. The neighbourhood is exclusive: i.e. each cell has two neighbours, not three.
For example, let's see how 1001011010 would evolve, where 1 is a living cell and 0 is a dead cell.
(0) 1 0 0 1 0 1 1 0 1 0 (1)
    *   $         %

The cell at the * has a dead cell on both sides of it so it dies of lonliness.
The cell at the $ has a living cell on one side of it and a dead cell on the other. It becomes alive.
The cel at the % has a living cell on both sides of it so it stays dead from overcrowding.
Winning Criteria
Shortest code wins.
I/O
Input will be a list of the cell states as two consistent values, and an integer representing the number of inputs, in some reasonable format. Output is to be a list of the cell states after the specified number of iterations.
Test Cases
start, iterations -> end
1001011010, 1000 -> 1100001100
100101011010000, 100 -> 000110101001010
0000000101011000010000010010001111110100110100000100011111111100111101011010100010110000100111111010, 1000 -> 1001111111100010010100000100100100111010010110001011001101010111011011011100110110100000100011011001

Test Case
This test case froze hastebin and exceeded the size limit on pastebin

I don't think this should be tagged as code golf if byte count is merely a tiebreaker. I'm also not sure if it is a good tiebreaker, as the contest will degenerate to a code golf competition if you can simply port answers to a more concise language to win.

@Dennis Right, I will remove the tag. What do you suggest for tiebreaking then; earliest submission is another one of my ideas.

A naive method can easily do 10^4 cells 10^4 times in 1 second. 10^8 bitwise operations is nothing.

I'm voting as unclear for the moment since it's unknowable what is meant by complexity when there are multiple parameters.

I haven't really analyzed it but I suspect it's also too trivial for a [tag:fastest-algorithm].

Does a cell count as its own neighbor?

@FryAmTheEggman Yes; sorry, I fixed that. I was having markdown troubles with such a long line.

@Zgarb No, it does not.

@feersum Thank you for your feedback. I decided to change it to a [tag:code-golf] instead because it doesn't have much room for optimizations.

Your hastebin test case claims to give the MD5 hash with a trailing newline, but actually gives the MD5 hash without a trailing newline. I cannot figure out how to make the hash match either way on your firebaseapp test case. Can you check that again?

@AndersKaseorg Oh, hm, that's strange. I'll update the description. And I'll need to get back to a computer (not this chromebook) for the insane test case because i can't update from my chromebook, so I'll get back to you on that one. Thanks!

@feersum, there is a tiny bit of play in [tag:fastest-algorithm]. The naïve algorithm takes Theta(nt) where n is the length of the array and t is the number of evolutions; a faster algorithm takes Theta(n lg t).

I've created a chatroom where we can discuss optimized algorithms further.

I think your description of alive/dead = 1/0 could do with improving. I had to read the pdf to fully understand the challenge, which is fine until the link dies. You should have all the info in your question.

@Notts90 I hope my latest edit clarifies it more.

@HyperNeutrino yes much clearer :)

@AndersKaseorg I think I've fixed it.

APL (Dyalog),14 bytes
Prompts for start state as Boolean list and then for number of iterations
(1∘⌽≠¯1∘⌽)⍣⎕⊢⎕

Try it online!
⎕ numeric prompt (for Boolean list of start state)
⊢ on that, apply
(…)⍣⎕ the following tacit function, numeric-prompt times
 ¯1∘⌽ the argument rotated one step right
 ≠ different from (XOR)
 1∘⌽ the argument rotated one step left

Jelly, 7 bytes
ṙ2^ṙ-µ¡

Try it online!
Extra Test Case (footer for formatting).
Explanation
ṙ2^ṙ-µ¡
     µ¡  - repeat a number of times equal to input 2:
ṙ2         - previous iteration rotated 2 to the left
  ^        - XOR-ed with:
           - (implicit) previous iteration
   ṙ-      - rotate back (by negative 1 to the left)

05AB1E, 6 bytes
FDÀÀ^Á

Try it online!
Explanation
F        # input_1 times do
 D       # duplicate last iteration (input_2 the first iteration)
  ÀÀ     # rotate left twice
    ^    # XOR
     Á   # rotate right


text:
Golf Practice: CJam
This is a challenge about the the tricks and optimizations that can be used when golfing in CJam. CJam golfers may recognize many of the tricks involved. However, unfamiliar approaches and constructs may be involved, so take a look at the CJam tips as well as the CJam instruction reference if you get stuck. Solutions may be tested on TIO or with the JavaScript interpreter.
Goal: There are 10 problems, each with a CJam snippet for you to optimize. Your goal is to create something equivalent but shorter. The reference solutions total 148 bytes. Your goal is to beat that by as much as possible.
The winner will go to the submission that solves all 10 problems with the smallest total number of bytes. Tiebreaker is earlier post.
Answering: Please spoiler your entire answer, except for your total score. It is intended that you do not look at other people's answers before submitting your own.
Each submission should answer every problem and give the corresponding byte count, but feel free to use the reference implementation if you cannot improve it.
Details: All answers will take input via the stack and output to the stack. You can assume that the input will be the only thing on the stack (or, if there is no input, the stack will be empty).
Problem 1: Add one to every element in a list (link):
e# 5 bytes
{1+}%

Problem 2: Given a list, create a list of partial sums. For example, [1 2 3] becomes [1 3 6] (link):
e# 16 bytes
_,\a*ee{~\)<:+}%

Problem 3: Create the following "times table" array (it doesn't need the whitespace, it's just there to make it look better):
[[1  2  3  4  5  6  7  8  9]
 [2  4  6  8 10 12 14 16 18]
 [3  6  9 12 15 18 21 24 27]
 [4  8 12 16 20 24 28 32 36]
 [5 10 15 20 25 30 35 40 45]
 [6 12 18 24 30 36 42 48 54]
 [7 14 21 28 35 42 49 56 63]
 [8 16 24 32 40 48 56 64 72]
 [9 18 27 36 45 54 63 72 81]]

Reference (link):
e# 15 bytes
9{):T;9{)T*}%}%

Problem 4: Add one to each element in a nested array (link):
e# 22 bytes
{{_`0='[={T}{)}?}%}:T~

Problem 5: Given a list with an odd number of elements, delete the center one (link):
e# 14 bytes
__,2/_@<@@W*>+

Problem 6: Given a list of bits (1 or 0), remove all leading zeroes (link):
e# 6 bytes
_1+1#>

Problem 7: Given a list of positive numbers, return the same list, but with every element replaced by 1 (link):
e# 5 bytes
{;1}%

Problem 8: Generate the list [1 2 3 4 5 4 3 2 1] (link):
e# 12 bytes
XYZ4 5 4ZYX]

Problem 9: Generate the list [[[0 1] [1 2] [2 0]] [[0 0] [1 1] [2 2]] [[0 2] [1 0] [2 1]]] (link):
e# 41 bytes
TX][XY][YT]][[TT][XX][YY]][[TY][XT][YX]]]

Problem 10: Take two arrays on the stack and "interleave" them, so "foo" "bar" becomes "fboaor". You can assume the arrays have the same length (link):
e# 12 bytes
]_0=,,\ff=:+

Note: Most of this challenge was stolen from Pyth practice.

Multi-part challenges are off-topic. The original golf practice has been closed as such. I don't know why the Pyth practice has slipped through the cracks there.

I'm voting to close this question as off-topic because multi-part challenges are off-topic.

@MartinEnder Hmm, even though a fun challenge, unfortunately it's off-topic here, and I agree with you.

68 bytes: https://pastebin.com/4gv5hnbD


text:
General tips for representing large numbers
Sometimes, while golfing, one needs to represent large number(s) in their code. Writing them as is can significantly increase the byte-count.
What general1 tips do you have for representing long numbers concisely in code?
Please post one tip per answer.

1With general, I mean tips that can be applied to more than a single language. For language-specific tips, post in their respective thread.

Related.

Also related

I saw someone misunderstanding the question - perhaps the title should say this is about golfing.

Also also related

Look out for special numbers
Some languages have built-in functions for squares, exponentiation with base 2, n-th prime, factorial, or other procedures that can generate large numbers. Check if you number happens to fall into any of those categories.
And if it doesn't, it may happen that a larger number that does will fit for your purposes and can be used instead.

Even if the number you want cannot be generated with a builtin function, it may be possible to generate a number that you can use as the basis for a simple calculation to arrive at your number, while still saving bytes over writing it out.

+1 for "larger number" -- if 1.01e6 iterations is enough, 1e7 saves 3 bytes at the expense of running time.

Use bitwise boolean operators
Some languages have bitwise AND, OR, XOR, and sometimes NOT.
Expressing a specific large number as a bitwise combination of a result of an exponentiation or left shift and another number can get you to precisely the number you need. This is usually only worth it if the numbers get quite big.
For example, 2147483722 is 10 bytes, but 2<<30^74 (2^31 bitwise-XORed with 74) is only 8.

The shift operator can be replaced with exponentiation, if the language has that operator (eg bc). And XOR is never more useful than + and -: in this case, xor and add give the same result, but in all cases there is some integer which can be added or subtracted to produce the same result as xor with an integer, and the addend is no larger and sometimes shorter.

@rici True if all integers are written as simple decimals, but it's just possible the integer to be used with xor can be shortened in ways that the integer to be used with plus or minus can't: think of something like 1e9^2e9.

@rici How would you express 9<<49^7<<19 using addition instead of xor?

@rici No, I meant what I wrote. It evaluates to 1286561280 in JavaScript and Perl (and probably other languages), and it's a shorter expression to produce that value than the equivalent using + or -.

@hvd: OK, point taken.

Use Scientific Notation
Scientific notation can save bytes in case of long numbers. For Example:
3564e-8 // returns 0.00003564 (saves 3 bytes!)

Why not just use 3564e-8 in that case?

@Joey Yes, of course! Thank you! :)

Granted, you can usually write the other number as .00003564, which is also one byte shorter again.

@Joey Not every language does, hence, I won't edit that in.

Is it intentional that 3564 (left) becomes 354 (right) or is that a typo?

@Erik Typo. Thanks for pointing that out! :)

Use Strings for repetitive numbers
For numbers that are very repetitive in nature, you can use Strings and cast them to Integer. For Example, in JavaScript
+"1".repeat(100) // returns 100 1s (saves 84 bytes!)

Or you could use a very large fraction, 1e100/9 in this case.

Look for another number to use instead
This may sound like a non-answer, but it is not always obvious that a larger number can be calculated by shorter code. An example I remember is Output a googol copies of a string, where the obvious answers require computing 10100. As it turns out, computing any multiple of 10100 leads to an equally correct, but in some languages, shorter answer. Dennis's answer there uses 100100, my own uses 250255.

Another example of this is CJam where you can get the current timestamp with es if you just need a large number but don't care about its value (or that it's always the same).

Base Compression
Base decompression code can be fairly complex, but if you have a truly enormous number sometimes it can help to compress it in some base higher than 10.
It also helps that in some languages, the base compression code is very simple. For example, PHP has base64_decode(_), Python has int(_,36), JavaScript has parseInt(_,36), and many golfing languages have base decompression builtins.
For example, in CJam:
"+ÜTbô±"256b

This contains an unprintable. Try it online!
This yields:
12345678987654321

Use exponential fractions for large repetitive numbers
Say you wanted to generate the number made of 100 1's. You could use int("1"*100), +"1".repeat(100), etc. but you can also take advantage of the fact that it's very close to
1e100/9

This works best for very repetitive numbers, such as those made of a single digit. A couple repeated digits also works fairly well:
12e100/99  // Generates 121212121212... (100 digits)

Occasionally you'll find some other weird pattern which also can be represented fairly tersely in this method. If you happened to need int("123456790"*11), for example:
1e100/81

Be careful, though: numbers such as int("1234567890"*10) don't have such an easy representation.

Use Bitwise Left Shift for 2's exponentiation
Although, there are many languages that support operator for exponentiation, some do not. And those which don't, usually require calling functions (or Class/Object methods), which can cost a few bytes.
But you can save some bytes when you need to raise 2 to the power n by using the Bitwise Left Shift operator << as 1<<n. Note that this will only save you bytes if n is greater than or equal to 17. However, this will always save you bytes if n is dynamic. Few Examples:
1<<2 // returns 4 (3 bytes more :( )
1<<3 // returns 8 (3 bytes more :( )
1<<6 // returns 64 (2 bytes more :( )
1<<14 // returns 16384 (no bytes saved)
1<<17 // returns 131072 (saves 1 byte!)
1<<18 // returns 262114 (saves 1 byte!)

Note that you can use other values instead of 1.  8<<9 // 4096 so we can get up to 99<<61 in 6 bytes, which equals 6,917,529,027,641,081,856 saving 13 bytes!

@Draco18s Yes, and it's covered here.

That one more covers the boolean bitwise operators. Yes, it has the bitshifting too, but it's talking about using two large numbers to XOR and get a third, specific number.

Chinese Remainder Theorem
If arbitrary big integers frequently appear, or big integer representation in target programming language costs too many bytes, you can consider using Chinese Remainder Theorem.
Choose some pairwise relatively prime integers mi >=2, and you can express a big number from 0 to lcm(m1, m2, ... , mi) -1
For example, I choose 2, 3, 5, 11, 79, 83, 89, 97, then I can express number less than 18680171730 uniquely. 10000000000 (1e10) can be expressed as 0,1,0,1,38,59,50,49 (1e10 mod 2, 3 ... , 97) which need not be expressed as special Big Integer class/struct which might save some bytes in some programming language.
Addition and substraction can be done directly using this representation.
Example:
(0,1,0,1,38,59,50,49)+(0,2,0,6,23,20,16,53) = 1e10 + 5000
                                            = (0+0 mod 2, 1+2 mod 3, 0+0 mod 5, 1+6 mod 11, 38+23 mod 79, 59+20 mod 83, 50+16 mod 89, 49+53 mod 97)

Care to elaborate on that?

@Mayube I have added some explanation, but I doubt it is useless in most cases.

It's "remainder theorem".

Use String Padding (where possible)
If a large number includes a repeating digit at the beginning or end, you may be able to save bytes by using your one of your language's padding methods to construct a string of the number you're looking for, which you can then convert to an integer.

Example
To generate the number 1111111111111111111111112 (25 bytes) in JavaScript (ES8):
+"2".padStart(25,1) // 19 bytes

Use Exponents
If your language has an exponent operator you might be able to use it to generate, if not the number you want, at least a number you can perform a simple calculation or 2 on to arrive at your number. Even without an operator, you may still be able to save bytes with a built-in function or method.
Example
The maximum safe integer in JavaScript is 9007199254740991, which is 16 digits long. In ES7, this can be calculated with the following 7 bytes:
2**53-1

The equivalent in ES6 and earlier, while the same length as the integer itself in this instance, demonstrates that using a more verbose method might not necessarily cost you any bytes.
Math.pow(2,53)-1

The above, though, may work out shorter if, for example, you already have Math aliased to a single character elsewhere in your code.

Use fractions in the place of float
Example: 1./3 in place of 0.333333333


text:
Print Real Invisible Text
My previous challenge, Print invisible text was quite popular, likely due to how trivial it is.
However those more observant of you may have noticed that you're not really printing invisible text, because it's impossible to read what was inputted given only the output.
So I figured how about a real invisible text challenge.
Given a string consisting of only printable ASCII characters (0x20-0x7E), convert each character to a distinct Unicode character (in UTF-8 encoding) that is not one of the 95 printable ASCII characters (any UTF-8 character outside of the 0x20-0x7E range)
Input
A string of printable ASCII characters, either as a string or character array/list
Output
The input string with each character replaced with a distinct non-printable character. Each given character must have a corresponding non-printable character that is not used as the substitute for any other character.
If you are unable to print non-printable characters, you can output the character values instead.
For example if your code replaces all lowercase a's with 0x01, you may not use 0x01 as the substitution for any other characters.
Your code must also be deterministic. This means that if, given the string Hello, all lowercase l's are replaced with 0x03, your code must also replace all lowercase l's with 0x03 given any other string.
Testcases
It's somewhat difficult to write testcases for this challenge, so I'll simply show the output as a list of hexcodes
input     -> output
"Hello"   -> [0x01, 0x02, 0x03, 0x03, 0x04]
"Hi!"     -> [0x01, 0x05, 0x06]
""        -> []
"   H   " -> [0x07, 0x07, 0x07, 0x01, 0x07, 0x07, 0x07]
"yo! "    -> [0x08, 0x04, 0x06, 0x07]

Leaderboard
Here is a Stack Snippet to generate both a regular leaderboard and an overview of winners by language.

/* Configuration */

var QUESTION_ID = 123447; // Obtain this from the url
// It will be like https://XYZ.stackexchange.com/questions/QUESTION_ID/... on any question page
var ANSWER_FILTER = "!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe";
var COMMENT_FILTER = "!)Q2B_A2kjfAiU78X(md6BoYk";
var OVERRIDE_USER = 48934; // This should be the user ID of the challenge author.

/* App */

var answers = [], answers_hash, answer_ids, answer_page = 1, more_answers = true, comment_page;

function answersUrl(index) {
  return "https://api.stackexchange.com/2.2/questions/" +  QUESTION_ID + "/answers?page=" + index + "&pagesize=100&order=desc&sort=creation&site=codegolf&filter=" + ANSWER_FILTER;
}

function commentUrl(index, answers) {
  return "https://api.stackexchange.com/2.2/answers/" + answers.join(';') + "/comments?page=" + index + "&pagesize=100&order=desc&sort=creation&site=codegolf&filter=" + COMMENT_FILTER;
}

function getAnswers() {
  jQuery.ajax({
    url: answersUrl(answer_page++),
    method: "get",
    dataType: "jsonp",
    crossDomain: true,
    success: function (data) {
      answers.push.apply(answers, data.items);
      answers_hash = [];
      answer_ids = [];
      data.items.forEach(function(a) {
        a.comments = [];
        var id = +a.share_link.match(/\d+/);
        answer_ids.push(id);
        answers_hash[id] = a;
      });
      if (!data.has_more) more_answers = false;
      comment_page = 1;
      getComments();
    }
  });
}

function getComments() {
  jQuery.ajax({
    url: commentUrl(comment_page++, answer_ids),
    method: "get",
    dataType: "jsonp",
    crossDomain: true,
    success: function (data) {
      data.items.forEach(function(c) {
        if (c.owner.user_id === OVERRIDE_USER)
          answers_hash[c.post_id].comments.push(c);
      });
      if (data.has_more) getComments();
      else if (more_answers) getAnswers();
      else process();
    }
  });
}

getAnswers();

var SCORE_REG = /<h\d>\s*([^\n,]*[^\s,]),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/;

var OVERRIDE_REG = /^Override\s*header:\s*/i;

function getAuthorName(a) {
  return a.owner.display_name;
}

function process() {
  var valid = [];

  answers.forEach(function(a) {
    var body = a.body;
    a.comments.forEach(function(c) {
      if(OVERRIDE_REG.test(c.body))
        body = '
' + c.body.replace(OVERRIDE_REG, '') + '
';
    });

    var match = body.match(SCORE_REG);
    if (match)
      valid.push({
        user: getAuthorName(a),
        size: +match[2],
        language: match[1],
        link: a.share_link,
      });

  });

  valid.sort(function (a, b) {
    var aB = a.size,
        bB = b.size;
    return aB - bB
  });

  var languages = {};
  var place = 1;
  var lastSize = null;
  var lastPlace = 1;
  valid.forEach(function (a) {
    if (a.size != lastSize)
      lastPlace = place;
    lastSize = a.size;
    ++place;

    var answer = jQuery("#answer-template").html();
    answer = answer.replace("{{PLACE}}", lastPlace + ".")
                   .replace("{{NAME}}", a.user)
                   .replace("{{LANGUAGE}}", a.language)
                   .replace("{{SIZE}}", a.size)
                   .replace("{{LINK}}", a.link);
    answer = jQuery(answer);
    jQuery("#answers").append(answer);

    var lang = a.language;
    if (/ b.lang) return 1;
    if (a.lang < b.lang) return -1;
    return 0;
  });

  for (var i = 0; i < langs.length; ++i)
  {
    var language = jQuery("#language-template").html();
    var lang = langs[i];
    language = language.replace("{{LANGUAGE}}", lang.lang)
                       .replace("{{NAME}}", lang.user)
                       .replace("{{SIZE}}", lang.size)
                       .replace("{{LINK}}", lang.link);
    language = jQuery(language);
    jQuery("#languages").append(language);
  }

}
body { text-align: left !important}

#answer-list {
  padding: 10px;
  width: 290px;
  float: left;
}

#language-list {
  padding: 10px;
  width: 290px;
  float: left;
}

table thead {
  font-weight: bold;
}

table td {
  padding: 5px;
}

<link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b">

Leaderboard

	Author	Language	Size

Winners by Language

Language	User	Score

{{PLACE}}	{{NAME}}	{{LANGUAGE}}	{{SIZE}}	Link

{{LANGUAGE}}	{{NAME}}	{{SIZE}}	Link

There is no such thing as a UTF-8 character: UTF-8 is a serialisation of Unicode, not a charset. And if "non-printable" makes sense in a Unicode context, it's certainly much narrower than "all but 95 of the hundreds of thousands of allocated codepoints".

@PeterTaylor Given we're talking in terms of character hexcodes here, I assumed it was clear that when I say UTF-8 character I mean a Unicode character in the UTF-8 encoding. ASCII is also an encoding standard, not a charset, yet people have no issue with the term "ASCII character". Anyway, I'll edit the wording to clarify.

Any particular reason UTF-8 is required?

Can the input be empty?

@Dennis yes, see the third testcase

+1 for "If you are unable to print non-printable characters"

Whitespace, 39 36 bytes

Try it online!
Explanation
nssn  ; label 'loop'
ssstssn ; push 4 to use as a multiplication operand
sns   ; dup 4 to use as a heap address
sns   ; dup 4 to use as a heap address
tnts  ; getchar and store at address 4
ttt   ; retrieve the value at address 4
tssn  ; multiply the character value by 4
tnss  ; putchar output the new character
nsnn  ; jmp 'loop'

Originally I wanted to multiply by -0 or -1 since they would be the shortest digits possible to declare in Whitespace. TIO does not differentiate between -0 and +0 so that's out. Unfortunately while the tutorial/spec is ambiguous about how to interpret a negative value as a char TIO (rightly) throws an error about the invalid argument so that also isn't an option.
The next shortest working constant is 4 so we end up performing the same basic approach as the Powershell/Pyth solutions.

Whitespace, 56 53 bytes - maps to tag characters

Try it online!
Explanation
Effectively the same approach as the previous version except this uses 0xE0000 as the constant and adds instead of multiplies. This maps the visible ASCII characters to the corresponding Unicode Tag Character (the range U+E0000-U+E007F). The intended use for this range was to indicate the language of the text in a plaintext file however that use is discouraged. This code will output valid labels if you prefix strings with a 0x01 character.
The Unicode Standard says that characters in this range have no visible rendering so I feel this meets the spirit of the challenge better than the previous approach.

Using an invisible program to print invisible text.  I like.

Jelly, 3 bytes
O²Ọ

Try it online!
Squares each codepoint.

Very similar to the Japt solution I came up with, expect I cubed the codepoint instead of squaring it - you OK with me posting it?

@Shaggy Japt ≠ Jelly, so you can post it.

Clever solution, didn't think of squaring.

Grand, just wanted to be sure, lest you thought I was just ripping off your solution :)

@Shaggy there's no guideline against porting a solution to another language ; if there was it would be terrible since there is usually one optimal algorithm which gives optimal implementations in most languages, and nobody but the first poster wouldn't be able to prove they came with the algorithm on their own. Of course if you indeed port someone else's solution, it's only fairplay to mention their answer.

@Holger Let us continue this discussion in chat.

Japt, 5 2 bytes
cp

Try it online

Explanation
     :Implicit input of string U
c    :Map over the character codes of the string.
p    :Square them.
     :Implicit output of result.

Hmm, after closer examination, it seems that 126 ** 3 == 2000376, which isn't in the range [0..1114111]. You can still square though :) That's because UTF-8 ends there, while UTF-16 continues.

@EriktheOutgolfer Ehm. UTF-8 has exactly the same range as UTF-16 by definition. (In theory, UTF-8 could store higher codepoints, using 5 or 6 bytes per codepoint, but that is illegal.)

Brain-Flak, 33 bytes
Includes +1 for -c
{((({}){}){}<>)<>}<>{({}<>)<>}<>

Try it online!
# For each character
{
  # Multiply by 4 and move to the other stack
  ((({}){}){}<>)

# End loop
<>}

# For each character on the other stack
<>{

  # Copy it back (reverse the stack)
  ({}<>)<>

# End loop
}<>

Mathematica, 48 bytes
FromCharacterCode[4Mod[Hash/@Characters@#,978]]&

Explanation:
                             Characters@#      & - Convert string to array of characters
                       Hash/@                    - Hash them all using default hash
                   Mod[                  ,978]   - apply a modulus which uniquely transforms each potential character's hash into a number
                  4                              - times by 4 to move values out of 0x20-0x7E.
FromCharacterCode[                            ]  - Convert array of numbers back to string

Interestingly of the two modulus options less than 1000 which changed the 96 characters into 96 unique values with modulus 978 the lowest two values were 7 then 33. Luckily times by 4 converts this to 28 and 132 which both just fall outside the visible range. If I used the other modulus of 784 then I needed to multiply by 18 to move the numbers outside the range.
Test case.
Note: extra backslashes in there as escape characters for " and \. Also character 0x7E doesn't seem to want to paste correctly.
Input: "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"

Output:

The use of Hash came about as ToCharacterCode is really long. However hashing it was nearly as expensive. The easy mathematica way to do this would be 49 bytes:
FromCharacterCode[4ToCharacterCode@Characters@#]&

Braingolf v0.6, 17 bytes
VRl1-M[R.*>v]R&@

Squares each char value then prints.
-1 byte thanks to Erik the Outgolfer's squaring solution
Braingolf v0.7, 6 bytes [non-competing]
{.*}&@

Also squares each value then prints, but v0.7 has the "foreach" {} loop

Vyxal s, 3 bytes
C²C

Try it Online!
That is,
C   # string to character codes
²C  # square each and convert back to letters
    # the s flag joins as a single string.

but if IO was a little less restrictive:
using K flag, 1 byte
²

Try it Online!
Keg is weird okay. It just is.
    # the K flag enables Keg mode, which makes integers and characters interchangeable. It's a tribute to my first golfing language and existed before I saw this challenge
²   # square the code point of each character
    # output that as characters because K flag.

The second answer now outputs codepoints instead of characters on the old interpreter, and doesn't work at all on the new interpreter

Google Sheets, 68 bytes
=ArrayFormula(Join("",IfError(Char(Code(Mid(A1,Row(A:A),1))^2),"")))

I wanted to post this to show how awkward it is to do some basic functions in Sheets. Do you want to do an operation to every character in a cell and out the concatenated result? You're at 42 bytes before you even act on those characters.
=ArrayFormula(Join("",Mid(A1,Row(A:A),1)))

Otherwise, this is the same as other solutions: square the code point of each character.

PowerShell, 32 31 Bytes
-1 Thanks to neil, 99+ to 4*
[char[]]"$args"|%{[char](4*$_)}

multiplies 9 by each character code and prints it back.

Out of interest, would multiplying by a small number (4-9) work?

the lowest printable times 4 is greater than the largest printable, that's -1 - thanks!

CJam, 8 5 bytes
l95f+

Try it online!
Adds 95 to each codepoint.

Isn't there a way to multiply or square instead?

@NieDzejkob No, this is based on the fact that Character + Long = chr(ord(Character) + Long). Character * Long = [Character] * Long. Character # Long = error (# is exponentiation in CJam).

Pyth, 6 bytes
smC*4C

Try it here.
Multiplies each codepoint by 4.

Subleq (8-bit), 11 bytes
-1 15 -128
2 15 -1
15 -1 9
15 15

Subleq Emulator
Explanation
-1 15 -128 '0: input to 15:, if null exit; use -128 for exit so I can be used to add 128
           '   in the next line saving a byte
2 15 -1    '3: 15: = 15: + 128
15 -1 9    '6: output 15:
15 15      '9: 15: = 0, goto 0; final 0 is not entered saving a byte

05AB1E, 4 bytes
ÇnçJ

Try it online!
Squares each codepoint.

The J can be left out, as a list of characters is also a string.

CJam, 4 bytes
lWf^

XORs each code point with -1. CJam's characters are 16 bits wide, so this maps code point n to code point 65535 - n.
Try it online!

Decimal, 37 bytes
91D31030030012255D412D590D543D301291D

Explanation:
91D             ; declare jump 1
    310         ; push user input to stack
    300         ; duplicate
    300         ; duplicate
    12255D      ; push EOF to stack
    412D        ; compare top two values, pop, push result
    5 90D 5     ; if result == true, quit
    43D         ; multiply top two values, pop, push result
    301         ; print
    2           ; pop
91D             ; goto jump 1

Try it online!

so jumping to zero (90D) terminates?

@Mayube Exactly.

Husk, 5 bytes
m(c□c

Try it online!

brainfuck, 12 bytes
,[[->-<]>.,]

Try it online!
Negate assuming latin1 output

-5: ,[>.<,]. Replaces each character with null

@Makonede Each given character must have a corresponding non-printable character that is not used as the substitute for any other character.

My bad, did not notice that.

Grok, 14 bytes
:j
}lI_p+wYp
q

Modification of this cat program. It adds 95 to every character before it gets outputted, changing the character range from 0x0A - 0x7E to 0x7F - 0xDD.

Python 3, 40 38 bytes

print([chr(ord(x)*9)for x in input()])

Try It Online!

C, 42 bytes
c;f(){while(~(c=getchar()))putwchar(c*c);}

Assumes a UTF-8 locale. Input is squared.
Try it online!

Clean, 25 bytes
import StdEnv

map((+)'~')

A partial function literal.
Try it online!
Realistically:
f s = {# c+'~' \\ c <-: s}

Unboxed array comprehension over an unboxed array of the same type ({#Char} -> {#Char}). Clean will be able to determine that the uniqueness is transferrable (!u:{#Char} -> u:{#Char}), and that the size is the same as the input size. This means that if you pass a *String, every character will be destructively updated with the corresponding one in the output, meaning no memory allocation or movement is done and the graph node is fully reused.
Try it online!

Erlang (escript), 18 bytes
One of the rare cases that Erlang is ever competitive.
f(X)->[I*I||I<-X].

Try it online!
Explanation
f(X)-> % Function taking a single string as input
[I*I|| % Square the code-point ...
I<-X]. % ... for every character taken from the string

Kotlin, 25 bytes
Subtract 99 from each character value. This ends up moving space to FFBD (as Kotlin uses UTF-16) and most of the ASCII set to control characters and unreadable garbage.
{fold(""){s,c->s+(c-99)}}

Try it online!

Duocentehexaquinquagesimal, 5 bytes
SYÍ’ü

Try it online!

Python 3, 47 bytes
lambda x:''.join(chr(y-32+(y>63)*98)for y in x)

Input must be bytes. I know this doesn't win, I'm posting it because the output could fit into an 8-bit ascii extension.
Try it online!

The lambda x: must be included in the bytecount.

Also, you can save 14 with lambda s:[_*4for _ in s].

Thunno J, 4 bytes
(Actually \$ 4 \log_{256}(96) \approx \$ 3.29 bytes but the leaderboard doesn't take decimals)
O2^C

Attempt This Online!
Explanation
O     # Ordinals of the input
 2^   # Square each ordinal
   C  # Convert back to characters
      # J flag joins the list

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