Pair-golfing Twin primes and the Collatz sequence This is a new kind of challenge inspired by the Recover the mutated source code problem.

You should write two programs or functions both in the same language. The first one should solve Task #1 and the second one should solve Task #2.

Your score will be the sum of the longer program and the Levenshtein distance between the two programs source code. Lower score is better so you should try to make the two solutions similar while keeping the lengths of the programs short.

Task #1

You are given a positive integer N and you should output the Collatz sequence of N separated by spaces or newline.  Trailing separator is allowed.

The first element of the Collatz sequence is N. The rest of the elements are generated based on their successor \$a_{i-1}\$:

$$ a_i =
\begin{cases}
\frac{a_{i-1}}{2} & \text{ if } a_{i-1} \text{ is even} \\
3a_{i-1} + 1 & \text{ if } a_{i-1} \text{ is odd}
\end{cases}
$$

As soon as the sequence reaches 1 no new elements are generated.

Input => Output examples:

6 => 6 3 10 5 16 8 4 2 1
8 => 8 4 2 1
1 => 1

Task #2

A pair of twin primes is a pair of positive integer whose difference is 2 and they are both primes.

You are given a positive integer N and you should output the smallest pair of twin primes where both primes are bigger than N The first number should be the smaller one and the two primes should be separated by spaces or newline.  Trailing separator is allowed.

Input => Output examples:

6 => 11 13
42 => 59 61
1 => 3 5

Snippet for calculating the score

(Modification of the one in the Recover the mutated source code problem.)

var f=document.getElementById("f"),g=document.getElementById("s");function h(){var a=f.value,e=g.value,m=Math.max(a.length,e.length);if(10000<a.length)a="First program is too long!";else if(10000<e.length)a="Second program is too long!";else{if(0===a.length)a=e.length;else if(0===e.length)a=a.length;else{var d=[],b;for(b=0;b<=e.length;b++)d[b]=[b];var c;for(c=0;c<=a.length;c++)d[0][c]=c;for(b=1;b<=e.length;b++)for(c=1;c<=a.length;c++)d[b][c]=e.charAt(b-1)===a.charAt(c-1)?d[b-1][c-1]:Math.min(d[b-1][c-1]+1,Math.min(d[b][c-1]+1,d[b-1][c]+ 1));a=d[e.length][a.length]}a="Distance = "+a+"   Longer length = "+m+"   Score = "+(a+m)+""}document.getElementById("d").innerHTML=a}f.onkeyup=h;g.onkeyup=h;
First program<textarea id=f rows=2 cols=80 style="width:100%"></textarea>Second program<textarea id=s rows=2 cols=80 style="width:100%"></textarea>

Edit

In the answers' header let's use the format

[Language], [longer length] + [distance] = [final score].

E.g.

Python 2, 60 + 32 = 92

CJam, 24 + 17 = 41 42
Collatz program:
ri2*{:N2%N3*)N2/?__p(}g;

Twin primes program:
ri_2+]{:)_{mp}/&_+((}gS*

Both take input from STDIN and print space/newline separated numbers to STDOUT
Try them online here


Infinitely many primes Since Euclid, we have known that there are infinitely many primes. The argument is by contradiction: If there are only finitely many, let's say \$p_1,p_2,...,p_n\$, then surely \$m:=p_1\cdot p_2\cdot...\cdot p_n+1\$ is not divisible by any of these primes, so its prime factorization must yield a new prime that was not in the list. So the assumption that only finitely primes exist is false.
Now let's assume that \$2\$ is the only prime. The method from above yields \$2+1=3\$ as a new (possible) prime. Applying the method again yields \$2\cdot 3+1=7\$, and then \$2\cdot 3\cdot 7+1=43\$, then \$2\cdot 3\cdot 7\cdot 43+1=13\cdot 139\$, so both \$13\$ and \$139\$ are new primes, etc. In the case where we get a composite number, we just take the least new prime. This results in A000945.
Challenge
Given a prime \$p_1\$ and an integer \$n\$ calculate the \$n\$-th term \$p_n\$ of the sequence defined as follows:
$$p_n := \min(\operatorname{primefactors}(p_1\cdot p_2\cdot ... \cdot p_{n-1} + 1))$$
These sequences are known as Euclid-Mullin-sequences.
Examples
For \$p_1 = 2\$:
1 2
2 3
3 7
4 43
5 13
6 53
7 5
8 6221671
9 38709183810571

For \$p_1 = 5\$ (A051308):
1 5
2 2
3 11
4 3
5 331
6 19
7 199
8 53
9 21888927391

For \$p_1 = 97\$  (A051330)
1 97
2 2
3 3
4 11
5 19
6 7
7 461
8 719
9 5

JavaScript (ES6),  45  44 bytes
Takes input as (n)(p1), where \$n\$ is 0-indexed.

n=>g=(p,d=2)=>n?~p%d?g(p,d+1):--n?g(p*d):d:p

Try it online!
Commented
n =>                // n = 0-based index of the requested term
  g = (             // g is a recursive function taking:
    p,              //   p = current prime product
    d = 2           //   d = current divisor
  ) =>              //
    n ?             // if n is not equal to 0:
      ~p % d ?      //   if d is not a divisor of ~p (i.e. not a divisor of p + 1):
        g(p, d + 1) //     increment d until it is
      :             //   else:
        --n ?       //     decrement n; if it's still not equal to 0:
          g(p * d)  //       do a recursive call with the updated prime product
        :           //     else:
          d         //       stop recursion and return d
    :               // else:
      p             //   don't do any recursion and return p right away


Find number of polynomials with a root which is a root of unity Write a program which takes an integer argument and outputs the number of degree n monic polynomials with coefficients that are -1,1 or 0 which have a root which is a root of unity.   To make it a little cleaner, only count polynomials with leading coefficient of 1.

You can use any language you like as long as it is freely available and the interpreter/compiler is open source. You can use the standard libraries of the language you choose but no tools specifically designed to solve this problem.

Your score is simply the length of your code.

Tests

  For n = 1,2,3,4,5,6,7,8 the output should be 2,6,12,36,94,
  276,790.

Degree two polynomials with a root which is a root of unity.

  x^2-1,x^2-x, x^2+x, x^2-x+1, x^2+1, x^2+x+1

There was a bug in my numbers above and so I have just copied Peter Taylor's until I find out how to fix it.

GolfScript (111 107 chars)

~3\?:k,{2k*+3base{(}%:P,.*,{,{!}%-1+P{.,2$,>!{\[.0={*}+2$%\2$0={*}+%\]zip{{-}*}%\}*\0:x;{x|:x},.}do;,(},},,

Note: I disagree with some of the given test cases: I get

input   output
   1         2
   2         6
   3        12
   4        36
   5        94
   6       276
   7       790
   8      2270
   9      6412
  10     18334

Theory

Every algebraic number \$a\$ over a field \$F\$ has a minimal polynomial which is a factor of any polynomial \$P\$ in \$F[x]\$ for which \$P(a) = 0\$. For every integer \$n\$, the primitive \$n^\textrm{th}\$ roots of unity (those which are not roots of unity for any smaller \$n\$) share a minimal polynomial, the \$n^\textrm{th}\$ cyclotomic polynomial, whose degree is \$\varphi(n)\$.

So for input \$k\$ we can get an exact result by enumerating the possible functions and for each one looking for a non-trivial GCD with a cyclotomic polynomial of degree no greater than \$k\$.

There are two ways of doing that check: either by looping over the cyclotomic polynomials (or safe products thereof - e.g. \$x^n - 1\$ rather than the \$n^\textrm{th}\$ cyclotomic polynomial), or by multiplying them together and doing one GCD. My current approach is to take a very loose bound \$N = (k+1)^2\$ on the largest number whose totient is \$k\$ and then loop over \$x^i - 1\$. This is much faster than doing a single GCD with a massive polynomial, which can get some truly enormous intermediate values in the GCD, and I've managed to golf it ever so slightly more as well.

For speedier results at the cost of some characters, the bound can be improved moderately. Let \$M(n) = \max \{i : \varphi(i) = n\}\$. This has one major problem, which is that it's not well defined for odd \$n\$ greater than \$1\$ or for all even \$n\$. It also has the minor problem that it's not monotone. We need to use bound \$B(n) = \max \{i : \varphi(i) \le n\} = \max \{M(j) : j \le n\}\$.

H. Gupta defines \$A(n) = n \prod_{(p-1) \mid n} \frac{p}{p-1}\$ where \$p\$ prime and proves that \$M(n) \le A(n)\$. The bound is tight for \$n=1, 2, 8\$. Note that this is also not a monotone function: e.g. \$A(14) < A(12)\$.

We can modify the definition of \$A(n)\$ to get a looser bound which is monotone. First observe that since \$2 - 1\$ divides any integer, we can say that \$A(n) = 2n \prod_{(p-1) \mid n} \frac{p}{p-1}\$ where the \$p\$ must be odd primes. Then the number of multiplicands of the \$\prod\$ is bounded above by \$\log_3 (n+1)\$, and each multiplicand is bounded above by \$\frac32\$, so we get \$A(n) \le 2^{1 - \log_3 (n+1)} n(n+1)\$, and since this is monotone increasing for positive \$n\$ we also have \$B(n) \le 2^{1 - \log_3 (n+1)} n(n+1)\$. This bound overestimates by a factor of about \$2.5\$ at \$n=96\$, which isn't too shabby.

To use this bound, replace .* with ..(*2*2@3base,(?/). This is what I did to get the output for n=6 and n=7 in a reasonable amount of time.

More efficient calculation

;10,{
    )..).(*2*2@3base,(?/),{
        ):N,{!}%-1+
        N,0-{
            .N\%!{
                ~${
                    1$,\:Q,-),{
                        ;.0=\
                        [.0={*}+Q%]zip
                        {{-}*}%(;\
                    }%\
                }:^~;
            }{;}if
        }/
    }/]

    (\{,(1$)<},
    3@?:k,{
        2k*+3base{(}%[`{\^0-!*}+1$?]
    },
    ,p;
}/

prints the values for \$1\$ to \$10\$, taking about 8 minutes to get to \$8\$ and 125 minutes to get to \$10\$ on my computer. It applies the theory above more directly: it computes the actual cyclotomic polynomials (filtering to only include relevant ones), and then rather than doing GCD it suffices to do a division. Thus we replace a loop per (candidate, cyclotomic) tuple with a loop per cyclotomic, and makes the remaining division per (candidate, cyclotomic) work with smaller polynomials. It also has a quick-accept which speeds up testing for the successful candidates. I'm not sure whether it's possible to golf it to beat the GCD version, even ditching some of these optimisations.


Straight Line to Text Input:

2 numbers, x and y.

Output:

Output a text block where x is the width of the text block and y is the height of the text block. Then there will be a straight line going from the top left to the bottom right and to show it, there should be a # where the line should cross.

The # should be generated using the straight line equation, y = mx + c where m is the gradient of the line which can be retrieved through making m as y divided by x. x is the current line index. c is the height intercept and can be found by multiplying the gradient by the x value and adding the y value. So, in short, it would be (y/x) * lineIndex + (y/x * x + h). This would all be rounded to the nearest position in the current line.

Rules:

there can only be 1 # per line
it has to be in the form of a string/whatever the equivalent in your language of choice. This has to be able to cover multiple lines as well.
in text block, after the # there does not need to be more spaces. Just initial ones to offset the #

Examples:

(don't mind the |, they are where the lines start and stop)

Where x is 9 and y is 1:

|        #|

Where x is 1 and y is 5:

|#|
|#|
|#|
|#|
|#|

where x is 9 and y is 5:

| #       |
|   #     |
|    #    |
|      #  |
|        #|

where x is 5 and y is 9:

|#    |
|#    |
| #   |
| #   |
|  #  |
|  #  |
|   # |
|   # |
|    #|

where x is 9 and y is 2:

|   #     |
|        #|

where x is 9 and y is 3:

|  #      |
|     #   |
|        #|

Edit: More detail in the output. Added 3rd rule. Added 5th and 6th example

Edit2: Fixed errors in the given examples (Sorry!). Revised over the output to make it much clearer v. sorry for any confusion :S

C, 74 70 bytes

Thanks to @Johan du Toit for saving 4 bytes!

i;f(x,y){for(i=y;i--;)printf("%*c\n",(int)round((i-y)/(-1.*y/x)),35);}

Try it online!


Emoticon facial expression recognition Write a program that accepts as input an emoticon and ouputs if the emoticon is happy or sad.

The program accepts a string as input or parameter, and should display the string "happy" if the input is in the happy emoticon list, or "sad" if the input is in the sad emoticon list.

You can assume the input is always a valid (happy or sad) emoticon, with no space or tabs around.

Here is a space separated list of happy emoticons:

:-) :) :D :o) :] :3 :c) :> =] 8) =) :} :^) :-D 8-D 8D x-D xD X-D XD =-D =D =-3 =3 B^D (-: (: (o: [: <: [= (8 (= {: (^:

Here is a space separated list of sad emoticons:

>:[ :-( :( :-c :c :-< :< :-[ :[ :{ 8( 8-( ]:< )-: ): >-: >: ]-: ]: }: )8 )-8

This is code-golf, so the shortest program wins.

Python, 86 bytes

I should be sent to prison.

x=lambda c: ["happy","sad"][c[0]+c[-1:]in open(__file__).read(88)[::-1]]#<][><:>{:}(:)

The shortest I could come up with was equivalent to Martin's CJam answer, so I decided I'd hide all the sad emojis (minus the middle character if any) in the reverse of my code and use Python's __file__ quine cheat.

Muahahaha.


Compute the inverse of an integer modulo 100000000003 The task is the following. Given  an integer x (such that x modulo 100000000003 is not equal to 0) presented to your code in any way you find convenient, output another integer y < 100000000003 so that (x * y) mod 100000000003 = 1.

You code must take less than 30 minutes to run on a standard desktop machine for any input x such that |x| < 2^40.

Test cases

Input: 400000001. Output: 65991902837

Input: 4000000001. Output: 68181818185

Input: 2. Output: 50000000002

Input: 50000000002. Output: 2.

Input: 1000000. Output: 33333300001

Restrictions

You may not use any libraries or builtin functions that perform modulo arithmetic (or this inverse operation).  This means you can't even do a % b without implementing % yourself. You can use all other non-modulo arithmetic builtin functions however.

Similar question

This is similar to this question although hopefully different enough to still be of interest.

Pyth, 24 bytes

L-b*/bJ+3^T11Jy*uy^GT11Q

Test suite

This uses the fact that a^(p-2) mod p = a^-1 mod p.

First, I manually reimplement modulus, for the specific case of mod 100000000003. I use the formula a mod b = a - (a/b)*b, where / is floored division. I generate the modulus with 10^11 + 3, using the code +3^T11, then save it in J, then use this and the above formula to calculate b mod 100000000003 with -b*/bJ+3^T11J. This function is defined as y with L.

Next, I start with the input, then take it to the tenth power and reduce mod 100000000003, and repeat this 11 times. y^GT is the code executed in each step, and uy^GT11Q runs it 11 times starting with the input.

Now I have Q^(10^11) mod 10^11 + 3, and I want Q^(10^11 + 1) mod 10^11 + 3, so I multiply by the input with *, reduce it mod 100000000003 with y one last time, and output.


Count the number of Hamming distance sequences The Hamming distance between two strings of equal length is the number of positions at which the corresponding symbols are different.

Let P be a binary string of length n and T be a binary string of length 2n-1.  We can compute the n Hamming distances between P and every n-length substring of T in order from left to right and put them into an array (or list).

Example Hamming distance sequence

Let P = 101 and T = 01100. The sequence of Hamming distances you get from this pair is 2,2,1.

Task

For increasing n starting at n=1, consider all possible pairs of binary strings P of length n and T of length 2n-1.  There are 2**(n+2n-1) such pairs and hence that many sequences of Hamming distances.  However many of those sequences will be identical . The task is to find how many are distinct for each n.

Your code should output one number per value of n.

Score

Your score is  the highest n your code reaches on my machine in 5 minutes.   The timing is for the total running time, not the time just for that n.

Who wins

The person with the highest score wins. If two or more people end up with the same score then it is the first answer that wins.

Example answers

For n from 1 to 8 the optimal answers are 2, 9, 48, 297, 2040, 15425, 125232, 1070553.

Languages and libraries

You can use any available language and libraries you like. Where feasible, it would be good to be able to run your code so please include a full explanation for how to run/compile your code in Linux if at all possible.

My Machine The timings will be run on my 64-bit machine. This is a standard ubuntu install with 8GB RAM, AMD FX-8350 Eight-Core Processor and Radeon HD 4250.  This also means I need to be able to run your code.

Leading answers

11 in C++ by feersum. 25 seconds.
11 in C++ by Andrew Epstein.  176 seconds.
10 in Javascript by Neil. 54 seconds.
9 in Haskell by nimi. 4 minutes and 59 seconds.
8 in Javascript by fəˈnɛtɪk. 10 seconds.

Haskell, score 9

import Data.Bits
import Data.List
import qualified Data.IntSet as S

main = mapM_ (print . S.size . S.fromList . hd) [1..9]

hd :: Int -> [Int]
hd n = [foldl' (\s e->s*m+e) 0 [popCount $ xor p (shiftR t i .&. m)|i<-[(0::Int)..n-1]] | let m=2^n-1,p<-[(0::Int)..2^n-1],t<-[(0::Int)..2^(2*n-1)-1]]

Compile with -O3. It takes 6min35s on my 6 year old laptop hardware to run up to n=9, so maybe it's under 5min on the reference hardware.

> time ./113785
2
9
48
297
2040
15425
125232
1070553
9530752

real  6m35.763s
user  6m27.690s
sys   0m5.025s


GolfScript - 67 chars

~17.'_'*n+*\153:|;{|/()[124^.2/6+:6.1&17*)\2&(*|+:|;]@++}*|/();'@'@

hallvabo's Python solution is the most similar to this, so I'll only describe the main differences.

The board is stored as a string instead of an array. This is so we can update a value on the board with less characters (as strings are always flat), and so getting it to the desired output format is easy.

The ant position is incremented by the formula ((d&1)*17+1)*((d&2)-1) (i.e. .1&17*)\2&(*), where d is the direction. We use the variable 6 so we can skip initialization.


Put the Hat in the Cat Inspired by the upcoming winter bash event
Objetive
Add a hat  ^,´ or ` to a single vowel in each word of the input.
Rules

The hat and the vowel must be chosen at random. Each hat has to appear with the same probability (33%) and the vowels must have the same probability within the valid vowels in the word (if the word have 2 valid vowels each must be 50% likely to be chosen) - or the closest that your language has.
Only AEIOUaeiouare considered vowels (sorry y)
Vowels with hats in the input DO NOT interfere with the rules (you can consider it as a consonant)
If the input has no vowel it won't be modified
Capitalization must be preserved.

Examples
winter > wintér
bash > bâsh
rhythm > rhythm
rng ftw > rng ftw
cat in the hat > cât ìn thê hát
dès > dès
tschüss > tschüss
principî > prìncipî
PROGRAMMING PUZZLES & code golf > PROGRÂMMING PÚZZLES & codé gòlf
Winning
This is code-golf so the shortest code wins

C#, 273 267 bytes

using System.Linq;A=s=>{var r=new System.Random();var a=s.Split(' ');return string.Join(" ",a.Select(w=>w.Select((c,i)=>"AEIOUaeiou".Any(d=>c==d)?i:-1).Where(x=>x>=0).ToList()).Select((l,i)=>l.Any()?a[i].Insert(l[r.Next(l.Count)]+1,""+(char)r.Next(768,771)):a[i]));};

repl.it demo

I really feels like I'm cheating, since I still add hats to already accented vowels created by combining characters. If that is not acceptable, let me know so I can add boilerplate codes declare this answer non-competing.

This thing adds a random character among U+0300 or U+0301 or U+0302, after a random vowel of each input word (if any).

Ungolfed (lambda body only)

var r=new System.Random();
// Split sentence to array of words
var a=s.Split(' ');
// Join the (hat-ed) words back to sentence
return string.Join(
    " ",
    // Select an IEnum of list of integers indicating the positions of vowels
    a.Select(w=>
        w.Select((c,i)=>
            // If it's vowel, return position (>=0), else return -1
            "AEIOUaeiou".Any(d=>c==d)?i:-1
        // Filter vowels only
        ).Where(x=>x>=0)
        .ToList()
    // Convert each list of integers to hat-ed words
    ).Select((l,i)=>
        l.Any()
            // Insert "something" into the word...
            ?a[i].Insert(
                // ...at the position after a random vowel in that word...
                l[r.Next(l.Count)]+1,
                // "something" is a random integer in [0x0300, 0x0303), then casted to UTF16 i.e. [U+0300, U+0302]
                ""+(char)r.Next(768,771))
            // List is empty => just return original word
            :a[i]));


Convert to Bibi-binary Bibi-binary is a numeric system invented by Boby Lapointe in order to represent numbers in letters which pronunciation seems funny.

Your task is to convert decimal numbers into Bibi-binary!

Conversion

A number is converted to base 16 (hexadecimal) and each character is replaced by its Bibi-binary name:

0 = HO
1 = HA
2 = HE
3 = HI
4 = BO
5 = BA
6 = BE
7 = BI
8 = KO
9 = KA
A = KE
B = KI
C = DO
D = DA
E = DE
F = DI

Let N be a positive integer (between 1 -> 2^31-1).
For every character in the hexadecimal representation of N, replace the character by its according Bibi-binary pair (the table above contains all the pairs).

Example

N = 156
H = (hexadecimal representation of N) --> 9C
9 --> KA, C --> DO

Thus the output is KADO.

Input & output

You will receive an positive 32-bit integer N, which you will have to turn into Bibi-binary.

You may (return, print, etc...) in any convenient format, but the pairs have to be connected! So KA DO wouldn't be okay, but KADO would.

Both, lowercase and uppercase are allowed.

Rules

No loopholes.
This is code-golf, so the shortest code wins.

Testcases

2048 -> KOHOHO
156 -> KADO
10000 -> HEBIHAHO
12 -> DO

Python 2, 58 bytes

f=lambda n:(n>15and f(n/16)or"")+"HBKD"[n/4%4]+"OAEI"[n%4]

A recursive solution. Try it on Ideone.


Am I outgolfed by Dennis? According to legend, almost everyone is outgolfed by Dennis. If not, they will be.

Now I'm curious if I'm one of those 'almost everyone'.

You will be given a link to an answer in the format of https://codegolf.stackexchange.com/questions/[QUESTION ID]/[QUESTION NAME]/#[ANSWER ID].

Find the length of the code, which we will assume as the last number on the first line (markdown wise) of the answer in the link.

Then, search for Dennis' answers, and do the same.

Now compare the input's and Dennis' answers code length, and if it is out-golfed (meaning one or more answer of Dennis' is shorter than that of the input answer), output a truthy value, and if not, a falsy value.

If there is no answer belonging to Dennis on the same question as the answer, output a falsy value.

Examples

Link : true
Link : false (At least for now, tell me when it changes)

Rules

You may use any form of truthy/falsy value.
The question of the answer you're given will always be code-golf.
The question may not have an answer of Dennis', but the inputted answer will never belong to Dennis.
You may assume there is always a number on the first line of the answer.

Python 3.6 + requests + bs4 - 363 358 bytes

import bs4,re,requests
u,n=input().split("/#");i=1;d=y=float("inf")
while i:
 A=bs4.BeautifulSoup(requests.get(u+f"?page={i}").text,"html.parser")(class_="answer")
 for a in A:
  c=int(re.findall("\d+",(a("h1")+a("h2")+a("p"))[0].text)[-1])
  if "Dennis"in a(class_="user-details")[-1].text:d=min(c,d)
  if a["data-answerid"]==n:y=c
 i=A and i+1;
print(d<y)

Prints True or False.

Note: does not currently work on the second link because of invalid HTML produced by this answer (the em and strong tags are terminated in the wrong order at the end of the second line, and causes the parser to miss the username block). Try it on this link instead.

Using the API - 401 380 bytes

import requests,re
q,A=re.findall("\d+",input());i=1;d=y=float("inf")
while i:
 r=requests.get(f"https://api.stackexchange.com/2.2/questions/{q}/answers?site=codegolf&filter=withbody&page={i}").json();i=r["has_more"]and i+1
 for a in r["items"]:
  c=int(re.search("(\d+)\D+$",a["body"]).group(1))
  if a["owner"]["user_id"]==12012:d=min(d,c)
  if a["answer_id"]==A:y=c
print(d<y)

Note that this also fails on the second link, but because one answer started with This may be foul play. instead of the header...


Is my Graph Graceful? A Graceful Graph is a type of Simple Graph.  Graceful graphs are special because there is a way to label all their nodes with positive integers so that when the edges are also labeled with the differences of the nodes they connect, no two edges have the same label and every label up to the number of edges is used.
Worked Out Example
Here is a Simple graph that we suspect is a Graceful graph

Let us try the following labeling:

Note we are permitted to skip integers in our node labeling.  Now we label every edge with the positive difference between the nodes it connects.  For increased visibility I have labeled these in red.

Each edge has a unique number and no number between between 1 and 7 (the number of edges we have) is left out.  Thus our graph is graceful.
Task
Given a graph, via any reasonable method of input, output a truthy value if it is graceful and a falsy value otherwise.
This is code-golf so the objective is to minimize your byte count.
Test Cases
Here graphs are represented as an array of edges:
3 nodes:

[(0,1),(0,2),(1,2)]

True

Labeling:

Node 0 -> 0
Node 1 -> 2
Node 2 -> 3

5 nodes:

[(0,1),(0,4),(1,2),(2,3),(3,4)]

False

5 nodes:

[(0,1),(1,2),(2,3),(3,4)]

True

Labeling:

Node 0 -> 0
Node 1 -> 1
Node 2 -> 3
Node 3 -> 6
Node 4 -> 10

9 nodes

[(0,1),(1,2),(1,7),(1,8),(2,3),(2,6),(3,4),(4,5)]

True

Labeling:

Node 0 -> 0
Node 1 -> 1
Node 2 -> 3
Node 3 -> 6
Node 4 -> 10
Node 5 -> 15
Node 6 -> 11
Node 7 -> 7
Node 8 -> 8

5 nodes

[(0,1),(0,2),(1,2),(1,3),(1,4),(3,4)]

False

Jelly, 12 bytes

FSŒ!ị@€ḅ-AċJ

Takes an array of edges as 1-indexed node pairs.

Try it online! (Horrendously inefficient. Don't bother with the actual test cases.)

How it works

FSŒ!ị@€ḅ-AċJ  Main link. Argument: A (array of pairs)

FS            Flatten and sum, yielding s. This is an upper bound for the labels
              a graceful labeling (if one exists) would require.
  Œ!          Take all permutations of [1, ..., s].
      €       For each permutation P:
    ị@          Replace each integer in A with the element of P at that index.
       ḅ-     Convert all pairs from base -1 to integer, mapping (a,b) to b-a.
         A    Take absolute values.
           J  Yield the indices of A, i.e., [1, ..., len(A)].
          ċ   Count the occurrences of [1, ..., len(A)] in the result to the left.


Secret ">" Stacking Challenge: grading Background
Tetris Grand Master 3 has a hidden grading system based on the shape of the stack at the end of the game, which is called Secret ">" Stacking Challenge. It consists of entirely filling the lowest rows except for the zigzag pattern which starts at the left bottom cell and spans the entire width:
#
.#########
#.########
##.#######
###.######
####.#####
#####.####
######.###
#######.##
########.#
#########.
########.#
#######.##
######.###
#####.####
####.#####
###.######
##.#######
#.########
.#########

The board is graded by how many lines follow this exact pattern from the bottom line. Note that the topmost hole in the pattern must be blocked by an extra piece of block. If you consider the #s and .s as the mandatory pattern (blanks can be anything), you can get the score of 19 only if the exact pattern above is matched from the bottom line. Analogously, if the board matches this pattern
   #
###.######
##.#######
#.########
.#########

but not
    #
####.#####
###.######
##.#######
#.########
.#########

then the score is 4.
For this challenge, consider a board of arbitrary size (other than 20 cells high and 10 cells wide). We can grade the board for the same pattern: for example, if the board has width 4, this is the pattern for score 3:
  #
##.#
#.##
.###

and this is the pattern for score 10:
   #
###.
##.#
#.##
.###
#.##
##.#
###.
##.#
#.##
.###

Challenge
Given the final state of the Tetris board of arbitrary size, grade the board using the system above.
You can take the board using any sensible format for a rectangular matrix, where every cell contains one of two distinct values (for empty and filled respectively). You can assume the grid is a valid Tetris board (no row is entirely filled). Also, the width of the grid is at least 2.
Standard code-golf rules apply. The shortest code in bytes wins.
Test cases
In order to prevent possible confusion, the test cases here use O for the blocks and . for empty spaces.
Input:
..O.O
OOOO.
OOO..
OO.OO
O.OOO
.OOOO
Output: 3

Input:
..
O.
.O
.O
O.
.O
O.
.O
Output: 4

Input:
.OOO
O.OO
OO.O
OO.O
OO.O
O.OO
.OOO
Output: 2 (any lines above the first non-conforming line are ignored;
           doesn't get 3 because 3rd line's hole is not capped)

Input:
OOO.
.OOO
O.OO
OO.O
OOO.
OO.O
O.OO
Output: 0 (Wrong starting hole)

Input:
.OOO
O.OO
OO.O
OOO.
Output: 0 (Wrong starting hole)

Input:
.OOO
.OOO
Output: 0 (Hole is not covered)

Input:
OOO...O..O
.OOOOOOOOO
O.OOOOOOOO
OO.OOOOOOO
OOO.OOOOOO
OOOO.OOOOO
OOOOO.OOOO
OOOOOO.OOO
OOOOOOO.OO
OOOOOOOO.O
OOOOOOOOO.
OOOOOOOO.O
OOOOOOO.OO
OOOOOO.OOO
OOOOO.OOOO
OOOO.OOOOO
OOO.OOOOOO
OO.OOOOOOO
O.OOOOOOOO
.OOOOOOOOO
Output: 19

Husk, 18 bytes
Lδ↑€…¢ŀT¹↑εΨ↑-↔m¥0

Try it online!
Takes a 0-1 matrix.
Explanation
There are three occurrences of ↑ in this program, and they all work differently thanks to the modifier functions δ and Ψ.
By default, ↑α expects α to be a unary function, takes a list and returns the longest prefix of elements for which α returns a truthy value.
Ψ↑α expects α to be binary, and returns the longest prefix of elements x for which α x y is truthy, where y is the next element.
δ↑α expects α to be binary and takes two lists instead of one.
It returns the longest prefix of the second list whose elements y satisfy α x y, where x is the corresponding element of the first list.
Input is a list of lists of integers.
Example: [[0,1,1],[1,0,1],[1,1,0],[1,0,1],[1,1,0],[0,0,1],[0,1,1]]

m     Map
 ¥0   indices where 0 occurs:
        [[1],[1,2],[3],[2],[3],[2],[1]]
↔     Reverse:
        [[1],[2],[3],[2],[3],[1,2],[1]]

 ↑    Take while
Ψ     this element and the next
  -   have nonempty set difference:
        [[1],[2],[3],[2],[3],[1,2]]

↑     Take while
 ε    this element is a singleton:
        [[1],[2],[3],[2],[3]]
      Call this list X.

ŀT¹   Indices of input transposed:
        [1,2,3]
¢     Cycle infinitely:
        [1,2,3,1,2,3,..]
…     Rangify:
        [1,2,3,2,1,2,3,2,1,..]
 ↑    Take from X while
δ     the corresponding integer in this list
  €   is an element of it:
        [[1],[2],[3],[2]]
L     Length: 4


determine longest group of consecutive numbers INPUT:

10 random numbers
each number is greater than 0 and less than 100
list of numbers is presorted, lowest to highest
the list will not contain any duplicate numbers

CHALLENGE:

Write a function that would take in the numbers, and return the count of the longest group of consecutive numbers.

EXAMPLE OUTPUT:

1 2 33 44 55 66 77 88 90 98 => return of the function would be 2
1 3 23 24 30 48 49 70 75 80 => return of the function would be 2
6 9 50 51 52 72 81 83 90 92 => return of the function would be 3

APL, 26 21 characters

1+⌈/+/^\9 9⍴0,1=-2-/⎕

Here's the 26-character solution:

i←⎕⋄⌈/{1++/^\⍵↓1=-2-/i}¨⍳9

I used Dyalog APL as my interpreter, and ⎕IO should be set to 0 for the 26-character version.

Example:

      1+⌈/+/^\9 9⍴0,1=-2-/⎕
⎕:
      6 7 51 51 53 51 54 55 56 55
3

This answer explains most of what I in the 26-character solution, but I might have to write a new one up for the 21-character version.


Translate English Characters to the Emoji Flag Alphabet Introduction

Emoji use a particular alphabet for their national flags, which allows one to put two symbols together to create the appropriate flag.

Your challenge, is to transform any uppercase letter into the appropriate Flag Identifier.

This may be much harder for languages that do not innately handle Unicode.
Each symbol is exactly 4 UTF-8 Bytes.

The Task

Given an input as one or more letters, output the same, with all letters replaced with their flag combinations.

Winner is the answer with the least Bytes, giving the tiebreaker to first answer posted.

Input / Output

Input and Output may use any standard method.
Letters in the input may optionally only support one case, Upper or Lower. Please specify in your answer what case your solution supports.

Your output may, intentionally or otherwise, output flag emoji instead of letter pairs.

Test Cases

FR

Hello, World! , !

Rules

Standard Loopholes Apply
Standard Input Output allowed
This is code-golf, however, All the Emoji Letters as provided above can be counted for a single byte each, instead of four. Least Bytes wins!

Pyth - 18 16 bytes
Supports lowercase.
XzGsCMrF+BC\26

Test Suite.


Code golf: Distributing the balls (I) Challenge

  In this task you have compute the number of  ways we can
  distribute A balls into B
  cells with with every cell
  having at-least one ball.

The inputs A and B are given in a single line separated by a blank,the inputs are terminated by EOF.

You may like to check your solutions here.

Input

0 0
1 0
12 4
6 3
18 17
20 19
15 13
18 9
20 20
17 14
9 2
14 13
18 11

Output

1
0
14676024
540
54420176498688000
23112569077678080000
28332944640000
38528927611574400
2432902008176640000
21785854970880000
510
566658892800
334942064711654400

Constraints

Every A and B can be distinguishable.
0 <= A,B <= 20
You can use any language of your choice
Shortest solution wins!

JavaScript (90 93)

function f(a,b){n=m=r=1;for(i=b;i>0;n*=-1){r+=n*m*Math.pow(i,a);m=m*i/(b-i--+1)}return--r}

http://jsfiddle.net/RDGUn/2/

Obviously, any math-based language such as APL will beat me because of syntax verbosity and lack of built-in mathematical constructs :)

Edit Also, I don't have any input-related functionality  except parameters passed into the function, not sure how to use standard input with JavaScript...

Edit: Move i-- into m=m* expression; move n*=-1 into for; start r=1 to  combine assignments and remove extraneous one on return. (save 3 chars)


Insta-Name... Just Add Coder! In the English language, a surefire way to make a pronounceable nonsense letter combination is to make it entirely out of consonant-vowel pairs, e.g., Wu ko pa ha, or, Me fa ro, consonant first, followed by vowel.

Challenge:

Write a program or function that will, given a user-specified number of letters, create a random name using this principle. It's that simple.

Input:

An integer greater than or equal to 2 which designates the required number of letters in the output. Input can be taken from STDIN, command line arguments, or function arguments.

Output:

A string of the given length containing randomly selected consonant-vowel pairs. It can be printed to STDOUT or closest alternative or returned in the case of a function.

Rules:

Each consonant of the English alphabet should have equal probability of being selected for the first character of each pair, and each vowel of the English alphabet should have equal probability of being selected for the second character of each pair.
Letter pairs may be repeated.
Since this is a name, the first letter must be capitalized.
If the input is odd, a randomly selected letter pair in the name should have y or h appended to the end. The choice of y or h should be random as well.
Standard loopholes are not permitted.
Smallest code in bytes wins.

Letter definitions:

Consonants:

bcdfghjklmnpqrstvwxyz

Vowels:

aeiou

Example I/O:

Input: 6
Output: Mefaro

Input: 9
Output: Wukohpaha

Enjoy!

JavaScript ES6, 187 180 168 bytes

f=l=>{r=m=>Math.random()*m|0
d=l%2&&r(--l/2)*2+1
for(s='';l--;s+=s?a:a.toUpperCase())a=l%2?'bcdfghjklmnpqrstvwxyz'[r(21)]:'aeiou'[r(5)]+(l==d-1?'hy'[r(2)]:'')
return s}

Edit: I switched from using regex replace to a simple for loop, which improved the length considerably. Ungolfed code and test UI below. Input a negative number at your own risk because it makes an infinite loop. (Thanks to unclemeat for pointing that out.)

f=function(l){
  // Function to return a random integer between 0 and m-1 inclusive
  r=function(m){
    return Math.random()*m|0
  }
  // d is the position the h or y will be added
  // l is decremented only if l is odd so an extra consonant won't be added to the end
  d=l%2&&r(--l/2)*2+1

  for(s='';l--;){
    a=l%2?'bcdfghjklmnpqrstvwxyz'[r(21)]:'aeiou'[r(5)]+(l==d-1?'hy'[r(2)]:'')
    // If `s` is empty (i.e. this is the first leter), make it uppercase
    s+=s?a:a.toUpperCase()
  }
  return s
}

run=function(){ip=parseInt(document.getElementById('input').value);if(ip<2)return alert('Input must be greater than one.');document.getElementById('output').innerHTML=f(ip)};document.getElementById('run').onclick=run;run()
<input type="number" id="input" value="7" min="2" /><button id="run">Run</button>


The Reaction Time Game Game

The game is simple. Test the user's response time by asking them to enter the correct value that is displayed on the screen in the shortest time possible. Each round of the game will be as follows:

  Show Value ----> Get Response ----> Check Response ----> Report Response Time

Example

ROUND ONE
---------
COMPUTER : G
USER     : G
CORRECT INPUT, TIME = 0.26 SECONDS

Code

You may use any language or program.
Do not use third party libraries, except GUI libraries.
(as suggested by marinus)
You may choose between CLI and GUI.

Points

+12 for the shortest code
-2 for every byte after the 1024th byte
+8 for GUI
+8 for showing questions (eg: 4 + 2 = ?) (rather than static values shown in the example above. There must be at least 10 questions.)
+2 for random intervals between each round
+4 for reporting average response time (in a set of 10 rounds)
+4 for quickly vanishing questions/values
(questions/values stays on screen only for a short interval of time. The vanish time must be less than or equal to 1 seconds.)

  You must, in your answer, calculate the total points you have scored. eg (+12 (-2x3) +4 = 10)

JavaScript, ES6 352 340 335 bytes, Potential score : 2 + 8 + 12 + 4 + 4 + 8 = 38
<script>r=Math.random,s=setTimeout;T=N=0;a=_=>(S=s(_=>(C=eval(G.innerHTML=((k=~~(r()*5))+~~(r()*5))+'-'+k),t=new Date,R=s(_=>C=G.innerHTML=a(clearTimeout(S)),r()*1e3)),r()*2e3+1e3),'');document.onkeyup=E=>{clearTimeout(R);E.key==C&&++N&&(T+=(X=new Date-t))&&alert([X,N%10?'':T/10]);C=G.innerHTML=a(N%10||(T=0))};a()</script><a id='G'/>

or try this JSFiddle on latest Firefox.
Working:

Shows a random question in form of X-Y after a random interval of [2,4] seconds.
Waits for a keypress till a random time in an interval of [1,2] seconds, after which, clears the input and moves to step 1.
If correct number is pressed, alerts the time in milliseconds.
If this is the tenth (or rather every tenth) correct answer, show the average time in milliseconds for the last 10 correct answers after a comma.
Empties the input area, goes to Step 1 again.

Please comment if something is incorrect or if you have any doubts.


Minimum number of numbers to sum to exactly n First question here, don't yell at me if this is a duplicate or a bad challenge.

Introduction

I thought of this challenge myself, and it seems to be a good basic puzzle for beginner code-golfers. It also might help me decide which code-golfing language to learn.

Challenge

Given an array of integers that are less than or equal to n, output or return the minimum number of numbers from the array that sum up to exactly n.

You can choose to write a function or a full program.

Input

You can safely assume 0 <= n < 2^31.

Take an array or list of any kind (vector for C++ or Java's LinkedList are allowed), along with n and an optional parameter length, which specifies the length of the array.

You can also take the input as a space-separated string, separated from n by either a comma or a space:

1 5 7 3 7 3 6 3 2 6 3,10

1 5 7 3 7 3 6 3 2 6 3 10

if it is easier.

Output

Output, or return the minimum number of numbers from the array that sum up to exactly n. Using the above example:

1 5 7 3 7 3 6 3 2 6 3,10

Your program should print:

2

because the minimum number of numbers that sum up to 10 is 2 (7 and 3).

In the case that there is no solution, print or return either a negative, 0, "No solution" (though that would not be smart), ∞ (as suggested), or any other falsy value, with the exception of an empty string.

Example Input and Output

Input:

1 5 7 3 7 3 6 3 2 6 3,10
143 1623 1646 16336 1624 983 122,18102
5 6 9,12

Output:

2
3
-1

Scoring

This is code-golf, so shortest code in bytes wins.

The top answer will be accepted on Christmas.

Pyth, 12 11 bytes
lhafqsTQyEY

This takes n as the first line of input and the list on the second line.
lhafqsTQyEY     (Implicit: Q = 1st line of input; E = 2nd line)
         E      The list
        yE      Powerset (sorted by increasing length; empty set first)
   f            Filter by lambda T:
     sT         sum(T)
    q                  ==
       Q                  Q
   fqSTQyE      Sublists that sum to Q, sorted by increasing length
  a       Y     append an empty array (in case none match)
lh              take the length of the first element (0 for empty array)

Try it here.


C: Output "tomorrow's date" I'm a code golf novice, but I'm eager to give it a go.

My challenge is: Write the shortest program in C which takes in a date D as input and outputs the date D + 1 day

Rules:

program must compile only with gcc progname.c -o progname So no compiler/makefile tricks (if there are any) - compiler warnings don't matter
The input and output format must be day/month/year zero padding of single digit values does not matter: 1/3/1998 is equal to 01/03/1998
It doesn't matter how you give the the program it's input date, it can be a program argument, scanf whatever. Output must be to stdout however
February has 29 days when the year is divisible by 4
No date validation necessary, i.e. assume the input is always a valid date.
any integer year should be supported, i.e. INT_MIN -> INT_MAX

Shortest code length wins, and there are extra points for extra bastardised C.

My solution uses 126 123* 121 characters

Good luck

*s="%i/%i/%i",m,d;main(y){scanf(s,&d,&m,&y);printf(s,d,m,(d=d%((m>7^m&1)+27+(m-2?3:y%4?1:2))+1)-1?y:(m=m%12+1)-1?y:y+1);}

*because of an idea Gareth's code gave me

Okay, it's been a while since I wrote any C but I'll give it a go:

m,y,*q="%d/%d/%d";
main(d){
scanf(q,&d,&m,&y);
++d>30+(m+(m>7))%2-(m^2?0:2-!(y%4))?(m+=d=1)>12?y+=m=1:0:0;
printf(q,d,m,y);}

120 characters.
With a bit of formatting(not that it makes it any more readable any more...):

m,y,*q="%d/%d/%d";
main(d)
{
    scanf(q,&d,&m,&y);
    ++d>30+(m+(m>7))%2-(m^2?0:2-!(y%4))?(m+=d=1)>12?y+=m=1:0:0;
    printf(q,d,m,y);
}

The compiler throws out warnings like nobody's business, but it works.

I'm not sure I can get it any smaller than this now without stealing a couple of tricks from Griffin. With those tricks I can get to 116 characters:

m,y,*q="%d/%d/%d";
main(d){
scanf(q,&d,&m,&y);
printf(q,d,m,++d>30+(m>7^m&1)-(m^2?0:2-!(y%4))?(m+=d=1)>12?y+=m=1:y:y);}


C.U.S.R.S - The Completely Useless String Refactoring System! Introduction

I'm a real big fan of the SBU (Short But Unique) challenges that crop up on PPCG all of the time. The CUSRS is a system designed to refactor strings, a CUSRS function takes 2 parameters and outputs 1 String.

Challenge

Produce a program, function, lambda or acceptable alternative to do the following:

Given String input and String refactor (as examples), refactor input using refactor as follows:

The refactor String will be in the format of ((\+|\-)\w* *)+ (regex), for example:

+Code -Golf -lf +al

Each section is a refactoring action to perform on input. Each program also has a pointer.

+ Will insert it's suffix (without the plus) at the pointers current location in the String and then reset the pointer to 0.

Each operation should be applied to the input String and the result should be returned.

Example:

input:
Golf +Code //pointer location: 0

output:
CodeGolf //pointer location: 0

- Will increment the pointer through the String until it finds the suffix. The suffix will be removed from the String and the pointer will be left on the left side of the removed text.  If no suffix is found the pointer will simply progress to the end of the String and be left there.

input:
Golf -lf //pointer location 0

output:
Go //pointer location 2

Examples

input:
"Simple" "-impl +nip -e +er"

output:
"Sniper"

input:
"Function" "-F +Conj"

output:
"Conjunction"

input:
"Goal" "+Code -al +lf"

output:
"CodeGolf"

input:
"Chocolate" "Chocolate"

output:
"Chocolate" //Nothing happens...

input:
"Hello" "-lo+p        +Please" //Spaces are irrelevant

output:
"PleaseHelp"

input:
"Mississippi" "-s-s-i-ppi+ng" //Operations can be in any order

output:
"Missing"

input:
"abcb" "-c -b +d"

output:
"abd"

input:
"1+1=2" "-1+22-=2+=23"

outut:
"22+1=23"

Example Code

The example is Java, it's not golfed at all.

public static String refactor(String input, String swap) {
    int pointer = 0;
    String[] commands = swap.replace(" ", "").split("(?=[-+])");

    for (String s : commands) {
        if (s.startsWith("+")) {
            input = input.substring(0, pointer) + s.substring(1) + input.substring(pointer, input.length());
            pointer = 0;
        } else {
            if (s.startsWith("-")) {
                String remove = s.substring(1);
                for (int i = pointer; i < input.length(); i++) {
                    if (input.substring(i, i + remove.length() > input.length() ? input.length() : i + remove.length()).equals(remove)) {
                        pointer = i;
                        input = input.substring(0, i) + input.substring(i + remove.length(), input.length());
                        break;
                    }
                }
            }
        }
    }

    return input;
}

Rules

Standard Loopholes Apply
Shortest code, in bytes, wins

Python 3 (164 194 186 181 168 165 bytes)

p=0
w,*x=input().split()
for i in x:
 if '-'>i:w,p=w[:p]+i[1:]+w[p:],0
 else:
  try:p=w.index(i[1:],p)
  except:p=len(w)
  w=w[:p]+w[p:].replace(i[1:],'',1)
print(w)

Example demonstrating the pointer moving to the end if it doesn't find a substring:

Input: HelloThere -x +Friend
Output: HelloThereFriend

Special thanks to Artyer for saving me 13 bytes.

Another thanks to Artyer for saving me another 3 bytes via the beg parameter of index.

Old answer:

p=0
x=input().split()
w=x[0]
for i in x[1:]:
 if i[0]=='+':
  w=w[:p]+i[1:]+w[p:]
  p=0
 else:
  p=w[p:].index(i[1:])+p
  w=w[:p]+w[p:].replace(i[1:],'',1)
print(w)

Example demonstrating the pointer works (all the examples in the Q work even if you don't factor in the pointer and simply replace on first occurence):

Input: HelloThereCowboy -r -e -y +ySays +Oh
Output: OhHelloTheCowboySays

Edit: Since 2 minutes ago my answer is now invalid according to a comment by the asker.

  aaa -b +b would result with aaab because the pointer would go all the
  way to the end.

Edit2: Fixed.


Convert a 32 bit binary IPv4 address to its quad-dotted notation Challenge

Write a program or function that converts a 32 bit binary number to its quad-dotted decimal notation (often used for representing IPv4)

Quad-dotted decimal

A quad-dotted decimal is formed like so:

Split the binary representation into its 4 individual bytes
Convert each byte into denary
place "." between each number

Example:

input:  10001011111100010111110001111110
step 1: 10001011 11110001 01111100 01111110
step 2:    139      241      124      126
step 3: 139.241.124.126

I/O examples

input --> output

10001011111100010111110001111110 --> 139.241.124.126
00000000000000000000000000000000 --> 0.0.0.0
01111111000000000000000000000001 --> 127.0.0.1
11000000101010000000000111111111 --> 192.168.1.255

Rules

Input will always be a 32 bit binary number or a binary list or string
Standard I/O rules apply
No standard loopholes
This is code-golf, so the shortest answer in bytes wins

x86-16 machine code, IBM PC DOS, 54 47 45 bytes
Binary:
00000000: be82 00b3 04b1 08ac d0d8 d0d4 e2f9 8ac4  ................
00000010: 41d4 0a50 8ac4 84c0 75f6 580c 30b4 0ecd  A..P....u.X.0...
00000020: 10e2 f74b 7406 b02e cd10 ebd9 c3         ...Kt........

Build and test BIN2IP.COM using xxd -r from above.
Unassembled listing:
BE 0082     MOV  SI, 82H        ; command line input address
B3 04       MOV  BL, 4          ; loop 4 bytes
        BYTE_LOOP:
B1 08       MOV  CL, 8          ; loop 8 bits
        BIT_LOOP:
AC          LODSB               ; load next bit char into AL
D0 D8       RCR  AL, 1          ; put LSB of char into CF
D0 D4       RCL  AH, 1          ; put CF into LSB of byte value, then shift left
E2 F9       LOOP BIT_LOOP       ; continue bit loop
8A C4       MOV  AL, AH         ; put byte result into AL
        GET_DIGIT:
D4 0A       AAM                 ; byte divide by 10, AH = AL / 10, AL = AL % 10
50          PUSH AX             ; save remainder in AL on stack
8A C4       MOV  AL, AH         ; put quotient back into AL
41          INC  CX             ; increment decimal digit count
D4 C0       TEST AL, AL         ; quotient = 0?
75 F6       JNZ  GET_DIGIT      ; if not, continue looping
        PRINT_DIGIT:
58          POP  AX             ; restore digit in AL
0C 30       OR   AL, '0'        ; ASCII convert
B4 0E       MOV  AH, 0EH        ; BIOS write char function
CD 10       INT  10H            ; write to console
E2 F7       LOOP PRINT_DIGIT    ; loop until done
4B          DEC  BX             ; is last byte?
74 06       JZ   END_LOOP       ; if so, don't display a '.'
B0 2E       MOV  AL, '.'        ; otherwise display '.'
CD 10       INT  10H            ; write to console
        END_LOOP:
75 D7       JNZ  BYTE_LOOP      ; continue byte loop
C3          RET                 ; exit to DOS

Output:

A standalone PC DOS executable.  Input is command line, output to console.
Notes:
The "interesting part" (converting binary string to bytes) is about 15 bytes, whereas the rest of code is writing the itoa() function to convert binary bytes into a decimal string representation for display.

-2 bytes eliminating unnecessary PUSH/POP thx to @PeterCordes!


Count the number of fields in each csv record Imagine a text file where each  csv record may have different numbers of fields.   The task is to write code to output how many fields there are in each record of the file. You can assume there is no header line in the file and can read in from a file or standard input, as you choose.

You can assume a version of rfc4180 for the csv rules which I will explain below for the definition of each line of the file.  Here is a lightly edited version of the relevant part of the spec:

Definition of the CSV Format

Each record is located on a separate line, delimited by a line
   break (CRLF).  For example:

aaa,bbb,ccc CRLF
zzz,yyy,xxx CRLF
The last record in the file may or may not have an ending line
   break.  For example:

aaa,bbb,ccc CRLF
zzz,yyy,xxx

(Rule 3. does not apply in this challenge)

Within each record, there may be one or more
   fields, separated by commas.   Spaces are considered part
   of a field and should not be ignored.
Each field may or may not be enclosed in double quotes.  If fields are not enclosed with double quotes, then double quotes may not appear inside the fields.  For example:

"aaa","bbb","ccc" CRLF
zzz,yyy,xxx
Fields containing line breaks (CRLF), double quotes, and commas
   should be enclosed in double-quotes.  For example:

"aaa","b CRLF
bb","ccc" CRLF
zzz,yyy,xxx
If double-quotes are used to enclose fields, then a double-quote
   appearing inside a field must be escaped by preceding it with
   another double quote.  For example:

"aaa","b""bb","ccc"

Example

Input:

,"Hello, World!"
"aaa","b""bb","ccc"
zzz,yyy,
"aaa","b
bb","ccc","fish",""

Should give the output:

2, 3, 3, 5

Your can give the output values in any way you find most convenient.

Libraries

You can use any library you like.

Awesome answers so far but we are missing a command line/bash answer which would be particularly cool.

Stax, 19 12 bytes

èJ§3‼}vAà○L>

Run and debug it

Unpacked, ungolfed, and commented, it looks like this.

_'"/    split *all* of standard input by double quote characters
2::     keep only the even numbered elements
|j      split on newlines (implicitly concatenates array of "strings")
m       for each line, execute the rest of the program and output
  ',#^  count the number of commas occurring as substrings, and increment

Run this one


Loops and Loops and Loops The Challenge

Create a function that, when given an input of ASCII art (directing a path that may eventually loop), outputs the length of the loop (if there is one) and the length of the "tail" leading into the loop in one of the forms below.

Input

Your input must be passed to a function. Below is an example of a simple input.

# --> # --> #
      ^     |
      |     |
      |     v
      # <-- #

You could visualize the above blocks like this

The "tail" is one item, while the loop is four long.

A more difficult one:

            # --> # --> #
            ^           |
            |           |
            |           v
      # --> # <-- #     # --> #
      ^           ^           |
      |           |           |
      |           |           v
# --> #           # <-- # <-- #

Output

You must output through STDOUT or your language's closest alternative.

Your two output integers should be the length of the tail and the length of the loop. This output can be in two forms.

a space-delimited string: "2 10"
an array of integers: [2, 10]

Rules

Every block, or #, will only have a single path away from itself.
Every arrow is two line segments and one head.
The starting block will always be in the leftmost column.
The input will never be just a loop.

Example

# --> # --> # --> #
^     ^           |
|     |           |
|     |           v
#     # <-- # <-- #

This one has a tail length of 2 and a loop length of 6. Below, the tail and loop are separated.

Tail

# -->
^
|
|
#

Loop

# --> # --> #
^           |
|           |
|           v
# <-- # <-- #

The correct outputs are [2, 6] and "2 6".

If the input is only a tail, the loop length is zero.

# --> # --> # --> #
                  |
                  |
                  v
        <-- # <-- #

The correct outputs for the above input are [6, 0] and "6 0"

JavaScript (ES6), 221 229

A function with the input as a parameter, output as a string via popup window (alert).

Scan repeatedly the input:
at each step

remove the end of the tail
count the remaining '#'

When there is not more tail to remove, the number of the steps so far is the size of the tail and the number of remaining '# is the size of the loop.

All the newlines inside backticks are significant and counted

Test running the snippet below with Firefox (not Chrome, as it does not support ...)

F=s=>{s=`

${s}

`.split`
`.map(r=>[...r]);for(t=0,f=1;f;)s.map((r,y)=>r.map((c,x)=>c=='#'&&((r[x+2]+r[x-2]+s[y-1][x]+s[y+1][x]).match`[v<>^]`?++l:t+=(f=r[x-4]=r[x+4]=s[y-3][x]=s[y+3][x]=r[x]=1))),f=l=0);alert(t+' '+l)}

// Less golfed
U=s=>{
  s=`\n\n\n${s}\n\n\n`.split`\n`.map(r=>[...r])
  t=0
  do {
    f=l=0
    s.forEach((r,y) => {
      r.forEach((c,x) => {
        if (c == '#')
        {
          if (!(r[x+2] == '<' || r[x-2] == '>' || s[y-1][x] == 'v' || s[y+1][x] == '^'))
            t+=(f=r[x-4]=r[x+4]=s[y-3][x]=s[y+3][x]=r[x]=1)
          else
            ++l
        }
      })
    })
  } while(f)
  alert(t+' '+l)
}

//Test

// Redefine console.log
alert=(...x)=>O.innerHTML+=x+'\n'

test=[`
# --> # --> #
      ^     |
      |     |
      |     v
      # <-- #`
,`
            # --> # --> #
            ^           |
            |           |
            |           v
      # --> # <-- #     # --> #
      ^           ^           |
      |           |           |
      |           |           v
# --> #           # <-- # <-- #`
,`
# --> # --> # --> #
^     ^           |
|     |           |
|     |           v
#     # <-- # <-- #`
]

test.forEach(t=>(alert(t),F(t)))


Fast Trig Calculation Fast Trigonometry Calculations

Your task is to create a program which can calculate the sine, cosine and tangent of an angle in degrees.

Rules

No built-in trigonometry functions (not even secant, cosecant and cotangent if your language has them).
You may use lookup tables, but their total size must not exceed 3000 members (for all of the three operations put together). Please make it read the tables from a file (e.g. trig.lookup) so they don't confuse the code.
No network access.
You must correctly round your output as explained below. Don't use floor or ceiling.
You may use any method to calculate the values, for example continued fractions, as long as it is correct to 7 significant figures.
Your code must be able to time itself. Exclude the file I/O operations from your time - so just time the function(s) that do(es) the trig and any rounding.
I must be able to run your code. Please post a link to a freely available compiler/interpreter and give the instructions needed to compile/run the code (e.g. what options to pass to GCC).
Standard loopholes apply.

Input Format

Read from a file called trig.in unless your language doesn't support file I/O.
Angles are between 0 and 360 inclusive.
Input will consist of angles to ten significant figures in decimal digits, separated by new lines. For example:

  90.00000000
  74.54390000
  175.5000000

Output Format

For each angle supplied, you must output its sine, cosine and tangent to 7 significant figures, separated by spaces, on a single line. Use "scientific notation", e.g. 1.745329E-5 for tan 0.001 or 1.000000E+0 for sin 90.
Denote infinity or NaN by n, for example the output for 90.00000000 should be 1.000000 0.000000 n.
If the input is three angles separated by newlines, your output should consist of three lines, each containing the sine, cosine and tangent.
You may not output anything else.
Output to a file called trig.out unless your language does not support file I/O.

Scoring

fastest-code. The challenge is to write a program which computes these three values as quickly as possible. Fastest time wins.
Everyone will receive the same test input of many angles.
Times will be recorded on my machine.
Your score is the average of three runs on the same input (you can't save anything in between runs obviously).
Compiling time not included. This challenge is more about the method used than the language. (If someone could point me to how I would exclude compilation time for languages such as Java, I'd be very grateful)
My machine is an Ubuntu 14.04 install. The processor's stats are on Pastebin (obtained by running cat /proc/cpuinfo).
I will edit your time into your answer when I've tested it.

Fortran 90

I employ the CORDIC method with a pre-tabulated array of 60 arctan values (see Wiki article for details on why that's necessary).

This code requires a file, trig.in, with all the values on newlines to be stored in the same folder as the Fortran executable. Compiling this is,

gfortran -O3 -o file file.f90

where file is whatever filename you give it (probably SinCosTan.f90 would be easiest, though it's not necessary to match program name and file name). If you have the Intel compiler, I'd recommend using

ifort -O3 -xHost -o file file.f90

as the -xHost (which doesn't exist for gfortran) provides higher level optimizations available to your processor.

My test runs were giving me about 10 microseconds per calculation when testing 1000 random angles using gfortran 4.4 (4.7 or 4.8 is available in the Ubuntu repos) and around 9.5 microseconds using ifort 12.1. Testing only 10 random angles will result in an indeterminable time using Fortran routines, as the timing routine is accurate to the millisecond and simple math says it should take 0.100 milliseconds to run all 10 numbers.

EDIT Apparently I was timing IO which (a) made the timing longer than necessary and (b) is contrary to bullet #6. I've updated the code to reflect this. I've also discovered that using a kind=8 integer with the intrinsic subroutine system_clock gives microsecond accuracy.

With this updated code, I am now computing each set of values of the trigonometric functions in about 0.3 microseconds (the significant digits in the end vary run-to-run, but it's consistently hovering near 0.31 us), a significant reduction from the previous iteration that timed IO.

program SinCosTan
   implicit none
   integer, parameter :: real64 = selected_real_kind(15,307)
   real(real64), parameter :: PI  = 3.1415926535897932384626433832795028842
   real(real64), parameter :: TAU = 6.2831853071795864769252867665590057684
   real(real64), parameter :: half = 0.500000000000000000000_real64
   real(real64), allocatable :: trigs(:,:), angles(:)
   real(real64) :: time(2), times, b
   character(len=12) :: tout
   integer :: i,j,ierr,amax
   integer(kind=8) :: cnt(2)

   open(unit=10,file='trig.out',status='replace')
   open(unit=12,file='CodeGolf/trig.in',status='old')
! check to see how many angles there are
   i=0
   do
      read(12,*,iostat=ierr) b
      if(ierr/=0) exit
      i=i+1
   enddo !-
   print '(a,i0,a)',"There are ",i," angles"
   amax = i

! allocate array
   allocate(trigs(3,amax),angles(amax))

! rewind the file then read the angles into the array
   rewind(12)
   do i=1,amax
      read(12,*) angles(i)
   enddo !- i

! compute trig functions & time it
   times = 0.0_real64
   call system_clock(cnt(1)) ! <-- system_clock with an 8-bit INT can time to us
   do i=1,amax
      call CORDIC(angles(i), trigs(:,i), 40)
   enddo !- i
   call system_clock(cnt(2))
   times = times + (cnt(2) - cnt(1))

! write the angles to the file
   do i=1,amax
      do j=1,3
         if(trigs(j,i) > 1d100) then
            write(tout,'(a1)') 'n'
         elseif(abs(trigs(j,i)) > 1.0) then
            write(tout,'(f10.6)') trigs(j,i)
         elseif(abs(trigs(j,i)) < 0.1) then
            write(tout,'(f10.8)') trigs(j,i)
         else
            write(tout,'(f9.7)') trigs(j,i)
         endif
         write(10,'(a)',advance='no') tout
      enddo !- j
      write(10,*)" "
   enddo !- i

   print *,"computation took",times/real(i,real64),"us per angle"
   close(10); close(12)
 contains
   !> @brief compute sine/cosine/tangent
   subroutine CORDIC(a,t,n)
     real(real64), intent(in) :: a
     real(real64), intent(inout) :: t(3)
     integer, intent(in) :: n
! local variables
     real(real64), parameter :: deg2rad = 1.745329252e-2
     real(real64), parameter :: angles(60) = &
       [ 7.8539816339744830962e-01_real64, 4.6364760900080611621e-01_real64, &
         2.4497866312686415417e-01_real64, 1.2435499454676143503e-01_real64, &
         6.2418809995957348474e-02_real64, 3.1239833430268276254e-02_real64, &
         1.5623728620476830803e-02_real64, 7.8123410601011112965e-03_real64, &
         3.9062301319669718276e-03_real64, 1.9531225164788186851e-03_real64, &
         9.7656218955931943040e-04_real64, 4.8828121119489827547e-04_real64, &
         2.4414062014936176402e-04_real64, 1.2207031189367020424e-04_real64, &
         6.1035156174208775022e-05_real64, 3.0517578115526096862e-05_real64, &
         1.5258789061315762107e-05_real64, 7.6293945311019702634e-06_real64, &
         3.8146972656064962829e-06_real64, 1.9073486328101870354e-06_real64, &
         9.5367431640596087942e-07_real64, 4.7683715820308885993e-07_real64, &
         2.3841857910155798249e-07_real64, 1.1920928955078068531e-07_real64, &
         5.9604644775390554414e-08_real64, 2.9802322387695303677e-08_real64, &
         1.4901161193847655147e-08_real64, 7.4505805969238279871e-09_real64, &
         3.7252902984619140453e-09_real64, 1.8626451492309570291e-09_real64, &
         9.3132257461547851536e-10_real64, 4.6566128730773925778e-10_real64, &
         2.3283064365386962890e-10_real64, 1.1641532182693481445e-10_real64, &
         5.8207660913467407226e-11_real64, 2.9103830456733703613e-11_real64, &
         1.4551915228366851807e-11_real64, 7.2759576141834259033e-12_real64, &
         3.6379788070917129517e-12_real64, 1.8189894035458564758e-12_real64, &
         9.0949470177292823792e-13_real64, 4.5474735088646411896e-13_real64, &
         2.2737367544323205948e-13_real64, 1.1368683772161602974e-13_real64, &
         5.6843418860808014870e-14_real64, 2.8421709430404007435e-14_real64, &
         1.4210854715202003717e-14_real64, 7.1054273576010018587e-15_real64, &
         3.5527136788005009294e-15_real64, 1.7763568394002504647e-15_real64, &
         8.8817841970012523234e-16_real64, 4.4408920985006261617e-16_real64, &
         2.2204460492503130808e-16_real64, 1.1102230246251565404e-16_real64, &
         5.5511151231257827021e-17_real64, 2.7755575615628913511e-17_real64, &
         1.3877787807814456755e-17_real64, 6.9388939039072283776e-18_real64, &
         3.4694469519536141888e-18_real64, 1.7347234759768070944e-18_real64]
     real(real64), parameter :: kvalues(33) = &
       [ 0.70710678118654752440e+00_real64, 0.63245553203367586640e+00_real64, &
         0.61357199107789634961e+00_real64, 0.60883391251775242102e+00_real64, &
         0.60764825625616820093e+00_real64, 0.60735177014129595905e+00_real64, &
         0.60727764409352599905e+00_real64, 0.60725911229889273006e+00_real64, &
         0.60725447933256232972e+00_real64, 0.60725332108987516334e+00_real64, &
         0.60725303152913433540e+00_real64, 0.60725295913894481363e+00_real64, &
         0.60725294104139716351e+00_real64, 0.60725293651701023413e+00_real64, &
         0.60725293538591350073e+00_real64, 0.60725293510313931731e+00_real64, &
         0.60725293503244577146e+00_real64, 0.60725293501477238499e+00_real64, &
         0.60725293501035403837e+00_real64, 0.60725293500924945172e+00_real64, &
         0.60725293500897330506e+00_real64, 0.60725293500890426839e+00_real64, &
         0.60725293500888700922e+00_real64, 0.60725293500888269443e+00_real64, &
         0.60725293500888161574e+00_real64, 0.60725293500888134606e+00_real64, &
         0.60725293500888127864e+00_real64, 0.60725293500888126179e+00_real64, &
         0.60725293500888125757e+00_real64, 0.60725293500888125652e+00_real64, &
         0.60725293500888125626e+00_real64, 0.60725293500888125619e+00_real64, &
         0.60725293500888125617e+00_real64 ]
    real(real64) :: beta, c, c2, factor, poweroftwo, s
    real(real64) :: s2, sigma, sign_factor, theta, angle
    integer :: j

! scale to radians
    beta = a*deg2rad
! ensure angle is shifted to appropriate range
    call angleShift(beta, -PI, theta)
! check for signs
    if( theta < -half*PI) then
       theta = theta + PI
       sign_factor = -1.0_real64
    else if( half*PI < theta) then
       theta = theta - PI
       sign_factor = -1.0_real64
    else
       sign_factor = +1.0_real64
    endif

! set up some initializations...
    c = 1.0_real64
    s = 0.0_real64
    poweroftwo = 1.0_real64
    angle = angles(1)

! run for 30 iterations (should be good enough, need testing)
    do j=1,n
       sigma = merge(-1.0_real64, +1.0_real64, theta <  0.0_real64)
       factor = sigma*poweroftwo

       c2 = c - factor*s
       s2 = factor*c + s
       c = c2
       s = s2
! update remaining angle
       theta = theta - sigma*angle

       poweroftwo = poweroftwo*0.5_real64
       if(j+1 > 60) then
          angle = angle * 0.5_real64
       else
          angle = angles(j+1)
       endif
    enddo !- j

    if(n > 0) then
       c = c*Kvalues(min(n,33))
       s = s*Kvalues(min(n,33))
    endif
    c = c*sign_factor
    s = s*sign_factor

    t = [s, c, s/c]
   end subroutine CORDIC

   subroutine angleShift(alpha, beta, gamma)
     real(real64), intent(in) :: alpha, beta
     real(real64), intent(out) :: gamma
     if(alpha < beta) then
        gamma = beta - mod(beta - alpha, TAU) + TAU
     else
        gamma = beta + mod(alpha - beta, TAU)
     endif
   end subroutine angleShift

end program SinCosTan


The tedious array of 7 rules The rundown
Create a program that generates an array of random length with random numbers, then apply a series of rules that alter the array. After the rules have been applied, print the sum of the array unless specified otherwise
Array setup
The array must be a random length between 5 and 10 inclusive, with random integers between 1 and 20 inclusive. Each array length should have equal probability of happening and each integer should have an equal probability of being picked per element.
The 7 rules
The rules should act as if they were applied in sequence (eg: rule 1 acts before rule 2) and are only applied once. For proof of rule application, the array must be printed to console after each rule application and once before any rules are applied.

If the array contains a 7, subtract 1 from every element
If rule 1 is applied and the array now contains a 0, add 1 to each element
If the array contains a 13, exclude the 13, and all elements that follow, from the array
If the array contains a 2, exclude all odd numbers
If the array contains a 20, and the third element is even, return 20 as the sum then terminate. If a 20 is present and the third element is odd, return 20 times the length of the array as the sum then terminate.
If the sum is greater than 50, remove the last element repeatedly until it is less than or equal to 50
If the array contains a 16, print the sum in both decimal and hexadecimal.

Example
Here is an initial array,
[20, 2, 5, 7, 14, 8]

Rule 1 can be applied:
[19, 1, 4, 6, 13, 7]

Rule 3 is applied next:
[19, 1, 4, 6]

No other rules are needed, so the program returns 30 as the sum.
Notes

I'm not an experienced code golfer, although I can say my personal record is in Python 3 with 369 bytes.
The rules don't have to actually be applied in order, but have to act as if they did.

Python 3, 294 301 287 356 bytes

import random as r
r=r.randint
k=[r(i)+1for i in[20]*r(5,11)]
p=print
if 7in k:k=[i-1for i in k]
p(k)
if 0in k:k=[i+1for i in k]
p(k)
i=k.find(13)
if not~i:k=k[:i]
p(k)
if 2in k:k=[i for i in k if~i%2]
p(k)
a=0
z=len(k)>2and k[2]%2
if 20in k:a=20*len(k)**z
if~z:p(k)
while sum(k)>50:k=k[:-1]
if~z:p(k)
if a:p(a)
else:a=sum(k);p(a,hex(a)*(16in k))
if~z:p(k)

I don't know how you're going to prevent people circumventing the rules, but this one uses the procedure specified.

+7 bytes; thanks to @YamB for saving a few bytes; added a lot more to fix a previous error.
-14 bytes thanks to @RootTwo and myself and also corrected the error.
+83 bytes; this is getting horribly long because OP keeps changing the  rules.
-some number of bytes thanks to @ZacharyT


Bring out the inner llama of a sentence Your objective is to take input like

Pie is good.  I just ate a bunch of pies early this morning.  Actually, it was closer to the afternoon.  Mornings are good.

and create an array of the indexes of the string where the letters that make up the word "Llama" appear (one of each in order).  For example, let me show the letters pointed at with carets to show the indexes:

Pie is good.  I just ate a bunch of pies early this morning.  Actually, it was closer to the afternoon.  Mornings are good.
                                            ^                      ^        ^                            ^        ^

So the array would look like:

[44, 67, 76, 105, 114]

(If your application uses a indexing that's not 0-based, the numbers will look different.  That's fine.)

If the text has no llama, then the array should be empty, nil, null, or undefined.

Any code language is accepted.  This is a code-golf contest, so the least characters win!

Perl, 52 bytes

The solution is provided as function that takes the string as argument and returns a list of positions.

One-based positions, case-sensitive search, without newlines: 52 bytes

 sub l{pop=~/(l).*?(l).*?(a).*?(m).*?(a)/;@+[1..$#+]}

The case-sensitive search returns an empty array in the example of the question, because after matching the first three letters the lowercase letter m is missing in the input text.
Support of newlines: + 1 byte = 53 bytes

sub l{pop=~/(l).*?(l).*?(a).*?(m).*?(a)/s;@+[1..$#+]}

The text can now span several lines.
Case-insensitive search: + 1 byte = 54 bytes

 sub l{pop=~/(l).*?(l).*?(a).*?(m).*?(a)/si;@+[1..$#+]}

Now the example in the question reports a list of index positions,
they are one-based numbers:

[45 68 77 106 115]

Zero-based positions: + 9 bytes = 63 bytes

 sub l{pop=~/(l).*?(l).*?(a).*?(m).*?(a)/si;map{$_-1}@+[1..$#+]}

Result for the example in the question:

[44 67 76 105 114]

Ungolfed:

The latter variant includes more or less the other variants.

sub l {
    # pop() gets the last argument
    pop() =~ /(l).*?(l).*?(a).*?(m).*?(a)/si;
    # the letters inbetween are matched against ".*?",
    # the non-greedy variant of ".*". Thus ".*?"
    # matches only as few as possible characters.
    # The modifier /i controls the case-sensitivity
    # and means ignore case. Without the case matters.
    # Modifier /s treats the string as single line,
    # even if it contains newlines.
    map { $_-1 }   # subtract 1 for zero-based positions
        @+[1..$#+]
    # Array @+ contains the end-positions of the last
    # submatches, and of the whole match in the first position.
    # Therefore the first value is sliced away.
    # @+ is available since Perl 5.6.
}

# test
my @result = l(<<"END_STR");
Pie is good.  I just ate a bunch of pies early this morning.  Actually, it was closer to the afternoon.  Mornings are good.
END_STR
print "[@result]\n";


Find the highest unique digit Surprisingly we haven't had a simple "find the highest digit" challenge yet, but I think that's a little too trivial.
Given input of a non-negative integer, return the highest unique (ie not repeated) digit found in the integer. If there are no unique digits, your program can do anything (undefined behaviour).
The input can be taken as a single integer, a string, or a list of digits.
Test cases
12         -> 2
0          -> 0
485902     -> 9
495902     -> 5
999999     -> Anything
999099     -> 0
1948710498 -> 7

This is code-golf so fewest bytes in each language wins!

05AB1E, 4 3 bytes

Saved 1 byte thanks to Mr. Xcoder notifying that a digit list is valid input.

¢ÏM

Try it online!

Explanation

¢     # count occurrences of each digit in input
 Ï    # keep only the digits whose occurrences are true (1)
  M   # push the highest


Generalized matrix trace Inspiration.
Given (by any means):

A two-argument (or single argument consisting of a two-element list) black box function, f: ℤ+ × ℤ+ → ℤ+ (input and output are 1, 2, 3,…)
A strictly positive integer matrix with at least two rows and two columns

return the matrix's function trace.
What is a function trace?
A normal matrix trace is the sum of the major diagonal (top-left to bottom-right) of a matrix:
[[1,2,3],[4,5,6],[7,8,9]] → [1,5,9] → 1+5+9 → 15
But instead of summing, we want to apply f along the diagonal:
[[1,2,3],[4,5,6],[7,8,9]] → [1,5,9] → f(f(1,5),9) or f(1,f(5,9))
Please state whether you use left-to-right or right-to-left.
The given matrix and all intermediate values will be strictly positive integers within your language's integer domain. The matrix may be non-square.
Examples
f(x,y) = xy, [[1,2,3],[4,5,6],[7,8,9]] → 1×5×9 → 45
f(x,y) = xy, [[1,2,3],[4,5,6],[7,8,9]] →  159 → 1
f(x,y) = x-y, [[4,5,6],[1,2,3]] → 4-2 → 2
f(x,y) = (x+y)⁄2, [[2,3,4],[5,6,7],[8,9,10]] → 5 or 7
f(x,y) = x+2y, [[1,2,3],[4,5,6],[7,8,9]] → 47 or 29
f(x,y) = max(x,y), [[1,2,3],[4,5,6],[7,8,9]] → max(1,5,9) → 9
f(x,y) = 2x, [[1,2,3],[4,5,6],[7,8,9]] → 2 or 4
f(x,y) = lcm(x,y), [[2,2,2],[2,2,3],[2,3,3],[4,4,4]] → lcm(2,2,3) → 6
Reference implementation.

R, 40 30 bytes

function(m,F)Reduce(F,diag(m))

Try it online!

Verify the test cases.

Traverses down the diagonal, so left-to-right in this case. For arithmetic operators, you can use "+" or backticks around the operators (+,*,-,%/%,^,%%)

Pretty straightforward: Reduce is R's equivalent to a fold, and the diagonal of a matrix is those elements a_ij where i==j, i.e., where the row and column indices are the same. diag has the appropriate behavior for non-square matrices.


How to golf evaluation of math expression in MySQL? The challenge given to me is comparatively easy, and specific to MySQL only. I'm given a table expressions which have mathematical calculations done by a kid. Basically, I've to select all the right calculations!
The table have the following properties,

a : an integer, the left operand.
b : an integer, the right operand.
operation : a char, any one operation from '+', '-', '*' and '/' (pure-div).
c : an integer, the result given by the kid.

Example
a  b  operation  c
------------------
2  3  +          5
4  2  /          3
6  1  *          9
8  5  -          3

As we can see, the second and third operations are wrongly calculated, so they need to be filtered out. Here is what I've done till now,
MySQL, 88 chars
Rule: 88 chars is calculated by removing all spaces (\s+) from the given code. This is MySQL, so they simply take amount of chars (calculated here).

select * from expressions
where if(
    '+' = @o := operation,
    a + b,
    if(
        @o = '-',
        a - b,
        if(
            @o = '*',
            a * b,
            a / b
        )
    )
) = c

Try it on Rextester!
But, I'm sure that this can be golfed further, as many other submissions are of 73 chars, which is 15 bytes fewer than mine!
I think I need to change the idea of my solution, but I can't find anything which can evaluate expressions directly in MySQL. Any ideas?
Rules

The names, specific to table, included in the code isn't subject to change.
select is considered to be the only method to output/result.
For multiple statements, it should be wrapped inside begin ... end, as the whole code is the body of a function, defined as,
CREATE PROCEDURE expressionsVerification()

Score 69
select * from expressions
where elt(ord(operation)/2-20,a*b,a+b,a-b,a/b)=c

Takes inspiration from Marmite Bomber's use of elt, but uses a magic formula. Indexes into the list via ord(operation)2/-20, which buckets the four character codes across 1 to 4 by abusing elt's rounding behavior.
-1 thanks to Arnauld, who improved on the modulo reduction.
-1 thanks to Bubbler, who found a better non-modulo formula.
Score 73
select * from expressions
where elt(instr('*/-+',operation),a*b,a/b,a-b,a+b)=c

This is my best guess as to the 73 you mention other people have gotten in the question.


Calculate the Progressive Mean™ Disclaimer: This challenge is inspired by a coding error I once made.

Okay, time for a maths lesson. A normal mean average looks like this:

Work out the sum of all numbers in a list
then divide by the size of the list.

But what if we don't know all the numbers at the time we're working out the average? We need a way to work out the average which can be added to over time. For this reason, I present the algorithm for a Progressive Mean™

The running total is the first number in the list
For each of the remaining numbers
  Add the number to the running total
  Divide the running total by two

So in effect we're averaging each number with the current average. (We could add to this later and get the same result)

BUT

This doesn't give the same result at all. It gives an average, but it differs from the standard methodology for finding the mean. Now the order of the list of numbers is significant.

Of course, being a curious type, I want to work out if the Progressive Mean™  tells us anything about the order of our list of numbers. So for this reason I want to compare Mean with Progressive Mean™ by means of a simple subtraction:

trend = Progressive Mean™ - Standard Mean

The Challenge

Write a piece of code which accepts a list of numbers (in any format) which then calculates three pieces of information about it:

Standard Mean
Progressive Mean™
Trend (Progressive - standard)

Work in any language you like.
It's golf, attempt to do the challenge in as few bytes as you can.
Avoid Standard Loopholes
I want the output to be human-readable numbers.
Please include a link to an online interpreter such as tio.run

Test Cases:

[1,2,3]

Normal Mean:        2.0
Progressive Mean:   2.25
Trend:              0.25

[3, 2, 1]

Normal Mean:        2.0
Progressive Mean:   1.75
Trend:              -0.25

[10, 20, 30]

Normal Mean:        20.0
Progressive Mean:   22.5
Trend:              2.5

[300, 200, 100]

Normal Mean:        200.0
Progressive Mean:   175.0
Trend:              -25.0

[10, 100, 10]

Normal Mean:        40.0
Progressive Mean:   32.5
Trend:              -7.5

[4, 4, 9, 8, 1, 8, 6, 9, 1, 1]

Normal Mean:        5.1
Progressive Mean:   2.62890625
Trend:              -2.4710937499999996

[1, 1, 1, 4, 4, 6, 8, 8, 9, 9]

Normal Mean:        5.1
Progressive Mean:   8.5390625
Trend:              3.4390625000000004

[9, 9, 8, 8, 6, 4, 4, 1, 1, 1]

Normal Mean:        5.1
Progressive Mean:   1.47265625
Trend:              -3.6273437499999996

R, 57 bytes

function(v,`!`=sum,N=!1^v)c(A<-!v/N,P<-!v/2^c(N:1,N),P-A)

Try it online!

A clever collaboration with digEmAll and RobinRyder; uses the observation by Grimmy and Kevin's explanation from the comments, which I replicate below:

  For anyone else wondering why the example [a,b,c,d] -> [a,b,c,c,d,d,d,d] doesn't match the explanation of the code, it actually transforms [a,b,c,d] to [a,b,b,c,c,c,c,d,d,d,d,d,d,d,d,a] (so two of each value in comparison to the example). The example confused me for a moment. But nice answer, +1 from me! I also like that it has all these different types of the letter 'A' in the code: āÅÅAÂÆª. xD

This uses R's recycling rules to use two copies of l[1]/2^N in the sumby just sticking an extra N at the end of the decay rate.

R, 62 bytes

function(l)c(p<-Reduce(function(x,y)(x+y)/2,l),a<-mean(l),p-a)

Try it online!

Straightforward implementation.


Four steps to the left: vipers. Four steps to the right: a cliff. Don't die! Introduction
Suppose for a moment that the vipers and cliff are only two steps away, instead of three.
            o
           ---
Hsss!       |
 ';;' ___  /_\  ___  _
                      |

You are, unfortunately, a captive of a sadistic torturer. You must take a step either to the left or to the right every turn. If you don't, they shoot you dead instantly. You are allowed to plan out your steps beforehand, but once you take your first step, you can't change your plan. (And no dawdling either; they'll shoot you.)
Suddenly, a bright idea comes to mind...

Ah! I can just alternate stepping right and left! Step right, step left, step right, step left, and so on...

Ah ah ah, not so fast. Like I said, the torturer is sadistic. They get to choose whether you take every step, or every second step, or every third step, and so on. So if you naively choose the sequence RLRLRL... then they can force you to take every second step, which starts with LL. Uh oh! You've been bitten by vipers! Blackness swoops over you and all else fades away...
Actually no, you're not dead yet. You still have to come up with your plan. After thinking about it for a few minutes, you realize you are doomed. There is no way to plan out a series of steps that will guarantee your survival. The best you can come up with is RLLRLRRLLRR.1 Eleven safe steps and no more. If the twelfth step is R, then the Torturer will make you take every step and then the last three steps send you off the cliff. If the twelfth step is L, then the Torturer will make you take every third step (LRLL), which puts you right in the brood of vipers and their lethal bites.
You pick R as the twelfth step, hoping to delay your demise as long as possible. With the wind roaring in your ears, you wonder to yourself...

What if I had three steps?

Spoiler alert!
You would still die. As it turns out, no matter how many steps you have, there will be some point where no matter what choice you make, there is a sequence of steps your Torturer can pick to ensure you meet your deadly fate.2 However, when the vipers and cliff are three steps away, you can take a total of 1160 safe steps and when they're four steps away, there are at least 13,000 safe steps!3
The challenge
Given a single integer n < 13000, output a sequence of n safe steps, assuming the cliff and the vipers are four steps away.
Rules

Can be either a full program or a function.
Input can be taken through STDIN or equivalent, or as a function argument.
Output must have two distinct characters (which can be +/-, R/L, 1/0, etc.).
Any whitespace in the output doesn't matter.
Hard-coding a solution is not allowed. That would trivialize this challenge.
Your program should (in theory) finish in a decent amount of time. As in, n=13000 might take like a month, but it shouldn't take a thousand years or more. That is, no brute force. (Well, at least try to avoid it.)
Life bonus: provide a series of 2000 safe steps. If you do this, the Torturer will be so impressed by your tenacity, perseverance, and forethought that they'll let you live. This one time. (Treat this sequence as a binary number and provide the decimal equivalent for verification. This is intended to reward answers that finish quickly as answers are allowed to take a very long time.)
Score: bytes, unless you qualify for the bonus - multiply by 0.75.

Survive!

1 There is a good explanation of this problem and "solution" by one of the stars of Numberphile, James Grime, over on his YouTube channel here: https://www.youtube.com/watch?v=pFHsrCNtJu4 .
2 This 80-year-old conjecture, known as Erdos' discrepancy problem, was proved very recently by Terence Tao. Here is a very nice article on Quanta Magazine about this: https://www.quantamagazine.org/20151001-tao-erdos-discrepancy-problem/ .
3 Source: A SAT Attack on the Erdos Discrepancy Conjecture, by Boris Konev and Alexei Lisitsa. Retrieved from here: http://arxiv.org/pdf/1402.2184v2.pdf .


Collection from a sequence that constitute a perfect square Given the sequence OEIS A033581, which is the infinite sequence, the n'th term (0-indexing) is given by the closed form formula 6 × n2 .

Your task is to write code, which outputs all the subsets of the set of N first numbers in the sequence, such that the sum of the subset is a perfect square.

Rules

The integer N is given as input.
You cannot reuse a number already used in the sum. (that is, each number can appear in each subset at most once)
Numbers used can be non-consecutive.
Code with the least size wins.

Example

The given sequence is {0,6,24,54,96,...,15000}

One of the required subsets will be {6,24,294}, because

6+24+294 = 324 = 18^2

You need to find all such sets of all possible lengths in the given range.

05AB1E, 10 bytes
Ý¨n6*æʒOÅ²

Try it online!
How?

Ý¨n6*æʒOÅ² || Full program. I'll call the input N.

Ý          || 0-based inclusive range. Push [0, N] ∩ ℤ.
 ¨         || Remove the last element.
  n        || Square (element-wise).
   6*      || Multiply by 6.
     æ     || Powerset.
      ʒ    || Filter-keep those which satisfy the following:
       O   ||---| Their sum...
        Å² ||---| ... Is a perfect square?


How to randomize letters in a word According to some controversial story, the odrer of ltteres in a wrod deos not mttaer much for raednig, as lnog as the frist and lsat lteter macth with the orignial wrod.

So, for fun, what would be the shortest function to randomize letter order in a word while keeping the first and the last letter in place?

Here's my stab at it with JavaScript. All whitespace removed it's at 124 130 characters.

function r(w) {
  var l=w.length-1;
  return l<3?w:w[0]+w.slice(1,l).split("").sort(function(){return Math.random()-.5}).join("")+w[l];
}

Shorter JavaScript always welcome.

Edit: length check added. Function should not fail for short words.

Haskell, 110 120 107 characters

import Random
s l=randomRIO(1,length l-2)>>=g.($l).splitAt
g(a:b,c:d)=fmap(a:).s$c:b++d
g(a,b)=return$a++b

An example of a program using this function:

main = getLine >>= s >>= putStrLn


Thinking outside the box - Am I doing it right? I keep hearing that thinking outside the box is a goal worth achieving, but how can I tell if I'm successfully doing it?

To solve this dilemma I have already wrote a Brainwave-to-ASCII-translator which in theory should produce outputs like

                    #
   +------------+   #
   |   thinking |   #
   |            |   #
   +------------+   #
                    #

or

                   #
 +------+          #
 |      | thinking #
 |      |          #
 |      |          #
 +------+          #
                   #

which make it fairly easy to tell whether one is thinking outside the box or not. (The # are not part of the output and represent new lines.)

However, due to a bug sometimes only a smaller section of the output is returned:

   |         |         #
   +---------+         #
    thinking           #

        #
       +#
       |#
inking |#

    #
    #

The Task

Please help me to automatically classify the Brainwave-to-ASCII-translator output by writing a program or function which reads an ascii-reprensentation and returns whether thinking is in the box, outside of it or it could not tell from the input.

Input

A set of same-length strings either as a list or delimited by newlines containing

the string thinking or valid pre- or suffixes thereof
the characters +-| forming a rectangular box or valid parts of it
spaces
NO #, those are only included in the challenge to mark the ends of the input lines.

Output

a truthy value if thinking is outside the box
a falsy value if thinking is in the box
a distinct third maybe value if it can not be determined from the input whether thinking is in the box or not

Examples

Truthy:

                   #
 +------+          #
 |      | thinking #
 |      |          #
 |      |          #
 +------+          #
                   #

   |         |         #
   +---------+         #
    thinking           #

        #
       +#
       |#
       |#
inking |#

thinking #
-------+ #

 ++ # (thinking is not in the box, so it must be outside)
 ++ # (this is also the smallest possible box)

+ #
 t#

+----+# (The box is not wide enough to contain "thinking")

---# (The box is not high enough to contain "thinking")
---#

As string input:

"                   \n +------+          \n |      | thinking \n |      |          \n |      |          \n +------+          \n                   "
"   |         |         \n   +---------+         \n    thinking           "
"        \n       +\n       |\n       |\ninking |"
"thinking \n-------+ "
" ++ \n ++ "
"+ \n t"
"+----+"
"---\n---"
"g++"
"k\n+"

Falsy:

                    #
   +------------+   #
   |   thinking |   #
   |            |   #
   +------------+   #
                    #

  +---------------#
  |               #
  |               #
  |   thinking    #

      | #
king  | #
------+ #

+---#
|thi#
+---#

-#
n#
-#

As string input:

"                    \n   +------------+   \n   |   thinking |   \n   |            |   \n   +------------+   \n                    "
"  +---------------\n  |               \n  |               \n  |   thinking    "
"      | \nking  | \n------+ "
"+---\n|thi\n+---"
"-\nn\n-"

Maybe:

thinking#

g|#

think#
-----#

|          |# (box large enough to possibly contain the string)
|          |#

   +--#
   |  #

# (empty input)

As string input:

"thinking"
"g|"
"|t"
"-\ni"
"h\n-"
"think\n-----"
"|          |\n|          |"
"   +--\n   |  "
""

Rules

This is code-golf, so try to use as few bytes as possible.
The maybe value can be chosen freely as long as it's different from the truthy/falsy value and is the same for all maybe-inputs. It can also be an error.
You can assume that the input is always valid (eg. contains no other chars than +-ghiknt|, no more than one box, ...).

Javascript (ES6), 274 263 bytes

f=(a,b=(b,c="")=>a=a.replace(b,c),c=b=>b.test(`,${a},`))=>(b(/\w+/,5),b(/\+/g,1),b(/\-/g,2),b(/\|/g,3),b(/\n/g,4),c(/[13][2 ]{0,7}[13]|[12] *4 *[12]/)||(b(/ /g),b(/43+(?=4)/g),!c(/353|24542|12+435|21453|35412|5342+1/)&&(!c(/^([^1]*|([^15]*1){1,2}[^15]*)$/)||-1)))

The function f returns true, false, or -1 as its "maybe" value. It should be called with one argument: the input. The other two parameters only exist to shorten the code.

Here's a less golfed version with comments:

var f = (input) => {
    var replace = (re, s) => input = input.replace(re, s);
    var test = re => re.test(input);

    /*
        Replace some "special" characters with ones that are shorter to put in a regex.
        "+" --> "1"
        "-" --> "2"
        "|" --> "3"
        "\n" --> ","
    */
    replace(/\+/g,1);
    replace(/\-/g,2);
    replace(/\|/g,3);
    replace(/\n/g,',');

    /*
        Shorten the word, if there is one, to just a single character "a".
    */
    replace(/[a-z]+/g,'a');

    /*
        Append a newline to the beginning and end of the input.
    */
    input = ','+input+',';

    /*
        Test the size of the box. These are the cases covered:
        /[13][2 ]{0,7}[13]/ : A horizontal edge or middle section has an inner width of fewer than 8 characters.
        /[12] *, *[12]/     : There are two horizontal edges in a row, with no space between.

        If either of these match, the word must be outside of the box. Return the truthy value (true).
    */
    if (test(/[13][2 ]{0,7}[13]|[12] *, *[12]/)) return true;

    /*
        Remove any spacing from the input. It it unnecessary from this point onwards.
    */
    replace(/ /g,'');

    /*
        Remove any lines with only vertical bars. These are also unnecessary.
    */
    replace(/,3+(?=,)/g,'');

    /*
        Edge / corner cases (heh). These are the cases covered:
        /3a3/    : two vertical bars with the word between.
        /2,a,2/  : two horizontal bars with the word between.
        /12+,3a/ : word inside the top left corner.
        /21,a3/  : word inside the top right corner.
        /3a,12/  : word inside the bottom left corner.
        /a3,2+1/ : word inside the bottom right corner.

        If any of these match, the word is inside the box. Return the falsy value (false).
    */
    if (test(/3a3|2,a,2|12+,3a|21,a3|3a,12|a3,2+1/)) return false;

    /*
        "Maybe" cases. These are the cases covered:
        /^[^1]*$/                : Input contains no corners, and may or may not contain a word.
        /^([^1a]*1){1,2}[^1a]*$/ : Input contains 1 or 2 corners, and no word.

        If either of these match, assuming the previous test cases have not been hit,
        we cannot tell if the word is inside or outside the box. Return the maybe value (-1).
    */
    if (test(/^([^1]*|([^1a]*1){1,2}[^1a]*)$/)) return -1;

    /*
        If none of the previous cases matched, the word must be outside of the box. Return the truthy value (true).
    */
    return true;
};

Had a lot of fun with this one. Thanks!

Edit: Saved 6 bytes thanks @L. Serné by modifying b to use a default argument, saving 3 bytes, and changing [a-z] to \w, saving 3 more bytes. Also saved 5 more bytes by making the word replacement non-global, saving 1 byte, and changing "a" to 5 and "," to 4, saving 4 bytes.


Bit floating sequence A bit floats from the LSB to the MSB moving one position each time until it floats to the top of the container:

0000
0001
0010
0100
1000

Once one bit floats to the top, another bit begins its journey and it stops when it meets other bit:

1001
1010
1100

This happens until the container is filled with bits:

1101
1110
1111

Challenge

Given an integer number, output the "Bit floating sequence" for a container of that number of bits.

Each term of the sequence can be separated by any separator of your choice.
Edit: Sequence must be shown as decimal integer numbers, starting by the first therm: 0.
The container size sould be greater than zero and up to the number of bits of the bigest integer suported by the language of your choice. You can assume that the input always match this requirement.

Examples

Only the numeric sequence is required, binary representation is shown as example:

For 1: 0 1

0 -> 0
1 -> 1

For 3: 0 1 2 4 5 6 7

000 -> 0
001 -> 1
010 -> 2
100 -> 4
101 -> 5
110 -> 6
111 -> 7

For 4: 0 1 2 4 8 9 10 12 13 14 15

0000 -> 0
0001 -> 1
0010 -> 2
0100 -> 4
1000 -> 8
1001 -> 9
1010 -> 10
1100 -> 12
1101 -> 13
1110 -> 14
1111 -> 15

For 8: 0 1 2 4 8 16 32 64 128 129 130 132 136 144 160 192 193 194 196 200 208 224 225 226 228 232 240 241 242 244 248 249 250 252 253 254 255

00000000 -> 0
00000001 -> 1
00000010 -> 2
00000100 -> 4
00001000 -> 8
…
…
…
11111000 -> 248
11111001 -> 249
11111010 -> 250
11111100 -> 252
11111101 -> 253
11111110 -> 254
11111111 -> 255

05AB1E, 10 bytes

LRL˜Íoî.¥ï

Try it online!

L                 # range [1..input]
 R                # reversed
  L               # convert each to a range: [[1..input], [1..input-1], ..., [1]]
   ˜              # flatten
    Í             # subtract 2 from each
     o            # 2**each
      î           # round up (returns a float)
       ï          # convert to integer
        .¥        # undelta