问:
The Final Number

Challenge

Write a program that takes an array of 4 integers (which represents a sequence of numbers generated by a certain algorithm)  and returns the next integer that would follow.

We will only be using simple addition, subtraction, multiplication and division algorithms with a constant (i.e non-variable) variation.

For division we will use the floor integer values: 133/4 = 33 and 33/4 = 8

You can assume that there will always be one single valid return value

Test cases

[14,24,34,44] should return 54 (addition Algorithm)

[105,45,-15,-75] should return -135 (subtraction algorithm)

[5,25,125,625] should return 3125 (multiplicative algorithm)

[256,64,16,4] should return 1 (division algorithm)

General rules

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

Standard loopholes are forbidden

答:
Java, <s>125</s> 123 bytes

Golfed:

```<code>int m(int[]a){int r=(a[1]>a[0])?a[1]/a[0]:a[0]/a[1];return(a[0]-a[1]==a[1]-a[2])?a[3]-a[0]+a[1]:(a[0]<a[1])?a[3]*r:a[3]/r;}
</code>```

Ungolfed:

```<code>int m(int[] a)
{
    int r = (a[1] > a[0]) ? a[1] / a[0] : a[0] / a[1];
    return (a[0] - a[1] == a[1] - a[2]) ? a[3] - a[0] + a[1] : (a[0] < a[1]) ? a[3] * r : a[3] / r;
}
</code>```

This code surely has some issues since it doesn't handle division by zero and such things. It also won't work of course if there are more (or less) than 4 integers in the input array a. Which makes it beyond stupid, but I had fun :)

Try it out: https://ideone.com/nELH5I

Title: The Final Number

Body:
Java, <s>125</s> 123 bytes

Golfed:

int m(int[]a){int r=(a[1]>a[0])?a[1]/a[0]:a[0]/a[1];return(a[0]-a[1]==a[1]-a[2])?a[3]-a[0]+a[1]:(a[0]<a[1])?a[3]*r:a[3]/r;}

Ungolfed:

int m(int[] a)
{
    int r = (a[1] > a[0]) ? a[1] / a[0] : a[0] / a[1];
    return (a[0] - a[1] == a[1] - a[2]) ? a[3] - a[0] + a[1] : (a[0] < a[1]) ? a[3] * r : a[3] / r;
}

This code surely has some issues since it doesn't handle division by zero and such things. It also won't work of course if there are more (or less) than 4 integers in the input array a. Which makes it beyond stupid, but I had fun :)

Try it out: https://ideone.com/nELH5I


问:
Hate/love conundrum

Challenge description

In this challenge, we only consider love and hate as feelings. If we want to utter a feeling expression of order N, we alternate between these two (starting with hate):

```<code>order | expression

1       I hate it.
2       I hate that I love it.
3       I hate that I love that I hate it.
4       I hate that I love that I hate that I love it.
</code>```

The pattern follows for every positive integer N. Given N, output the correspoinding feeling expression of order N.

Notes

Full stop (.) at the end of the expression is mandatory,

Trailing and leading whitespaces (including newlines) are permitted,

Output for a non-positive or non-integer N is undefined,

This is a code-golf challenge, so make your code as short as possible!

答:
Mathematica, 63 bytes

```<code>"I love"["I hate"][[#~Mod~2]]&~Array~#~Riffle~" that "<>" it."&
</code>```

ContentLicense: CC BY-SA 3.0

Title: Hate/love conundrum

Body:
Mathematica, 63 bytes

"I love"["I hate"][[#~Mod~2]]&~Array~#~Riffle~" that "<>" it."&


答:
Jelly, 25 bytes

```<code>“ṅɠT5“£ẏkg⁷»ṁj“¥ıQ»ṙ1“it.
</code>```

Try it online!

Explanation

```<code>                             Input: n, a number.
“ṅɠT5“£ẏkg⁷»                 Compressed string array [' I hate', ' I love']
            ṁ                Cycle for n repetitions.
             j“¥ıQ»          Join by compressed string ' that'.
                   ṙ1        Rotate left once: move the initial space to the end.
                     “it.    Implicitly print the result, then print 'it.'
</code>```

Title: Hate/love conundrum

Body:
Challenge description

In this challenge, we only consider love and hate as feelings. If we want to utter a feeling expression of order N, we alternate between these two (starting with hate):

```<code>order | expression

1       I hate it.
2       I hate that I love it.
3       I hate that I love that I hate it.
4       I hate that I love that I hate that I love it.
</code>```

The pattern follows for every positive integer N. Given N, output the correspoinding feeling expression of order N.

Notes

Full stop (.) at the end of the expression is mandatory,

Trailing and leading whitespaces (including newlines) are permitted,

Output for a non-positive or non-integer N is undefined,

This is a code-golf challenge, so make your code as short as possible!

Body:
Jelly, 25 bytes

“ṅɠT5“£ẏkg⁷»ṁj“¥ıQ»ṙ1“it.

Try it online!

Explanation

                             Input: n, a number.
“ṅɠT5“£ẏkg⁷»                 Compressed string array [' I hate', ' I love']
            ṁ                Cycle for n repetitions.
             j“¥ıQ»          Join by compressed string ' that'.
                   ṙ1        Rotate left once: move the initial space to the end.
                     “it.    Implicitly print the result, then print 'it.'


问:
Alternating Sign Sequence

Introduction

The sign of a number is either a +, or a - for every non-zero integer. Zero itself is signless (+0 is the same as -0). In the following sequence, we are going to alternate between the positive sign, the zero and the negative sign. The sequence starts with 1, so we write 1 with a positive sign, with zero (this one is weird, but we just multiply the number by 0) and the negative sign:

```<code>1, 0, -1
</code>```

The next number is 2, and we do the same thing again:

```<code>2, 0, -2
</code>```

The sequence eventually is:

```<code>1, 0, -1, 2, 0, -2, 3, 0, -3, 4, 0, -4, 5, 0, -5, 6, 0, -6, 7, 0, -7, ...
</code>```

Or a more readable form:

```<code>a(0) = 1
a(1) = 0
a(2) = -1
a(3) = 2
a(4) = 0
a(5) = -2
a(6) = 3
a(7) = 0
a(8) = -3
a(9) = 4
...
</code>```

The Task

Given a non-negative integer n, output the nth term of the above sequence. You can choose if you use the zero-indexed or one-indexed version.

Test cases:

Zero-indexed:

```<code>a(0) = 1
a(11) = -4
a(76) = 0
a(134) = -45
a(296) = -99
</code>```

Or if you prefer one-indexed:

```<code>a(1) = 1
a(12) = -4
a(77) = 0
a(135) = -45
a(297) = -99
</code>```

This is code-golf, so the submission with the smallest number of bytes wins!

答:
Oasis, 12 bytes (non-competing)

```<code>n3÷>n3÷y>n-*
</code>```

Try it online!

Oasis is a language designed by Adnan which is specialized in sequences.

Currently, this language can do recursion and closed form.

This answer can only demonstrate closed form. For recursion, see for example this answer.

We use this formula: a(n) = (n/3+1)*((n/3*3)+1-n) which is modified from the formula used in my Python answer, since there is no modulo at the moment.

```<code>n3÷>n3÷y>n-*

n             push n (input)
 3÷           integer-division by 3
   >          +1
    n         push n (input)
     3÷       integer-division by 3
       y      *3
        >     +1
         n    push n (input)
          -   subtract the top of stack from the second top of stack
           *  multiply the top of stack to the second top of stack
</code>```

Title: Alternating Sign Sequence

Body:
Oasis, 12 bytes (non-competing)

n3÷>n3÷y>n-*

Try it online!

Oasis is a language designed by Adnan which is specialized in sequences.

Currently, this language can do recursion and closed form.

This answer can only demonstrate closed form. For recursion, see for example this answer.

We use this formula: a(n) = (n/3+1)*((n/3*3)+1-n) which is modified from the formula used in my Python answer, since there is no modulo at the moment.

n3÷>n3÷y>n-*

n             push n (input)
 3÷           integer-division by 3
   >          +1
    n         push n (input)
     3÷       integer-division by 3
       y      *3
        >     +1
         n    push n (input)
          -   subtract the top of stack from the second top of stack
           *  multiply the top of stack to the second top of stack


答:
php, <s>64</s> 62 bytes

```<code><?=str_pad("",$argv[1]*12-5,"I hate that I love that ")."it.";
</code>```

Unfortunately I couldn't work out a way to avoid repeating the " that I ", or at least no way to do it in less than 7 bytes.

edit: saved 2 bytes thanks to @Jörg Hülsermann

Title: Hate/love conundrum

Body:
php, <s>64</s> 62 bytes

<?=str_pad("",$argv[1]*12-5,"I hate that I love that ")."it.";

Unfortunately I couldn't work out a way to avoid repeating the " that I ", or at least no way to do it in less than 7 bytes.

edit: saved 2 bytes thanks to @Jörg Hülsermann


问:
The Squiggly Sequence

All credits to Adnan for coming up with this challenge.

My last challenge, before I go on break.

Task

Given positive integer n, if n is odd, repeat / that many times; if n is even, repeat \ that many times.

(Seriously, the testcases would be much clearer than this description, so just look at the testcases.)

Specs

Any reasonable input/output format.

Standard loopholes apply.

Testcases

```<code>n output
1 /
2 \\
3 ///
4 \\\\
5 /////
6 \\\\\\
</code>```

答:
Bash + coreutils, <s>29</s> 28 bytes

yes $1_45r2%*92+P|sed $1q|dc
```

<p>Previous answer, easier to understand:</p>

<pre class="lang-sh prettyprint-override"><code>yes $[92-$1%2*45]P|sed $1q|dc
</code>```

In the new script I just transferred the calculation of the ASCII code from bash to dc entirely.

Title: The Squiggly Sequence

Body:
Bash + coreutils, <s>29</s> 28 bytes

yes $1_45r2%*92+P|sed $1q|dc

Previous answer, easier to understand:

yes $[92-$1%2*45]P|sed $1q|dc

In the new script I just transferred the calculation of the ASCII code from bash to dc entirely.


问:
Sheffle tho vawols ureund!
Given an input string, output that string with all vowels a, e, i, o and u swapped at random between each other.

For example, in the string this is a test, there are 4 vowels: [i, i, a, e]. A valid shuffling of those vowels could be [a, i, e, i] therefore yielding the output thas is e tist.

About shuffling

All shuffles shall be equally likely if we consider equal vowels to be distinct. For the example above, those 24 shuffles are possible:

```
[i<sub>1</sub>, i<sub>2</sub>, a, e]    [i<sub>1</sub>, i<sub>2</sub>, e, a]    [i<sub>1</sub>, a, i<sub>2</sub>, e]    [i<sub>1</sub>, a, e, i<sub>2</sub>]
[i<sub>1</sub>, e, i<sub>2</sub>, a]    [i<sub>1</sub>, e, a, i<sub>2</sub>]    [i<sub>2</sub>, i<sub>1</sub>, a, e]    [i<sub>2</sub>, i<sub>1</sub>, e, a]
[i<sub>2</sub>, a, i<sub>1</sub>, e]    [i<sub>2</sub>, a, e, i<sub>1</sub>]    [i<sub>2</sub>, e, i<sub>1</sub>, a]    [i<sub>2</sub>, e, a, i<sub>1</sub>]
[a, i<sub>1</sub>, i<sub>2</sub>, e]    [a, i<sub>1</sub>, e, i<sub>2</sub>]    [a, i<sub>2</sub>, i<sub>1</sub>, e]    [a, i<sub>2</sub>, e, i<sub>1</sub>]
[a, e, i<sub>1</sub>, i<sub>2</sub>]    [a, e, i<sub>2</sub>, i<sub>1</sub>]    [e, i<sub>1</sub>, i<sub>2</sub>, a]    [e, i<sub>1</sub>, a, i<sub>2</sub>]
[e, i<sub>2</sub>, i<sub>1</sub>, a]    [e, i<sub>2</sub>, a, i<sub>1</sub>]    [e, a, i<sub>1</sub>, i<sub>2</sub>]    [e, a, i<sub>2</sub>, i<sub>1</sub>]
```

Each one should be equally as likely.

You may not try random shuffles of the entire string until finding one where all vowels are in the right place. In short, your code's running time shall be constant if the input is constant.

Inputs and outputs

You may assume that all letters in the input will be lowercase or uppercase. You may also support mixed casing, though this won't give you any bonus.

The input will always consist of printable ASCII characters. All characters that are in the input shall be in the output, only the vowels must be shuffled around and nothing else.

The input can be empty. There is no guarantee that the input will contain at least one vowel or at least one non-vowel.

You may take the input from STDIN, as a function parameter, or anything similar.

You may print the output to STDOUT, return it from a function, or anything similar.

Test cases

The first line is the given input. The second line is one of the possible outputs.

```<code><empty string>
<empty string>

a
a

cwm
cwm

the quick brown fox jumps over the lazy dog.
tho qeuck brewn fax jumps ovir the lozy dog.

abcdefghijklmnopqrstuvwxyz
abcdefghujklmnipqrstovwxyz

programming puzzles & code golf
pregromming pezzlos & coda gulf

fatalize
fitaleza

martin ender
mirten ander
</code>```

Scoring

This is code-golf, sa tho shirtist enswer en bytes wons.

答:
PHP, <s>144</s> 129 bytes

Using lowercase input

```<code>$r=Aaeiou;$v=str_shuffle(preg_replace("#[^$r]+#",'',$a=$argv[1]));for(;$i<strlen($a);)echo strpos($r,$a[$i++])?$v[$j++]:$a[$i-1];
</code>```

Explanation:

```<code>$r="aeiou"; // set vowels

preg_replace("#[^$r]+#",'',$argv[1]) // find all vowels in input

$v=str_shuffle() // shuffle them

for(;$i<strlen($a);) // run through the text

strpos($r,$a[$i++])?$v[$j++]:$a[$i-1]; // if it's a vowel print the j-th shuffled vowel else print original text
</code>```

Title: Sheffle tho vawols ureund!

Body:
PHP, <s>144</s> 129 bytes

Using lowercase input

$r=Aaeiou;$v=str_shuffle(preg_replace("#[^$r]+#",'',$a=$argv[1]));for(;$i<strlen($a);)echo strpos($r,$a[$i++])?$v[$j++]:$a[$i-1];

Explanation:

$r="aeiou"; // set vowels

preg_replace("#[^$r]+#",'',$argv[1]) // find all vowels in input

$v=str_shuffle() // shuffle them

for(;$i<strlen($a);) // run through the text

strpos($r,$a[$i++])?$v[$j++]:$a[$i-1]; // if it's a vowel print the j-th shuffled vowel else print original text


答:
R, 79 bytes

```<code>n=scan();for(i in n:1)cat(if((i+n)%%2)"I love"else"I hate",if(i>1)"that "else"it.")
</code>```

Luckily in R, the default separator for cat is a space.

(Edited from original 73 byte version which didn't quite solve the problem.)

Title: Hate/love conundrum

Body:
R, 79 bytes

n=scan();for(i in n:1)cat(if((i+n)%%2)"I love"else"I hate",if(i>1)"that "else"it.")

Luckily in R, the default separator for cat is a space.

(Edited from original 73 byte version which didn't quite solve the problem.)


Title: The Final Number

Body:
Challenge

Write a program that takes an array of 4 integers (which represents a sequence of numbers generated by a certain algorithm)  and returns the next integer that would follow.

We will only be using simple addition, subtraction, multiplication and division algorithms with a constant (i.e non-variable) variation.

For division we will use the floor integer values: 133/4 = 33 and 33/4 = 8

You can assume that there will always be one single valid return value

Test cases

[14,24,34,44] should return 54 (addition Algorithm)

[105,45,-15,-75] should return -135 (subtraction algorithm)

[5,25,125,625] should return 3125 (multiplicative algorithm)

[256,64,16,4] should return 1 (division algorithm)

General rules

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

Standard loopholes are forbidden

Body:
JavaScript, 73 bytes

(a,b,c,d)=>(x=b-a,c-b==x&&d-c==x)?d+x:(x=b/a,b*x|0==c&&c*x|0==d)?d*x|0:-1

Tests:

console.log(s.apply(null,[14,24,34,44]), 54);
console.log(s.apply(null,[105,45,-15,-75]), -135);
console.log(s.apply(null,[5,25,125,625]), 3125);
console.log(s.apply(null,[256,64,16,4]), 1);

console.log(s.apply(null,[2,1,0,0]),0);
console.log(s.apply(null,[1,0,0,0]),0);
console.log(s.apply(null,[-325,-82,-21,-6]),-1);

console.log(s.apply(null,[-1,-1,-1,-1]),-1);
console.log(s.apply(null,[0,0,0,0]),0);

Works for them all.


问:
Prune connections
John is writing a program that finds the best route from A to B using public transport. For a given pair of origin and destination the program calculates a set of routes with departure time and arrival time, such as this:

```<code>10:12 11:45
10:15 11:50
10:22 12:05
10:25 12:00
</code>```

As you see, the output may include a few routes that are superfluous in the sense that there is another route that starts later and ends earlier. Such routes are certainly never wanted by the user since he cat get out later to arrive sooner.

Your task, if you choose to accept it, is to write a program that prunes a set of routes such that all superfluous rules are eliminated.

Input

The input is a list of newline separated pairs of whitespace separated departure and arrival time in military format (hh:mm). Such a pair is called a route.

You may assume that all times are in the same day and that the arrival time is always later than the departure time. You may also assume that the list is orderer by departure times.

Output

The output is the same list as the input without redundant routes. A redundant route is a route for which another route exists in the list that has a later departure and an earlier arrival time. There must exist an order to remove all redundant routes such that in each step you can show the route that makes the removed route redundant. You don't have to output that order.

Extra credit

Prove or disprove that for each list of input routes there exists exactly one set of output routes.

Restriction

Usual codegolf rules apply

Scoring

To score, apply the function that gives an upper bound to your solutions complexity with your solution's total number of characters. Normalize your bounding function such that a solution length of two character yields a score of two.

For example, if your solution has 24 characters and a complexity of O(2n), your score is 4194304. If your solution has 123 characters and a complexity of O(n2) your score is 7564. If your solution has 200 characters and a complexity of O(n*logn), your score is 734.

I use this scoring method in order to encourage people to implement efficient solutions.

Title: Prune connections

Body:
APL <s>107</s> <s>57</s> 52 . O(n) = 52

T m
r←m
m←⍎(,0 5↓m)~':'
l:m←(n←(2≤/m),1)/m
r←n⌿r
→(~×/n)/l
r

The input m variable could be simply typed in as follows for the first example below:

m←4 11⍴'10:12 11:4510:15 11:5010:22 12:0510:25 12:00'

or it could be read in programatically from a number of sources eg text file.

The line before the start of the loop converts the character input (m) of arrival times to 4 digit numbers. The loop is then using sequential ≤ on those times to do the pruning. Tested on the following:

10:12 11:45  10:12 11:45  10:12 11:45  10:12 11:45
10:15 11:50  10:15 11:50  10:15 11:50  10:15 11:50
10:22 12:05  10:22 12:05  10:22 12:05  10:22 12:05
10:25 12:00  10:25 12:00  10:25 12:00  10:25 12:00
===========  10:30 11:55  10:30 11:55  10:30 11:55
10:12 11:45  ===========  10:35 12:10  10:35 12:10
10:15 11:50  10:12 11:45  ===========  10:40 11:40
10:25 12:00  10:15 11:50  10:12 11:45  ===========
             10:30 11:55  10:15 11:50  10:40 11:40
                          10:30 11:55
                          10:35 12:10


答:
Haskell, 70 bytes

```<code>g 1="I hate";g n=g(n-1)++" that "++cycle["I love",g 1]!!n
(++" it.").g
</code>```

Title: Hate/love conundrum

Body:
Haskell, 70 bytes

g 1="I hate";g n=g(n-1)++" that "++cycle["I love",g 1]!!n
(++" it.").g


问:
Calculate the nth term of Golomb's self-describing sequence
Inspired by the previous question.

Golomb's self-describing sequence g(n) is a sequence where any natural number n is repeated within the sequence g(n) times.

The first few numbers in the sequence are:

```<code>n    1  2  3  4  5  6  7  8  9  10 11 12 13 14 15 16 17 18 19 20
g(n) 1  2  2  3  3  4  4  4  5  5  5  6  6  6  6  7  7  7  7  8
</code>```

You can see that g(4)=3, and that "4" is repeated 3 times in the sequence.

Given an input of n, output g(n).

Limitations: n < 100000.

Smallest code wins.

答:
Oasis, 7 bytes (non-competing)

Code:

```<code>n<aae>T
</code>```

Try it online!

Oasis is a language designed by Adnan which is specialized in sequences.

Currently, this language can do recursion and closed form.

The T at the end is shorthand for 10, which indicates that a(0) = 0 and a(1) = 1. To add more testcases, simply add to the list at the end.

```<code>n<aae>T
n<aae>10  expanded

       0  a(0) = 0
      1   a(1) = 1

n         push n (input)
 <        -1
  a       a(above)  [a is the sequence]
   a      a(above)
    e     a(n-above)
     >    +1
</code>```

Now we essentially calculated a(n-a(a(n-1))+1.

Body:
Oasis, 7 bytes (non-competing)

Code:

n<aae>T

Try it online!

Oasis is a language designed by Adnan which is specialized in sequences.

Currently, this language can do recursion and closed form.

The T at the end is shorthand for 10, which indicates that a(0) = 0 and a(1) = 1. To add more testcases, simply add to the list at the end.

n<aae>T
n<aae>10  expanded

       0  a(0) = 0
      1   a(1) = 1

n         push n (input)
 <        -1
  a       a(above)  [a is the sequence]
   a      a(above)
    e     a(n-above)
     >    +1

Now we essentially calculated a(n-a(a(n-1))+1.


答:
PHP, <s>63</s> 52 bytes

Version 1 - 63 bytes

```<code>$i=$argv[1];$x=($i%2?"/":"\\");echo sprintf("%'".$x.$i."s",$x);
</code>```

Version 2 - 52 bytes

Thanks to manatwork for saving 11 bytes

```<code>$i=$argv[1];$x=$i%2?"/":"\\";printf("%'$x{$i}s",$x);
</code>```

Run with php -f squiggle.php <number>

https://repl.it/DFdi/2 (remember to change the input on repl)

Title: The Squiggly Sequence

Body:
All credits to Adnan for coming up with this challenge.

My last challenge, before I go on break.

Task

Given positive integer n, if n is odd, repeat / that many times; if n is even, repeat \ that many times.

(Seriously, the testcases would be much clearer than this description, so just look at the testcases.)

Specs

Any reasonable input/output format.

Standard loopholes apply.

Testcases

```<code>n output
1 /
2 \\
3 ///
4 \\\\
5 /////
6 \\\\\\
</code>```

Body:
PHP, <s>63</s> 52 bytes

Version 1 - 63 bytes

$i=$argv[1];$x=($i%2?"/":"\\");echo sprintf("%'".$x.$i."s",$x);

Version 2 - 52 bytes

Thanks to manatwork for saving 11 bytes

$i=$argv[1];$x=$i%2?"/":"\\";printf("%'$x{$i}s",$x);

Run with php -f squiggle.php <number>

https://repl.it/DFdi/2 (remember to change the input on repl)


问:
Randomly Misspell a Word
Inspired by this CR question (please don't kill me for browsing CR)

Spec

The probabilities of misspelling a word are:

1/3 of the time don't change the output

1/3 of the time remove a random character

1/3 of the time duplicate a random character

The chance for removing/duplicating a given character in the input should be the same for all chars.

If two consecutive characters are the same (case-sensitive), the probability of one of them being modified should be the same as if they are one character. I.e. the outputs for AA (which are AA or A or AAA) should all have the same probability.

The input will only contain of letters for simplicity.

Examples

First line is input, following lines are all possible misspellings. Each line should have the same probability of being output, the input is excluded in the examples but it should still have a 1/3 probability of output.

```<code>foo

fo
oo
ffoo
fooo
</code>```

```<code>PPCG

PPC
PPG
PCG
PPPCG
PPCCG
PPCGG
</code>```

答:
Python 2, 134 bytes

from random import*
def f(s):
 p=c=0;M,L=[],list(s)
 for t in L:
  if t!=p:M+=c,;p=t
  c+=1
 L[choice(M)]*=randint(0,2);return''.join(L)
```

White spaces in for loop are tabs.

Try it on Ideone

Title: Randomly Misspell a Word

Body:
Python 2, 134 bytes

from random import*
def f(s):
 p=c=0;M,L=[],list(s)
 for t in L:
  if t!=p:M+=c,;p=t
  c+=1
 L[choice(M)]*=randint(0,2);return''.join(L)

White spaces in for loop are tabs.

Try it on Ideone


答:
PowerShell v3+, <s>155</s> 99 bytes

```<code>param([char[]]$n)$a=$n|?{$_-match'[aeiou]'}|sort{random};-join($n|%{if($_-in$a){$a[$i++]}else{$_}})
</code>```

Big props to @Ben Owen for the 56-byte golf

Takes input $n, expecting all lowercase, immediately casts it as a char-array.

We pipe that into a Where-Object clause to pull out those elements that -match a vowel, pipe them to Sort-Object with {Get-Random} as the sorting mechanism. Calling Get-Random without qualifiers will return an integer between 0 and [int32]::MaxValue -- i.e., assigning random weights to each element on the fly. We store the randomized vowels into $a.

Finally, we loop through $n. For each element, |%{...}, if the current character is somewhere -in $a, we output the next element in $a, post-incrementing $i for the next time. Otherwise, we output the current character. That's all encapsulated in parens and -joined together into a string. That string is left on the pipeline, and output is implicit at program conclusion.

Test cases

```<code>PS C:\Tools\Scripts\golfing> 'a','cwm','the quick brown fox jumps over the lazy dog.','abcdefghijklmnopqrstuvwxyz','programming puzzles & code golf','fatalize','martin ender'|%{.\vawols.ps1 $_}
a
cwm
thu qaeck brown fix jomps ovor thu lezy deg.
abcdofghejklmnupqrstivwxyz
prugrammong pizzles & code golf
fitaleza
mertin endar
</code>```

Title: Sheffle tho vawols ureund!

Body:
Given an input string, output that string with all vowels a, e, i, o and u swapped at random between each other.

For example, in the string this is a test, there are 4 vowels: [i, i, a, e]. A valid shuffling of those vowels could be [a, i, e, i] therefore yielding the output thas is e tist.

About shuffling

All shuffles shall be equally likely if we consider equal vowels to be distinct. For the example above, those 24 shuffles are possible:

```
[i<sub>1</sub>, i<sub>2</sub>, a, e]    [i<sub>1</sub>, i<sub>2</sub>, e, a]    [i<sub>1</sub>, a, i<sub>2</sub>, e]    [i<sub>1</sub>, a, e, i<sub>2</sub>]
[i<sub>1</sub>, e, i<sub>2</sub>, a]    [i<sub>1</sub>, e, a, i<sub>2</sub>]    [i<sub>2</sub>, i<sub>1</sub>, a, e]    [i<sub>2</sub>, i<sub>1</sub>, e, a]
[i<sub>2</sub>, a, i<sub>1</sub>, e]    [i<sub>2</sub>, a, e, i<sub>1</sub>]    [i<sub>2</sub>, e, i<sub>1</sub>, a]    [i<sub>2</sub>, e, a, i<sub>1</sub>]
[a, i<sub>1</sub>, i<sub>2</sub>, e]    [a, i<sub>1</sub>, e, i<sub>2</sub>]    [a, i<sub>2</sub>, i<sub>1</sub>, e]    [a, i<sub>2</sub>, e, i<sub>1</sub>]
[a, e, i<sub>1</sub>, i<sub>2</sub>]    [a, e, i<sub>2</sub>, i<sub>1</sub>]    [e, i<sub>1</sub>, i<sub>2</sub>, a]    [e, i<sub>1</sub>, a, i<sub>2</sub>]
[e, i<sub>2</sub>, i<sub>1</sub>, a]    [e, i<sub>2</sub>, a, i<sub>1</sub>]    [e, a, i<sub>1</sub>, i<sub>2</sub>]    [e, a, i<sub>2</sub>, i<sub>1</sub>]
```

Each one should be equally as likely.

You may not try random shuffles of the entire string until finding one where all vowels are in the right place. In short, your code's running time shall be constant if the input is constant.

Inputs and outputs

You may assume that all letters in the input will be lowercase or uppercase. You may also support mixed casing, though this won't give you any bonus.

The input will always consist of printable ASCII characters. All characters that are in the input shall be in the output, only the vowels must be shuffled around and nothing else.

The input can be empty. There is no guarantee that the input will contain at least one vowel or at least one non-vowel.

You may take the input from STDIN, as a function parameter, or anything similar.

You may print the output to STDOUT, return it from a function, or anything similar.

Test cases

The first line is the given input. The second line is one of the possible outputs.

```<code><empty string>
<empty string>

a
a

cwm
cwm

the quick brown fox jumps over the lazy dog.
tho qeuck brewn fax jumps ovir the lozy dog.

abcdefghijklmnopqrstuvwxyz
abcdefghujklmnipqrstovwxyz

programming puzzles & code golf
pregromming pezzlos & coda gulf

fatalize
fitaleza

martin ender
mirten ander
</code>```

Scoring

This is code-golf, sa tho shirtist enswer en bytes wons.

Body:
PowerShell v3+, <s>155</s> 99 bytes

param([char[]]$n)$a=$n|?{$_-match'[aeiou]'}|sort{random};-join($n|%{if($_-in$a){$a[$i++]}else{$_}})

Big props to @Ben Owen for the 56-byte golf

Takes input $n, expecting all lowercase, immediately casts it as a char-array.

We pipe that into a Where-Object clause to pull out those elements that -match a vowel, pipe them to Sort-Object with {Get-Random} as the sorting mechanism. Calling Get-Random without qualifiers will return an integer between 0 and [int32]::MaxValue -- i.e., assigning random weights to each element on the fly. We store the randomized vowels into $a.

Finally, we loop through $n. For each element, |%{...}, if the current character is somewhere -in $a, we output the next element in $a, post-incrementing $i for the next time. Otherwise, we output the current character. That's all encapsulated in parens and -joined together into a string. That string is left on the pipeline, and output is implicit at program conclusion.

Test cases

PS C:\Tools\Scripts\golfing> 'a','cwm','the quick brown fox jumps over the lazy dog.','abcdefghijklmnopqrstuvwxyz','programming puzzles & code golf','fatalize','martin ender'|%{.\vawols.ps1 $_}
a
cwm
thu qaeck brown fix jomps ovor thu lezy deg.
abcdofghejklmnupqrstivwxyz
prugrammong pizzles & code golf
fitaleza
mertin endar


答:
C, 96 Bytes

```<code>c;f(i){printf("I hate");for(;c<i+1/2-1;c++)printf(" that I %s",c&1?"hate":"love");puts(" it.");}
</code>```

I didn't see the above solution from Releasing Helium Nuclei which is better.

Title: Hate/love conundrum

Body:
Challenge description

In this challenge, we only consider love and hate as feelings. If we want to utter a feeling expression of order N, we alternate between these two (starting with hate):

```<code>order | expression

1       I hate it.
2       I hate that I love it.
3       I hate that I love that I hate it.
4       I hate that I love that I hate that I love it.
</code>```

The pattern follows for every positive integer N. Given N, output the correspoinding feeling expression of order N.

Notes

Full stop (.) at the end of the expression is mandatory,

Trailing and leading whitespaces (including newlines) are permitted,

Output for a non-positive or non-integer N is undefined,

This is a code-golf challenge, so make your code as short as possible!

Body:
C, 96 Bytes

c;f(i){printf("I hate");for(;c<i+1/2-1;c++)printf(" that I %s",c&1?"hate":"love");puts(" it.");}

I didn't see the above solution from Releasing Helium Nuclei which is better.


问:
Traveling on a flat Earth
Coordinates in the flat-Earth world consist of latitude (x) and longitude (y), which are integers in the range 0...9999. Much like Gaussian integers, but they are always written using this notation:

```<code>411S 370E
</code>```

That is, with S or N appended to the latitude, and E or W appended to the longitude, with space(s) between the two components.

Goal

Write a program (not a function) that reads two coordinates, separated by whitespace, and outputs their sum. The first coordinate is a starting point, the second one is a displacement, and the output is the resulting position.

Input/Output

Since this challenge is partially about formatting, I'll try to define the input and output formats unambiguously.

The preferred input format has 1 space between the coordinate components, no leading zeros, and a newline character between the two coordinates. The program must be able to read the preferred format.

The output can contain any amount of whitespace and leading zeros. If it's different from the preferred input format, the program must be able to read this format too.

Just to make it clear, the input cannot (will not) contain any additional formatting characters. Just spaces and newlines where needed.

Scoring

This is an experiment on a new winning condition. I'll choose the winner by accepting an answer in a few weeks. If a better answer appears afterwards, I'll change the accepted answer.

The score for the program is its byte count. The winning program is one that is shorter than 400 bytes, has the fewest byte count, but is written in the most verbose programming language. To determine the winner:

Remove programs with byte count 400 or more (they can participate but cannot win)

Consider only the shortest program for each programming language

The longest program wins

Polyglots compete against programs in all languages in which they are valid (e.g. if a program is valid in both bash and sh, it competes against programs in both languages).

Test cases

In the test cases, the first two lines are the input, and the third line is the output.

```<code>0S 0E
0S 0W
0N 0E
</code>```

(the direction of zero doesn't matter, both in input and output)

```<code>0S 9999E
9999N 9999W
9999N 0E
</code>```

(maximal values)

```<code>42S 314W
42N 2718W
0N 3032W
</code>```

(the direction of zero doesn't matter in the output)

```<code>5555N 8888W
7777S 0E
2222S 8888W
</code>```

(no negative values; change the direction if you need to change the sign)

```<code>0001N        4545W
0999N        5454W
1000N        9999W
</code>```

(if the program outputs leading zeros and several spaces, it must be able to read them; it must also be able to read input that doesn't contain them)

```<code>8888N 8888W
9999N 9999W
</code>```

(invalid input - any behavior is acceptable, including crash and infinite loop)

Title: Traveling on a flat Earth

Body:
Perl 6, 130 bytes

my (\h,\v)=[Z+] lines».split(' ')».map: {m/(.*)(.)/;$1 eq'S'|'W'??-$0!!$0}
say "{abs h}{h <0??'S'!!'N'} {abs v}{v <0??'W'!!'E'}"


问:
Excessive Integers
For a positive integer n with the prime factorization n = p1^e1 * p2^e2 * ... pk^ek where p1,...,pk are primes and e1,...,ek are positive integers, we can define two functions:

Ω(n) = e1+e2+...+ek the number of prime divisors (counted with multiplicity) (A001222)

ω(n) = k the number of distinct prime divisors. (A001221)

With those two functions we define the excess e(n) = Ω(n) - ω(n) (A046660). This can be considered as a measure of how close a number is to being squarefree.

Challenge

For a given positive integer n return e(n).

Examples

For n = 12 = 2^2 * 3 we have Ω(12) = 2+1 and ω(12) = 2 and therefore e(12) = Ω(12) - ω(12) = 1. For any squarefree number n we obivously have e(n) = 0. The first few terms are

```<code>1       0
2       0
3       0
4       1
5       0
6       0
7       0
8       2
9       1
10      0
11      0
12      1
13      0
14      0
15      0
</code>```

Some more details in the OEIS wiki.

Title: Excessive Integers

Body:
C, 158

#define G(a,b) if(a)goto b
#define R return
f(n,i,j,o,w){if(!n)R 0;o=w=i=j=0;a:i+=2;b:if(n%i==0){++j;G(n/=i,b);}o+=!!j;w+=j;i+=(i==2);j=0;G(i*i<n,a);R w-o;}

In the start there is the goto instruction... even if this is more long
than yours it is more readable and right [if i not consider n too much big...]
one Language that has 10000 library functions is wrost than a
Language that with few, 20 or 30 library functions can do all better [because
we can not remember all these functions]

#define F for
#define P printf

main(i,r)
{F(i=0; i<100; ++i)
   r=f(i,0,0,0,0),P("[%u|%u]",i,r);
 R  0;
}

/*
 158
 [0|0][1|0][2|0][3|0][4|1][5|0][6|0][7|0][8|2]
 [9|0][10|0][11|0][12|1][13|0][14|0][15|0][16|3]
 [17|0][18|0][19|0][20|1][21|0][22|0][23|0][24|2][25|1][26|0][27|0] [28|1]
 [29|0][30|0][31|0][32|4][33|0][34|0][35|0][36|1]
 [37|0][38|0][39|0][40|2][41|0]
 */


答:
PowerShell v2+, 64 bytes

```<code>((1..$args[0]|%{('I love','I hate')[$_%2]})-join' that ')+' it.'
</code>```

Rather straightforward. Loops from 1 up to the input $args[0], each iteration placing either 'I love' or 'I hate' on the pipeline, based on a pseudo-ternary for modulo-2 (i.e., it alternates back and forth, starting with 'I hate'). Those strings are encapsulated in parens and -joined with ' that ' to smush them together, then string concatenation ' it.' at the end.

Test Cases

```<code>PS C:\Tools\Scripts\golfing> 1..5|%{.\hate-love-conundrum.ps1 $_}
I hate it.
I hate that I love it.
I hate that I love that I hate it.
I hate that I love that I hate that I love it.
I hate that I love that I hate that I love that I hate it.
</code>```

Title: Hate/love conundrum

Body:
PowerShell v2+, 64 bytes

((1..$args[0]|%{('I love','I hate')[$_%2]})-join' that ')+' it.'

Rather straightforward. Loops from 1 up to the input $args[0], each iteration placing either 'I love' or 'I hate' on the pipeline, based on a pseudo-ternary for modulo-2 (i.e., it alternates back and forth, starting with 'I hate'). Those strings are encapsulated in parens and -joined with ' that ' to smush them together, then string concatenation ' it.' at the end.

Test Cases

PS C:\Tools\Scripts\golfing> 1..5|%{.\hate-love-conundrum.ps1 $_}
I hate it.
I hate that I love it.
I hate that I love that I hate it.
I hate that I love that I hate that I love it.
I hate that I love that I hate that I love that I hate it.


答:
CJam, 11 bytes

```<code>ri_mf,\mF,-
</code>```

Try it online!

Explanation

```<code>ri_         Get an integer from input and duplicate it
   mf,      Get the number of prime factors (with repetition)
      \     Swap top 2 elements on the stack
       mF,  Get the number of prime factors (with exponents)
          - Subtract
</code>```

Title: Excessive Integers

Body:
For a positive integer n with the prime factorization n = p1^e1 * p2^e2 * ... pk^ek where p1,...,pk are primes and e1,...,ek are positive integers, we can define two functions:

Ω(n) = e1+e2+...+ek the number of prime divisors (counted with multiplicity) (A001222)

ω(n) = k the number of distinct prime divisors. (A001221)

With those two functions we define the excess e(n) = Ω(n) - ω(n) (A046660). This can be considered as a measure of how close a number is to being squarefree.

Challenge

For a given positive integer n return e(n).

Examples

For n = 12 = 2^2 * 3 we have Ω(12) = 2+1 and ω(12) = 2 and therefore e(12) = Ω(12) - ω(12) = 1. For any squarefree number n we obivously have e(n) = 0. The first few terms are

```<code>1       0
2       0
3       0
4       1
5       0
6       0
7       0
8       2
9       1
10      0
11      0
12      1
13      0
14      0
15      0
</code>```

Some more details in the OEIS wiki.

Body:
CJam, 11 bytes

ri_mf,\mF,-

Try it online!

Explanation

ri_         Get an integer from input and duplicate it
   mf,      Get the number of prime factors (with repetition)
      \     Swap top 2 elements on the stack
       mF,  Get the number of prime factors (with exponents)
          - Subtract


问:
Bitwise Operators in Brainfuck
Your task is to create one brainfuck program for each of the following binary operators. Each program should take one or two 8-bit numbers (A and B) from input and calculate the specified operation:

A XOR B

A AND B

A OR B

A Shifted Left by 1 (circular shift)

NOT A

You do not have to implement all 5. Score is calculated by:

```<code>#totalCharacters + {4000 * #problemsNotCompleted}
</code>```

So valid scores are from zero (best) to 20,000(nothing completed).

I don't care where you store the result, or whether or not you preserve the input. Assume 8-bit cells, and as many empty cells as you need to the right only.

You may assume the numbers are already in whatever memory location works best for you, so you don't need to worry about IO operations.

Title: Bitwise Operators in Brainfuck

Body:
Score: 686

All snippets assume that the numbers are already loaded in cell 0 and 1 and that the pointer points to cell 0.
I can add an atoi snippet later if that's required for the challenge. For now, you can try the code like this:

+++++++++>    number 1
++++<         number 2

XOR, 221

Result is written to cell 10, pointer ends at cell 5

>>>>>++++++++[-<<<<<[->>+<<[->>->+<]>>[->>>>+<<]<<<<]>>>[-<<<+>>>]<<[->+<[->->+>
>>>>]>[->>>>>+>>]<<<<<<<<]>>[-<<+>>]>>>[->>+<<]>[>[-<->]<[->+<]]>[[-]<<<[->+>-<<
]>[-<+>]+>+++++++[-<[->>++<<]>>[-<<+>>]<]<[->>>>+<<<<]>>]<<<]

AND, 209

Result is written to cell 10, pointer ends at cell 5

>>>>>++++++++[-<<<<<[->>+<<[->>->+<]>>[->>>>+<<]<<<<]>>>[-<<<+>>>]<<[->+<[->->+>
>>>>]>[->>>>>+>>]<<<<<<<<]>>[-<<+>>]>>>[->[->+<]<]>[-]>[-<<<[->+>-<<]>[-<+>]+>++
+++++[-<[->>++<<]>>[-<<+>>]<]<[->>>>+<<<<]>>]<<<]

OR, 211

Result is written to cell 10, pointer ends at cell 5

>>>>>++++++++[-<<<<<[->>+<<[->>->+<]>>[->>>>+<<]<<<<]>>>[-<<<+>>>]<<[->+<[->->+>
>>>>]>[->>>>>+>>]<<<<<<<<]>>[-<<+>>]>>>[->>+<<]>[->+<]>[[-]<<<[->+>-<<]>[-<+>]+>
+++++++[-<[->>++<<]>>[-<<+>>]<]<[->>>>+<<<<]>>]<<<]

Rotate Left, 38

Result is written to cell 1, pointer ends at cell 4

[->++>+<[>-]>[->>+<]<<<]>>>>[-<<<+>>>]

NOT, 7

Result is written to cell 1, pointer ends at cell 0

+[+>+<]

Explanation:

XOR, AND and OR all work in a similiar fashion: Calculate n/2 for each number
and remember n mod 2. Calculate the logical XOR/AND/OR for the single bits. If
the resulting bit is set, add 2^n to the result. Repeat that 8 times.

This is the memory layout I used:

 0      1        2        3      4        5         6        7
n1  |  n2  |  marker  |  n/2  |  0  |  counter  |  bit1  |  bit2  |

  8        9        10
temp  |  temp  |  result

Here's the source for XOR (numbers indicate where the pointer is at that time):

>>>>>
++++ ++++ counter
[
    -
    <<<<<

    divide n1 by two
    [ 0
        -
        >>+ set marker 2
        << 0
        [->>->+<] dec marker inc n/2
        >> 2 or 4
        [->>>>+<<]
        <<<<
    ]
    >>>
    [-<<<+>>>]
    <<

    divide n2 by two
    [ 1
        -
        >+ set marker 2
        < 1
        [->->+>>>>>] dec marker inc n/2
        > 2 or 9
        [->>>>>+>>]
        <<<< <<<<
    ]
    >>[-<<+>>] 3

    >>> 6

    [->>+<<]>[>[-<->]<[->+<]]>  one bit xor 8

    [
        [-]<<< 5
        [->+>-<<] copy counter negative
        > 6
        [-<+>]
        +> 7
        ++++ +++  cell 6 contains a one and cell 7 how many bits to shift
        [-<[->>++<<]>>[-<<+>>]<]  2^n
        < 6
        [->>>>+<<<<]
        >> 8
    ]

    <<<
]

For left rotate, once again there is a marker in cell 2 to determine if 2n
is zero, since you can only determine if a cell is non-zero directly. If
so, a carry bit is written to cell 4 and later added to 2n. This is the memory
layout:

0      1        2       3       4
n  |  2n  |  marker  |  0  |  carry


问:
DNA Encode a String

Challenge

You must write an encoder (and a separate decoder) which takes a string as input and outputs the string encoded in the style of a strand of DNA.

DNA

DNA is made up of four types of nucleotide:

Adenine (A)

Thymine (T)

Cytosine (C)

Guanine (G)

Adenine and thymine pair up together to make AT or TA. Similarly, cytosine and guanine pair up together to make CG or GC.

Let's call these pairs units. This means that your encoded string is only allowed to contain the four units AT, TA, CG and GC.

This means that:

```<code>ATTAGACG
</code>```

Would be invalid because it contains the unit GA, which is impossible.

Similarly,

```<code>TAGCGCCGATA
</code>```

Is invalid because the final A does not have a thymine to pair up with.

Example

You must encode the following example text and use its encoded length as part of your score:

I have a friend who's an artist and has sometimes taken a view which I don't agree with very well. He'll hold up a flower and say "look how beautiful it is," and I'll agree. Then he says "I as an artist can see how beautiful this is but you as a scientist take this all apart and it becomes a dull thing," and I think that he's kind of nutty. First of all, the beauty that he sees is available to other people and to me too, I believe. Although I may not be quite as refined aesthetically as he is ... I can appreciate the beauty of a flower. At the same time, I see much more about the flower than he sees. I could imagine the cells in there, the complicated actions inside, which also have a beauty. I mean it's not just beauty at this dimension, at one centimeter; there's also beauty at smaller dimensions, the inner structure, also the processes. The fact that the colors in the flower evolved in order to attract insects to pollinate it is interesting; it means that insects can see the color. It adds a question: does this aesthetic sense also exist in the lower forms? Why is it aesthetic? All kinds of interesting questions which the science knowledge only adds to the excitement, the mystery and the awe of a flower. It only adds. I don't understand how it subtracts.

Bounty

If you answer this challenge in the language DNA#, I will offer a 100 to 200 rep bounty.

Rules

Your encoder and decoder programs must work for any string supplied. Therefore, your encoder must produce a genuine encoding and your decoder should not simply hardcode the example text.

You must support all printable ASCII characters:

```<code> !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
</code>```

If you can support more characters, that is acceptable.

Scoring

Your score is how long in characters (not units) the encoded version of the above text plus the length in bytes of your decoder and your encoder.

Winning

The program with the lowest score wins.

答:
DNA# : 10216 + 852 + 384 = 11452 bytes

This is not exactly tested, as I haven't gotten a hold of a working interpreter... There are probably mistakes

I use a simple brute force approach so far where each character is read in, then broken up into 2 bit blocks with AT = 00; TA = 01; CG = 10; GC = 11. The sample text is 1277 ASCII characters, and it takes 4 codes (2 bits) to encode each 8 bit char: 1277 * 4 * 2 = 10216 bytes

 Encoder

852 bytes - line form

```<code>GCGCGCTAATATATTAATTAATTAATTAATTAATTAATTAATTATACGCGCGATATTAATATGCATGCCGCGGCTACGATATGCCGCGATATATTAATTAATTAATTAATTAATTAATTAATTATACGCGCGATTAATATATTAATTAATTAATTAATTAATTAATTAATTAATTATACGCGCGATTAATTAATTAATGCATGCGCTAATATATTAATTAATTAATTAATTAATTAATTAATTAATTAATTAATTAATTAATTAATTAATTAATTAATTAATTAATTAATATATCGATCGATCGATCGATCGATCGATCGATCGATCGATCGATCGATCGATCGATCGATCGATCGATCGATCGATCGATGCATGCATCGGCCGGCTAATATATCGATCGATCGATCGATCGATCGATCGATCGATCGATCGATCGATCGATCGATCGATCGATCGATCGATATATTAATTAATTAATTAATTAATTAATTAATTAATTAATTAATTAATTAATTAATTAATTAATTAATTAATGCATGCATCGGCCGGCTAATATATTAATTAATTAATTAATATATCGATCGATCGATCGATGCATGCATCGGCCGATATGCATATATGCATATGCATGCATGCATCGGCTAATTAATATTAATATGCATGCCGCGCGATATGCCGCGTACGATGCCGCGATGCATGCTATAATATATATCGCGATATATATGCTAATCGGCCGATTAATTAATTAATTAATGCCGATATATCGCGATATTAATATGCATGCCGCGATATGCTAATCGGCCGATATGCTAATCGGCCGGCCGATGCATGCGCCGATGCATGCGCGCGCCG
</code>```

224 bytes - symbol form:

```<code>,[>++++++++*=X>:=<<X[/=<X>++++++++*=X+>+++++++++*=X+++<<[>+++++++++++++++++++>-------------------<<-][>----------------->+++++++++++++++++<<-][>++++>----<<-]>.>.<<<-[+>:=<<X/=<X*=<X<<-=>>X>>[-]++++</=>X>:=<<X>[-]>[-]]<<]<<,]
</code>```

and with variable names and some messy comments...

```<code>DNA# dna encoder

a = input              //get first char
[                      //for each char
    b = 64             //divisor to get first 2 bits
    c = a              //initialize as a
    [                  //while c != 0
        c /= b
        d = 65         //first print char
        e = 84         //second print char
        c              //select c
        [              //if c > 0 (3,2,1)
            d + 19
            e - 19
            c - 1
        ]
        [              //if c > 1 (3,2)
            d - 17
            e + 17
            c - 1
        ]
        [              //if c > 2 (3)
            d + 4
            e - 4
            c - 1
        ]              //c is now 0 (hopefully)
        print d
        print e
        b - 1
        [              //if b is not 1 (last 2 bits)
            b + 1      //reset b
            c = a      //trash top 2 bits (modulus algorithm)
            c /= b
            c *= b
            a -= c
            c = 0      //reset c
            c + 4
            b /= c     //b >> 2
            c = a      //copy a again for next 2 bits
            d = 0      //get a 0 value so we don't loop
        ]
        c              //select c (0 if done with char: exit loop and get next char)
    ]
    a = input          //get next char
]</code>```

Decoder

384 bytes - line form

```<code>GCGCGCGCGCTAATATATATATTAATTAATTAATTAGCTAATATATTAATTAATTAATTAATTAATTAATTAATTAATTATACGCGCGATTAATTAATTAATGCATGCATGCTATAATATATATATATCGCGGCTAATATATTAATGCATTAATTAATTAATTAATTAATTAATTAATTAATTAATTAATTAATTAATTAATTAATTAATTAATTAATTAATTAGCCGGCTAATATATTAATGCATCGATCGATCGATCGATCGATCGGCCGGCTAATATATTAATGCATTAATTAATTAATTAGCCGATTAATTAATTAATTAATATTACGATGCCGCGATGCGCGCGCGCATATATATATCGGCCGATGCGCATATGCGCCG
</code>```

99 bytes - symbol form

```<code>,,[>>++++[>+++++++++*=X+++<<<-=>>>X[>+<+++++++++++++++++++][>+<------][>+<++++]++++>*=<X<,,>>-]<.<]
</code>```

var names...

```<code>DNA# dna decoder

,
,                  /* read second char into a*/
[                  /* for each set of 4 pairs */
    c = 4          /* loop iterator */
    [
        a - 84     /* if pair was AT (65,84): don't increment b */
        [
            b + 1
            a + 19 /* if pair was TA (84,65): increment b once */
        ]
        [
            b + 1
            a - 6  /* if pair was CG (67,71): increment b twice */
        ]
        [
            b + 1
            a + 4  /* if pair was GC (71,67): increment b three times */
        ]
        a = 4
        b *= a     /* shift b up 2 bits */
        a,,        /* get next char (skip one) */
        c - 1      /* decrement loop iterator: exit loop on 0 */
    ]
    b
    print          /* output b in ASCII */
    a              /* select a (next char) */
]                  /* end if next char is 0 (null terminated string) */</code>```

If anyone finds a mistake or is able to run the web interpreter feel free to tell me how wrong I am :P

Title: DNA Encode a String

Body:
DNA# : 10216 + 852 + 384 = 11452 bytes

This is not exactly tested, as I haven't gotten a hold of a working interpreter... There are probably mistakes

I use a simple brute force approach so far where each character is read in, then broken up into 2 bit blocks with AT = 00; TA = 01; CG = 10; GC = 11. The sample text is 1277 ASCII characters, and it takes 4 codes (2 bits) to encode each 8 bit char: 1277 * 4 * 2 = 10216 bytes

 Encoder

852 bytes - line form

GCGCGCTAATATATTAATTAATTAATTAATTAATTAATTAATTATACGCGCGATATTAATATGCATGCCGCGGCTACGATATGCCGCGATATATTAATTAATTAATTAATTAATTAATTAATTATACGCGCGATTAATATATTAATTAATTAATTAATTAATTAATTAATTAATTATACGCGCGATTAATTAATTAATGCATGCGCTAATATATTAATTAATTAATTAATTAATTAATTAATTAATTAATTAATTAATTAATTAATTAATTAATTAATTAATTAATTAATATATCGATCGATCGATCGATCGATCGATCGATCGATCGATCGATCGATCGATCGATCGATCGATCGATCGATCGATCGATGCATGCATCGGCCGGCTAATATATCGATCGATCGATCGATCGATCGATCGATCGATCGATCGATCGATCGATCGATCGATCGATCGATCGATATATTAATTAATTAATTAATTAATTAATTAATTAATTAATTAATTAATTAATTAATTAATTAATTAATTAATGCATGCATCGGCCGGCTAATATATTAATTAATTAATTAATATATCGATCGATCGATCGATGCATGCATCGGCCGATATGCATATATGCATATGCATGCATGCATCGGCTAATTAATATTAATATGCATGCCGCGCGATATGCCGCGTACGATGCCGCGATGCATGCTATAATATATATCGCGATATATATGCTAATCGGCCGATTAATTAATTAATTAATGCCGATATATCGCGATATTAATATGCATGCCGCGATATGCTAATCGGCCGATATGCTAATCGGCCGGCCGATGCATGCGCCGATGCATGCGCGCGCCG

224 bytes - symbol form:

,[>++++++++*=X>:=<<X[/=<X>++++++++*=X+>+++++++++*=X+++<<[>+++++++++++++++++++>-------------------<<-][>----------------->+++++++++++++++++<<-][>++++>----<<-]>.>.<<<-[+>:=<<X/=<X*=<X<<-=>>X>>[-]++++</=>X>:=<<X>[-]>[-]]<<]<<,]

and with variable names and some messy comments...

DNA# dna encoder

a = input              //get first char
[                      //for each char
    b = 64             //divisor to get first 2 bits
    c = a              //initialize as a
    [                  //while c != 0
        c /= b
        d = 65         //first print char
        e = 84         //second print char
        c              //select c
        [              //if c > 0 (3,2,1)
            d + 19
            e - 19
            c - 1
        ]
        [              //if c > 1 (3,2)
            d - 17
            e + 17
            c - 1
        ]
        [              //if c > 2 (3)
            d + 4
            e - 4
            c - 1
        ]              //c is now 0 (hopefully)
        print d
        print e
        b - 1
        [              //if b is not 1 (last 2 bits)
            b + 1      //reset b
            c = a      //trash top 2 bits (modulus algorithm)
            c /= b
            c *= b
            a -= c
            c = 0      //reset c
            c + 4
            b /= c     //b >> 2
            c = a      //copy a again for next 2 bits
            d = 0      //get a 0 value so we don't loop
        ]
        c              //select c (0 if done with char: exit loop and get next char)
    ]
    a = input          //get next char
]

Decoder

384 bytes - line form

GCGCGCGCGCTAATATATATATTAATTAATTAATTAGCTAATATATTAATTAATTAATTAATTAATTAATTAATTAATTATACGCGCGATTAATTAATTAATGCATGCATGCTATAATATATATATATCGCGGCTAATATATTAATGCATTAATTAATTAATTAATTAATTAATTAATTAATTAATTAATTAATTAATTAATTAATTAATTAATTAATTAATTAGCCGGCTAATATATTAATGCATCGATCGATCGATCGATCGATCGGCCGGCTAATATATTAATGCATTAATTAATTAATTAGCCGATTAATTAATTAATTAATATTACGATGCCGCGATGCGCGCGCGCATATATATATCGGCCGATGCGCATATGCGCCG

99 bytes - symbol form

,,[>>++++[>+++++++++*=X+++<<<-=>>>X[>+<+++++++++++++++++++][>+<------][>+<++++]++++>*=<X<,,>>-]<.<]

var names...

DNA# dna decoder

,
,                  /* read second char into a*/
[                  /* for each set of 4 pairs */
    c = 4          /* loop iterator */
    [
        a - 84     /* if pair was AT (65,84): don't increment b */
        [
            b + 1
            a + 19 /* if pair was TA (84,65): increment b once */
        ]
        [
            b + 1
            a - 6  /* if pair was CG (67,71): increment b twice */
        ]
        [
            b + 1
            a + 4  /* if pair was GC (71,67): increment b three times */
        ]
        a = 4
        b *= a     /* shift b up 2 bits */
        a,,        /* get next char (skip one) */
        c - 1      /* decrement loop iterator: exit loop on 0 */
    ]
    b
    print          /* output b in ASCII */
    a              /* select a (next char) */
]                  /* end if next char is 0 (null terminated string) */

If anyone finds a mistake or is able to run the web interpreter feel free to tell me how wrong I am :P


答:
MATL, 37 bytes

```<code>:"2@o3]Qv'hate I that it. love'Ybw)Zc
</code>```

Try it online!

Explanation

The code is based on the following mapping from numbers to strings:

```<code>0: 'love'
1: 'hate'
2: 'I'
3: 'that'
4: 'it.'
</code>```

The program pushes numbers to the string in groups of three: 2, 0, 3; then 2, 1, 3; then 2, 0, 3; ... as many times as the input n. After that, the final 3 is transformed into a 4, the mapping is applied to transform numbers to strings, and the strings are joined using space as separator.

```<code>:                         % Input n implicitly. Push range [1 2 ... n]
"                         % For each
  2                       %   Push 2
  @o                      %   Iteration index modulo 2: pushes 0 or 1
  3                       %   Push 3
]                         % End
Q                         % Add 1 to the last 3
v                         % Concatenate stack contents into a numeric column vector
'hate I that it. love'    % Push this string
Yb                        % Split at spaces. Gives a cell array of five strings
w                         % Swap to move numeric vector to top
)                         % Index cell array of strings with that vector. Indexing
                          % is 1-based and modular, so 0 refers to the last string.
                          % This gives a cell array of (repeated) strings
Zc                        % Join those strings by spaces. Display implicitly
</code>```

Title: Hate/love conundrum

Body:
MATL, 37 bytes

:"2@o3]Qv'hate I that it. love'Ybw)Zc

Try it online!

Explanation

The code is based on the following mapping from numbers to strings:

0: 'love'
1: 'hate'
2: 'I'
3: 'that'
4: 'it.'

The program pushes numbers to the string in groups of three: 2, 0, 3; then 2, 1, 3; then 2, 0, 3; ... as many times as the input n. After that, the final 3 is transformed into a 4, the mapping is applied to transform numbers to strings, and the strings are joined using space as separator.

:                         % Input n implicitly. Push range [1 2 ... n]
"                         % For each
  2                       %   Push 2
  @o                      %   Iteration index modulo 2: pushes 0 or 1
  3                       %   Push 3
]                         % End
Q                         % Add 1 to the last 3
v                         % Concatenate stack contents into a numeric column vector
'hate I that it. love'    % Push this string
Yb                        % Split at spaces. Gives a cell array of five strings
w                         % Swap to move numeric vector to top
)                         % Index cell array of strings with that vector. Indexing
                          % is 1-based and modular, so 0 refers to the last string.
                          % This gives a cell array of (repeated) strings
Zc                        % Join those strings by spaces. Display implicitly


Title: Hate/love conundrum

Body:
JavaScript (ES6), 68 bytes

f=(n,i)=>n?(i?' that I ':'I ')+(i&1?'love':'hate')+f(n-1,-~i):' it.'

document.write('<pre>'+[ 1, 2, 3, 4, 10, 100 ].map(c=>c+': '+f(c)).join`\n`);


问:
Roll the Alphabet into a Spiral
Write a program or function that, when given n, will print a spiral n characters long made up of the Latin alphabet ABCDEFGHIJKLMNOPQRSTUVWXYZ repeated as needed. This spiral should run through the alphabet only forwards.

Related to Alphabet Spiral, though the spiral runs through the alphabet forwards and backwards, and the spiral is constant.

Test cases

```<code>4   AB
    DC

40   UVWXYZ
     TGHIJA
    NSFABKB
    MREDCLC
    LQPONMD
    KJIHGFE

0

10  GHIJ
    FAB
    EDC

1000    UVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ
        TGHIJKLMNOPQRSTUVWXYZABCDEFGHIJA
        SFABCDEFGHIJKLMNOPQRSTUVWXYZABKB
        REZCDEFGHIJKLMNOPQRSTUVWXYZABCLC
        QDYBMNOPQRSTUVWXYZABCDEFGHIJCDMD
        PCXALEFGHIJKLMNOPQRSTUVWXYZKDENE
        OBWZKDEFGHIJKLMNOPQRSTUVWXALEFOF
        NAVYJCDMNOPQRSTUVWXYZABCDYBMFGPG
        MZUXIBCLCDEFGHIJKLMNOPQREZCNGHQH
        LYTWHABKBABCDEFGHIJKLMNSFADOHIRI
        KXSVGZAJAZGHIJKLMNOPQROTGBEPIJSJ
        JWRUFYZIZYFUVWXYZABCDSPUHCFQJKTK
        IVQTEXYHYXETQRSTUVWXETQVIDGRKLUL
        HUPSDWXGXWDSPUVWXYZYFURWJEHSLMVM
        GTORCVWFWVCROTGHIJAZGVSXKFITMNWN
        FSNQBUVEVUBQNSFABKBAHWTYLGJUNOXO
        ERMPATUDUTAPMREDCLCBIXUZMHKVOPYP
        DQLOZSTCTSZOLQPONMDCJYVANILWPQZQ
        CPKNYRSBSRYNKJIHGFEDKZWBOJMXQRAR
        BOJMXQRARQXMLKJIHGFELAXCPKNYRSBS
        ANILWPQZQPWVUTSRQPONMBYDQLOZSTCT
        ZMHKVOPYPONMLKJIHGFEDCZERMPATUDU
        YLGJUNOXONMLKJIHGFEDCBAFSNQBUVEV
        XKFITMNWVUTSRQPONMLKJIHGTORCVWFW
        WJEHSLMLKJIHGFEDCBAZYXWVUPSDWXGX
        VIDGRKJIHGFEDCBAZYXWVUTSRQTEXYHY
        UHCFQPONMLKJIHGFEDCBAZYXWVUFYZIZ
        TGBEDCBAZYXWVUTSRQPONMLKJIHGZAJA
        SFAZYXWVUTSRQPONMLKJIHGFEDCBABKB
        REDCBAZYXWVUTSRQPONMLKJIHGFEDCLC
        QPONMLKJIHGFEDCBAZYXWVUTSRQPONMD
                                LKJIHGFE
</code>```

Rules

Your input will be a non-negative integer 0 <= n <= 1000, but your code should theoretically handle any non-negative integer.

Your output format may be in any sane format, with delimiters if necessary.

Rotations and reflections are equivalent.

Your alphabet may be uppercase or lowercase.

The empty spaces in your spiral may be filled in with whatever non-alphabetic nulls you see fit.

The spiral itself may be in any shape you see fit. Rectangular spirals work best with ASCII solutions, but graphical solutions may be shorter with circular spirals.

Leading and trailing spaces and newlines are allowed.

This is code golf. The shortest answer in bytes (or equivalent) wins.

As always, if anything is unclear or incorrect, please let me know in the comments. Good luck and good golfing!

答:
Javascript (ES6), <s>203</s> 201 bytes

```<code>n=>{for(a=[],i=d=k=z=0,p=526,j=1;i<n;){p+=[1,32,-1,-32][d&3];j--||(((z^=1)||k++),j=k,d++);(a[y=p>>5]=(a[y]||Array(32).fill` `))[p&31]=String.fromCharCode(65+(i++%26))}return a.map(r=>r.join``).join`
`}
</code>```

Demo

The demo below should be preferably run in full page.

let f =

n=>{for(a=[],i=d=k=z=0,p=526,j=1;i<n;){p+=[1,32,-1,-32][d&3];j--||(((z^=1)||k++),j=k,d++);(a[y=p>>5]=(a[y]||Array(32).fill` `))[p&31]=String.fromCharCode(65+(i++%26))}return a.map(r=>r.join``).join`
`}

function draw(n) {
  document.getElementById('v').innerHTML = n;
  document.getElementById('o').innerHTML = f(n);
}
draw(500);```
<pre class="snippet-code-css lang-css prettyprint-override"><code>pre {font-size:10px}</code>```

<input type="range" min="1" max="1000" oninput="draw(this.value)" style="width:500px">
```</code>```

Title: Roll the Alphabet into a Spiral

Body:
Javascript (ES6), <s>203</s> 201 bytes

n=>{for(a=[],i=d=k=z=0,p=526,j=1;i<n;){p+=[1,32,-1,-32][d&3];j--||(((z^=1)||k++),j=k,d++);(a[y=p>>5]=(a[y]||Array(32).fill` `))[p&31]=String.fromCharCode(65+(i++%26))}return a.map(r=>r.join``).join`
`}

Demo

The demo below should be preferably run in full page.

let f =

n=>{for(a=[],i=d=k=z=0,p=526,j=1;i<n;){p+=[1,32,-1,-32][d&3];j--||(((z^=1)||k++),j=k,d++);(a[y=p>>5]=(a[y]||Array(32).fill` `))[p&31]=String.fromCharCode(65+(i++%26))}return a.map(r=>r.join``).join`
`}

function draw(n) {
  document.getElementById('v').innerHTML = n;
  document.getElementById('o').innerHTML = f(n);
}
draw(500);

pre {font-size:10px}

<input type="range" min="1" max="1000" oninput="draw(this.value)" style="width:500px"><span id="v"></span><pre id="o"></pre>


问:
Quixels - Quantum Pixels

Introduction

A quixel is a quantum pixel. Similar to a classical pixel, it is represented with 3 integer values (Red, Green, Blue). However, quixels are in a super position of these 3 states instead of a combination. This super position only lasts until the quixel is observed at which point it collapses to one of three classical pixels; RGB(255,0,0), RGB(0,255,0) and RGB(0,0,255).

Specification

Representation

Each quixel is represented as an array of 3 integers between 0 and 255, r, g and b respectively.

Super Positions

Each quixel is in a super position between the Red, Blue and Green states represented by R, G and B respectively.

Observation

When each quixel is observed it collapses into one of the three states. The probability of each classical state is R = (r + 1) / (r + g + b +3), G = (g + 1) / (r + g + b + 3) and B = (b + 1) / (r + g + b + 3). This way each classical state always as a non-zero probability of showing up.

Input

The function or program should take a image of quixels. How it does this is flexible. A filename, using a multi-dimensional array, etc are all acceptable.

Output

The function or program should produce an image of classical pixels. The data structure for this produced image is also flexible. Note that all of the pixels should be one of these three: RGB(255,0,0), RGB(0,255,0) and RGB(0,0,255)

The output should not be deterministic; these are quantum pixels! The same input should result in different outputs.

If your language has no way of generating a random number, you can take random bytes as input

Scoring

This is code-golf so fewest bytes win.

Images

Mona Lisa by Leonardo da Vinci

Starry Night by Vincent van Gogh

Persistence of Memory by Salvador Dali

Teddy Roosevelt VS. Bigfoot by SharpWriter

答:
Pyth - <s>11</s> 10 bytes

Takes RGB 2d bitmap and outputs bitmap with indexed 3-bit color.

```<code>mLOs.emkbk
</code>```

That level of nesting is hurting my head.

Try it online here.

Title: Quixels - Quantum Pixels

Body:
Pyth - <s>11</s> 10 bytes

Takes RGB 2d bitmap and outputs bitmap with indexed 3-bit color.

mLOs.emkbk

That level of nesting is hurting my head.

Try it online here.


答:
Lua , 75 Bytes

```<code>n=io.read();print(('I hate that I love that '):rep(n):sub(1,n*12-5)..'it.')
</code>```

Title: Hate/love conundrum

Body:
Lua , 75 Bytes

n=io.read();print(('I hate that I love that '):rep(n):sub(1,n*12-5)..'it.')


答:
Pyth - 17 bytes

This one actually handles the special cases with consecutive char correctly.

```<code> XZOKrz8Or_1 2r9K
</code>```

Test Suite.

Title: Randomly Misspell a Word

Body:
Inspired by this CR question (please don't kill me for browsing CR)

Spec

The probabilities of misspelling a word are:

1/3 of the time don't change the output

1/3 of the time remove a random character

1/3 of the time duplicate a random character

The chance for removing/duplicating a given character in the input should be the same for all chars.

If two consecutive characters are the same (case-sensitive), the probability of one of them being modified should be the same as if they are one character. I.e. the outputs for AA (which are AA or A or AAA) should all have the same probability.

The input will only contain of letters for simplicity.

Examples

First line is input, following lines are all possible misspellings. Each line should have the same probability of being output, the input is excluded in the examples but it should still have a 1/3 probability of output.

```<code>foo

fo
oo
ffoo
fooo
</code>```

```<code>PPCG

PPC
PPG
PCG
PPPCG
PPCCG
PPCGG
</code>```

Body:
Pyth - 17 bytes

This one actually handles the special cases with consecutive char correctly.

 XZOKrz8Or_1 2r9K

Test Suite.


答:
PHP >= 5.3, <s>139</s> 136 bytes (and no errors thrown)

```<code>array_map(function($a,$b){echo$a.$b;},preg_split("/[aeiou]/",$s=$argv[1]),str_split(str_shuffle(implode(preg_split("/[^aeiou]/",$s)))));
</code>```

Title: Sheffle tho vawols ureund!

Body:
Given an input string, output that string with all vowels a, e, i, o and u swapped at random between each other.

For example, in the string this is a test, there are 4 vowels: [i, i, a, e]. A valid shuffling of those vowels could be [a, i, e, i] therefore yielding the output thas is e tist.

About shuffling

All shuffles shall be equally likely if we consider equal vowels to be distinct. For the example above, those 24 shuffles are possible:

```
[i<sub>1</sub>, i<sub>2</sub>, a, e]    [i<sub>1</sub>, i<sub>2</sub>, e, a]    [i<sub>1</sub>, a, i<sub>2</sub>, e]    [i<sub>1</sub>, a, e, i<sub>2</sub>]
[i<sub>1</sub>, e, i<sub>2</sub>, a]    [i<sub>1</sub>, e, a, i<sub>2</sub>]    [i<sub>2</sub>, i<sub>1</sub>, a, e]    [i<sub>2</sub>, i<sub>1</sub>, e, a]
[i<sub>2</sub>, a, i<sub>1</sub>, e]    [i<sub>2</sub>, a, e, i<sub>1</sub>]    [i<sub>2</sub>, e, i<sub>1</sub>, a]    [i<sub>2</sub>, e, a, i<sub>1</sub>]
[a, i<sub>1</sub>, i<sub>2</sub>, e]    [a, i<sub>1</sub>, e, i<sub>2</sub>]    [a, i<sub>2</sub>, i<sub>1</sub>, e]    [a, i<sub>2</sub>, e, i<sub>1</sub>]
[a, e, i<sub>1</sub>, i<sub>2</sub>]    [a, e, i<sub>2</sub>, i<sub>1</sub>]    [e, i<sub>1</sub>, i<sub>2</sub>, a]    [e, i<sub>1</sub>, a, i<sub>2</sub>]
[e, i<sub>2</sub>, i<sub>1</sub>, a]    [e, i<sub>2</sub>, a, i<sub>1</sub>]    [e, a, i<sub>1</sub>, i<sub>2</sub>]    [e, a, i<sub>2</sub>, i<sub>1</sub>]
```

Each one should be equally as likely.

You may not try random shuffles of the entire string until finding one where all vowels are in the right place. In short, your code's running time shall be constant if the input is constant.

Inputs and outputs

You may assume that all letters in the input will be lowercase or uppercase. You may also support mixed casing, though this won't give you any bonus.

The input will always consist of printable ASCII characters. All characters that are in the input shall be in the output, only the vowels must be shuffled around and nothing else.

The input can be empty. There is no guarantee that the input will contain at least one vowel or at least one non-vowel.

You may take the input from STDIN, as a function parameter, or anything similar.

You may print the output to STDOUT, return it from a function, or anything similar.

Test cases

The first line is the given input. The second line is one of the possible outputs.

```<code><empty string>
<empty string>

a
a

cwm
cwm

the quick brown fox jumps over the lazy dog.
tho qeuck brewn fax jumps ovir the lozy dog.

abcdefghijklmnopqrstuvwxyz
abcdefghujklmnipqrstovwxyz

programming puzzles & code golf
pregromming pezzlos & coda gulf

fatalize
fitaleza

martin ender
mirten ander
</code>```

Scoring

This is code-golf, sa tho shirtist enswer en bytes wons.

Body:
PHP >= 5.3, <s>139</s> 136 bytes (and no errors thrown)

array_map(function($a,$b){echo$a.$b;},preg_split("/[aeiou]/",$s=$argv[1]),str_split(str_shuffle(implode(preg_split("/[^aeiou]/",$s)))));


问:
Write an xkcd feed bot
The new xkcd feed bot room gave me an idea for a simple challenge.

Your code will have to monitor the xkcd website and output all the new comics to the user.

Specs

When first run it should just sit around waiting.

Then, when randall posts a new comic, within a minute, it should display the new comic in any of our usual standards for images (display, save, etc.)

If the comic is interactive and not a simple image, then print out the string "interactive comic".

This does not include the comics which are an image inside a link, those still have to be displayed normally.

After displaying the image, it should go back to waiting around for the next update.

Your program cannot access any sites except http://xkcd.com

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

答:
PowerShell v2+ & Default Browser, <s>215</s> 217 bytes

```<code>$l=date;for(){if(($x=([xml](iwr xkcd.com/rss.xml)).rss.channel.item[0]).pubdate-ge$l){if(($y=$x.description)-match'img src'){saps ($y-replace'<img src="'-replace'" .*')}else{echo "interactive comic"}}$l=date}
</code>```

WARNING: Running this as-is will likely make Randall very mad at you, due to the high frequency of calls to the RSS feed ... so, y'know, don't do that. (See below for an alternate version that can be used in a one-off manner)

Sets the $last time we displayed a comic to the result of Get-Date. Then, enter an infinite for loop.

Each iteration, we iwr (alias for Invoke-WebRequest) the RSS feed for the site. That's parsed as [xml] (yes, PowerShell can cast as XML), and the .rss.channel.item[0] thereof (i.e., the newest) is stored in $x. If the .pubDate is -ge$l (i.e., newer than the last comic we showed), we have a new comic to display.

So, we first check the .description field (saved in $y), to see if it matches img src. If so, we parse out the img from $y, and feed that to saps (alias for Start-Process). Since it's a URI, this relies on Windows' default behavior for "executing" a URI, that is, it opens the default browser to that location. (If this is too cheaty, let me know and we can iwr down the actual image and save it.)

Otherwise, we echo out that we've got an interactive comic.

In either case, we update our $l date to "now" since we just displayed a comic.

Saved 7 bytes thanks to Matt for reminding me that http:// can be implied

"Safe" version that executes just once and displays the latest comic

```<code>$l=(date).AddDays(-3);if(($x=([xml](iwr http://xkcd.com/rss.xml)).rss.channel.item[0]).pubdate-ge$l){if(($y=$x.description)-match'img src'){saps ($y-replace'<img src="'-replace'" .*')}else{echo "interactive comic"}}
</code>```

You can run this one safely to see how the logic works. It'll only execute once and only display the latest comic.

Title: Write an xkcd feed bot

Body:
PowerShell v2+ & Default Browser, <s>215</s> 217 bytes

$l=date;for(){if(($x=([xml](iwr xkcd.com/rss.xml)).rss.channel.item[0]).pubdate-ge$l){if(($y=$x.description)-match'img src'){saps ($y-replace'<img src="'-replace'" .*')}else{echo "interactive comic"}}$l=date}

WARNING: Running this as-is will likely make Randall very mad at you, due to the high frequency of calls to the RSS feed ... so, y'know, don't do that. (See below for an alternate version that can be used in a one-off manner)

Sets the $last time we displayed a comic to the result of Get-Date. Then, enter an infinite for loop.

Each iteration, we iwr (alias for Invoke-WebRequest) the RSS feed for the site. That's parsed as [xml] (yes, PowerShell can cast as XML), and the .rss.channel.item[0] thereof (i.e., the newest) is stored in $x. If the .pubDate is -ge$l (i.e., newer than the last comic we showed), we have a new comic to display.

So, we first check the .description field (saved in $y), to see if it matches img src. If so, we parse out the img from $y, and feed that to saps (alias for Start-Process). Since it's a URI, this relies on Windows' default behavior for "executing" a URI, that is, it opens the default browser to that location. (If this is too cheaty, let me know and we can iwr down the actual image and save it.)

Otherwise, we echo out that we've got an interactive comic.

In either case, we update our $l date to "now" since we just displayed a comic.

Saved 7 bytes thanks to Matt for reminding me that http:// can be implied

"Safe" version that executes just once and displays the latest comic

$l=(date).AddDays(-3);if(($x=([xml](iwr http://xkcd.com/rss.xml)).rss.channel.item[0]).pubdate-ge$l){if(($y=$x.description)-match'img src'){saps ($y-replace'<img src="'-replace'" .*')}else{echo "interactive comic"}}

You can run this one safely to see how the logic works. It'll only execute once and only display the latest comic.


答:
Perl  47 (+1) bytes • O(n) ⇒ 48 score

```<code>$#a-=2until$a[-/ \K/]lt$';push@a,$`,$'}{print@a
</code>```

Adding one byte for the -n option, as per the OP's instructions.

Sample input:

```<code>10:30 11:00
10:33 11:18
10:42 11:10
10:47 11:18
10:49 11:26
10:50 11:09
11:00 11:20
11:01 11:28
11:11 11:31
11:21 11:49
11:23 11:53
11:29 12:09
11:36 12:08
11:41 12:15
11:46 12:06
11:53 12:23
11:56 12:32
12:01 12:30
12:04 12:47
12:05 12:25
</code>```

Sample output:

```<code>$ perl -n prune-connections.pl < in.dat
10:30 11:00
10:50 11:09
11:00 11:20
11:01 11:28
11:11 11:31
11:21 11:49
11:23 11:53
11:46 12:06
11:53 12:23
12:05 12:25
</code>```

Input generator (PHP):

```<code><?php
  for($t = strtotime('10:30'); 20 > $i; $i++) {
    $r = rand(15, 45)*60;
    echo date('H:i', $t), ' ', date('H:i', $t+$r), PHP_EOL;
    $t += rand(0, 10)*60;
  }
?>
</code>```

Lemma:

If a route  is invalidated by some other route  where , and no other route between  and  invalidates , then  invalidates all routes from  to .

Because the routes are sorted by departure time, and ,  must necessarily have a later departure time than . Then, in order to invalidate ,  needs only to have an earlier arrival time. If there were a route between  and  which was not invalidated by , it would have an earlier arival time than , and hence, would have already invalidated .

Therefore, a linear time algorithm, which only checks if the current route invalidates the previous route is sufficient to solve the problem. When an invalidation is found, the route before the invalidated route must also be checked, until a route is not invalidated (or no valid routes remain). Because a route can only be invalidated once, no more than  routes will be invalidated in this manner.

Note that it is important that the invalid routes actually be removed from the list. If they are simply marked invalid (or set to null, etc.), this will result in  complexity, in the case that each new route invalidates all previous routes.

Proof that only one solution exists follows directly from the law of transitivity. If a route  is invalidated by , and  is invalidated by ,  is also invalidated by . In order for multiple solutions to exist, it must be possible to invalidate  without invalidating , but any route that invalidates  will also invalidate , and will lead to the same solution.

Title: Prune connections

Body:
John is writing a program that finds the best route from A to B using public transport. For a given pair of origin and destination the program calculates a set of routes with departure time and arrival time, such as this:

```<code>10:12 11:45
10:15 11:50
10:22 12:05
10:25 12:00
</code>```

As you see, the output may include a few routes that are superfluous in the sense that there is another route that starts later and ends earlier. Such routes are certainly never wanted by the user since he cat get out later to arrive sooner.

Your task, if you choose to accept it, is to write a program that prunes a set of routes such that all superfluous rules are eliminated.

Input

The input is a list of newline separated pairs of whitespace separated departure and arrival time in military format (hh:mm). Such a pair is called a route.

You may assume that all times are in the same day and that the arrival time is always later than the departure time. You may also assume that the list is orderer by departure times.

Output

The output is the same list as the input without redundant routes. A redundant route is a route for which another route exists in the list that has a later departure and an earlier arrival time. There must exist an order to remove all redundant routes such that in each step you can show the route that makes the removed route redundant. You don't have to output that order.

Extra credit

Prove or disprove that for each list of input routes there exists exactly one set of output routes.

Restriction

Usual codegolf rules apply

Scoring

To score, apply the function that gives an upper bound to your solutions complexity with your solution's total number of characters. Normalize your bounding function such that a solution length of two character yields a score of two.

For example, if your solution has 24 characters and a complexity of O(2n), your score is 4194304. If your solution has 123 characters and a complexity of O(n2) your score is 7564. If your solution has 200 characters and a complexity of O(n*logn), your score is 734.

I use this scoring method in order to encourage people to implement efficient solutions.

Body:
Perl  47 (+1) bytes • O(n) ⇒ 48 score

$#a-=2until$a[-/ \K/]lt$';push@a,$`,$'}{print@a

Adding one byte for the -n option, as per the OP's instructions.

Sample input:

10:30 11:00
10:33 11:18
10:42 11:10
10:47 11:18
10:49 11:26
10:50 11:09
11:00 11:20
11:01 11:28
11:11 11:31
11:21 11:49
11:23 11:53
11:29 12:09
11:36 12:08
11:41 12:15
11:46 12:06
11:53 12:23
11:56 12:32
12:01 12:30
12:04 12:47
12:05 12:25

Sample output:

$ perl -n prune-connections.pl < in.dat
10:30 11:00
10:50 11:09
11:00 11:20
11:01 11:28
11:11 11:31
11:21 11:49
11:23 11:53
11:46 12:06
11:53 12:23
12:05 12:25

Input generator (PHP):

<?php
  for($t = strtotime('10:30'); 20 > $i; $i++) {
    $r = rand(15, 45)*60;
    echo date('H:i', $t), ' ', date('H:i', $t+$r), PHP_EOL;
    $t += rand(0, 10)*60;
  }
?>

Lemma:

If a route  is invalidated by some other route  where , and no other route between  and  invalidates , then  invalidates all routes from  to .

Because the routes are sorted by departure time, and ,  must necessarily have a later departure time than . Then, in order to invalidate ,  needs only to have an earlier arrival time. If there were a route between  and  which was not invalidated by , it would have an earlier arival time than , and hence, would have already invalidated .

Therefore, a linear time algorithm, which only checks if the current route invalidates the previous route is sufficient to solve the problem. When an invalidation is found, the route before the invalidated route must also be checked, until a route is not invalidated (or no valid routes remain). Because a route can only be invalidated once, no more than  routes will be invalidated in this manner.

Note that it is important that the invalid routes actually be removed from the list. If they are simply marked invalid (or set to null, etc.), this will result in  complexity, in the case that each new route invalidates all previous routes.

Proof that only one solution exists follows directly from the law of transitivity. If a route  is invalidated by , and  is invalidated by ,  is also invalidated by . In order for multiple solutions to exist, it must be possible to invalidate  without invalidating , but any route that invalidates  will also invalidate , and will lead to the same solution.


答:
Node.js (5.6.0), 5104 + 125 + 122 = 5351

I was originally working in JavaScript, but Node.js provides compression much more easily. Thanks Neil for helping trim out 5 bytes on the encoder!

Encoder (125 bytes):

s=>[...require('zlib').deflateRawSync(s)].map(a=>('000'+a.toString(4)).slice(-4).replace(/./g,b=>'ATCG'[b]+'TAGC'[b])).join``
```
<p><strong>Decoder (122 bytes):</strong></p>
<pre class="lang-js prettyprint-override"><code>s=>require('zlib').inflateRawSync(Buffer(s.replace(/../g,a=>'ATCG'.search(a[0])).match(/..../g).map(a=>parseInt(a,4))))+''
</code>```

DNA Sequence (5104 bytes):

```<code>TATATATATATATAATGCATCGTACGATGCCGGCTACGGCATGCATATATATGCATGCGCGCTAATTATATATACGATCGATCGGCCGTAGCATGCATATCGTAGCGCATCGATATATTACGTAGCTAGCATATGCCGCGATATCGTATAGCCGCGATCGCGGCCGTAATATGCGCGCTAATATCGGCATGCTACGATCGATGCATGCCGGCATTAATTACGCGTATACGTATAGCTAATTAATTATAATCGCGCGATTAGCCGGCGCGCGCTAGCGCTAATTAGCGCCGCGTATATAGCCGATCGTATACGTAATCGGCATTAATATCGATCGTAGCATCGGCTATACGGCTAATCGATGCGCCGTATAATTAATTATAATGCCGGCCGATATGCATGCATATTATACGGCCGCGCGTATAATGCATCGATTAGCCGTACGCGTAATTAGCTATACGTAATCGTACGTAGCCGCGTATACGTAATATATCGCGTAATTATAATCGATCGGCTACGCGCGGCGCCGATATGCTAGCATCGATCGTAATATGCTAATCGTATACGTATATACGTACGCGATCGGCATGCATGCATCGCGGCTATACGTACGGCCGATATGCATTAGCATATCGTAGCTAATCGATGCGCCGGCGCATATCGATCGATGCGCTAATATGCCGATTAATGCCGTAGCTATACGCGATCGTATAATGCGCGCATCGATGCATGCCGTAATTACGCGGCTACGATTACGCGTACGATGCTATAGCTACGCGTAATTAATTAGCTAGCATCGGCCGATTACGGCCGCGGCTACGTAGCATGCTAATCGCGTAATTATAGCGCCGGCGCATGCTAGCATGCTAATCGCGATGCTAATTAATCGTAATTACGCGCGCGCGTAATCGGCCGCGATGCCGCGTATAATTACGTAATGCCGTATAGCTAATCGATGCCGCGTACGCGGCGCTACGATGCCGCGATATCGCGTACGATCGTAGCTAGCATATTAATATTATAGCCGGCCGCGTAGCATGCATCGCGATTATATACGCGCGGCGCATGCTATAATTAATTAATGCTAATTAATCGCGATGCCGCGCGGCCGATTACGCGCGTAGCCGTATACGTAGCATCGGCGCATCGGCCGCGTAGCTATAATGCGCCGGCTAATCGGCTACGGCATATTAATGCCGCGATCGATCGTACGGCGCTATAATGCCGGCCGCGTAGCCGCGTATAATTAATGCCGATTAATCGCGGCGCTATATAATATATTATAGCGCGCATTATATAGCGCCGATGCTAGCGCTATACGGCGCTACGTAATTATAATATTATATAGCATGCTAGCCGCGATTATAGCATCGATGCTAATGCTACGCGCGCGTACGCGGCTACGATTAATTAGCTAATCGATATATGCTACGATTATATACGGCCGTAATTACGCGCGTAGCCGCGTAATGCCGTAGCATATCGTACGATATATTATACGGCGCTAATTACGCGATCGCGCGATTACGATCGTAGCATTAGCCGTAATTAATATATTATAGCATTAGCATTACGCGATCGCGGCATCGCGCGTAATGCTATAGCATCGCGGCTATAGCCGTAGCTATATAATGCATGCCGGCGCTAGCTAGCGCATATATTACGGCATATGCATTAGCGCATGCCGATATGCTACGATATCGGCTAGCCGATCGTATACGCGATCGGCCGCGTATAATCGCGCGGCGCTACGTATAGCTACGCGCGTAATTATAGCGCCGGCATTACGCGATATATGCCGTAGCATGCCGGCCGCGATTAGCCGCGTAATATATATTACGCGTAGCTAGCTAATTACGGCTACGGCTATAGCCGGCCGATTATAATTAATATTACGGCCGCGGCTATAGCATATATATGCGCATGCATTACGATTATATAGCATGCATATATCGATATCGTAATCGATTATAATATTATACGATCGCGCGATTACGATTATATACGTATAGCATATTAGCTACGTATAGCATTATAGCATATATGCTAGCTAGCCGGCTAATTAATATATGCCGCGATATATATGCGCATTAGCATGCCGATCGCGTAGCGCATCGATTAGCATATCGGCATGCGCGCCGTAATGCTAATGCTATATAATCGCGCGGCGCGCCGGCCGGCGCCGGCATATGCATATATATGCCGGCATGCATGCCGATTATATAGCGCGCCGCGTATATAGCCGCGATGCCGGCATTAGCATCGGCATCGCGGCTAGCGCATCGATCGTACGTACGTATAATTAGCATATCGCGCGCGGCATGCCGCGATTACGTAGCTAGCATTAATATATATCGATTAGCGCATGCTAATATATGCCGATATATATATTATAGCCGATCGGCGCATTATAGCCGATTAATTAATCGCGATTACGTACGGCATTATATACGTATACGCGCGTATAGCGCATATATTAATATCGATATGCGCGCATTATATATAGCCGATTACGTAATGCCGGCGCCGCGATGCATTAATCGATGCTAATATATTATACGTAATATCGGCTACGCGTATAGCATATATTACGCGATTACGATCGGCGCGCGCGCATGCTAGCATATCGATGCGCGCCGTAGCCGATCGCGCGGCATTAGCATGCGCTATAATCGATATATATTAGCCGATCGTATACGGCTACGCGCGTAATGCATTAGCCGTAGCATGCCGATTATAGCATATCGCGGCGCATATCGCGGCTACGGCATTAATCGATTATAATCGATGCATTAGCGCCGTAATGCCGATCGATTAGCATCGCGGCTATACGATCGGCTATAGCATTAATATATATTATACGCGGCATATATTAGCGCATTAGCTACGTAATATGCGCCGATTATACGGCCGGCATGCGCTACGGCATATTAGCCGCGTAATCGTACGCGATATTACGCGCGTAATGCCGTAGCGCATCGGCATATATCGCGATGCTACGTAATGCATGCATGCTAATCGATGCCGCGATCGATGCGCTAGCATCGTATAATATCGGCTAATCGTATACGTATATATAGCGCGCTATACGTAATGCCGGCTATATACGGCCGGCGCATGCGCATATGCATCGGCTAATTACGCGATCGTACGATCGATATATGCTACGGCGCGCATATCGGCTAGCCGCGCGCGGCCGGCTAATGCCGCGCGATATCGGCGCTATACGGCCGTACGATGCCGCGCGATATCGATGCTATAATTACGCGTAATCGATATGCGCTAGCGCCGATCGTATAGCTACGTAGCGCATTACGGCATGCTACGCGGCATGCATTAATCGGCCGATCGGCGCCGTAGCTACGATATCGTACGGCGCCGGCGCATTAGCTAGCGCGCGCGCCGCGGCATGCTATAATATTACGTACGCGTACGTAATATTAGCATGCATTAATTAGCCGGCATTATAGCTACGCGTACGCGATGCATTATACGTAGCGCTAGCATCGCGCGCGCGTATATAATGCCGCGTATACGATTAGCTATAGCCGGCCGCGCGGCTAGCATGCCGATCGATGCTAATCGGCCGTAATTACGATATTATATATATATATAGCTAGCGCATGCCGTACGGCCGTACGGCATATATTAATTAATTATAGCGCTAGCTACGATTATAGCTATATAGCTACGTAATCGCGGCATCGTAATCGGCGCTAGCCGCGATGCTAGCCGATCGCGGCCGGCCGCGTAATATGCCGGCGCCGTAATGCCGATCGTATATACGGCATCGCGGCCGCGATGCATGCCGATATCGTACGCGATATCGCGGCTATAGCCGATATCGTATACGCGTAATGCGCATGCTACGATATGCCGCGCGTATATAGCCGATCGGCCGCGTAATATTATAATCGGCATGCATATGCGCCGCGCGTACGGCGCTAATATCGCGCGATTAATTAATATATATTAGCATCGCGATGCGCATTATAATGCTACGCGGCGCCGGCGCCGATCGTATATAATGCCGGCCGCGATATATTAGCTATACGCGCGCGCGGCGCGCTACGCGTATAGCGCGCATATCGATATTAGCATGCTAATCGTAGCATGCATATCGTATACGCGCGATGCGCCGCGATGCATCGGCGCGCGCATGCCGGCGCGCGCCGCGCGGCATTATACGTAATCGTAGCGCGCGCCGATATGCTAATTAGCGCCGCGTAGCATGCTACGGCCGCGGCCGGCCGGCGCGCCGCGGCGCATATCGCGGCATCGCGGCTAATATCGCGATGCCGCGCGGCGCCGATCGTAGCTAGCTAGCGCGCATCGATATATATGCGCGCATGCCGCGTAGCTAGCGCATCGTAATTATAGCATCGCGCGCGGCATCGCGGCGCGCGCTAATTACGTAGCGCTACGCGATTACGCGATTAATGCGCGCCGGCATCGGCATTAGCGCATGCATTATATATATACGCGCGTACGGCGCTACGATATCGCGGCTATAATATGCTAGCGCCGCGATATATCGGCGCATCGTAATATGCGCTAATATATTAGCGCTAATATGCATCGGCATCGATCGGCTACGTATAATATGCGCGCGCATATATCGATATTAGCCGCGTACGTATACGTACGTATATAATGCTAATGCGCATTATAGCCGATTACGTACGATATGCGCGCATTAATCGTATATAGCTATACGATCGCGGCTATACGATATGCTAGCCGTATAGCGCTAGCATATATTAATATCGGCATATGCTAGCGCCGGCCGCGGCTATATACGGCATGCGCGCTACGGCGCTACGCGCGGCGCGCCGTATAATTATACGCGTAGCCGGCGCATATATCGGCCGTAGCCGGCATATGCGCATCGGCGCTAGCTATAGCTAATGCGCTAGCTACGTATACGTAGCCGTAATGCGCCGATGCGCATTAGCATGCTAGCCGCGCGTATACGTACGTATACGATCGCGCGGCGCTATACGCGGCGCCGTACGATGCGCGCCGATATGCATATCGATATATCGGCATGCGCTATACGTAGCATGCATGCATGCTATACGTACGATGCGCGCGCGCGCATATATTA
</code>```

Title: DNA Encode a String

Body:
Challenge

You must write an encoder (and a separate decoder) which takes a string as input and outputs the string encoded in the style of a strand of DNA.

DNA

DNA is made up of four types of nucleotide:

Adenine (A)

Thymine (T)

Cytosine (C)

Guanine (G)

Adenine and thymine pair up together to make AT or TA. Similarly, cytosine and guanine pair up together to make CG or GC.

Let's call these pairs units. This means that your encoded string is only allowed to contain the four units AT, TA, CG and GC.

This means that:

```<code>ATTAGACG
</code>```

Would be invalid because it contains the unit GA, which is impossible.

Similarly,

```<code>TAGCGCCGATA
</code>```

Is invalid because the final A does not have a thymine to pair up with.

Example

You must encode the following example text and use its encoded length as part of your score:

I have a friend who's an artist and has sometimes taken a view which I don't agree with very well. He'll hold up a flower and say "look how beautiful it is," and I'll agree. Then he says "I as an artist can see how beautiful this is but you as a scientist take this all apart and it becomes a dull thing," and I think that he's kind of nutty. First of all, the beauty that he sees is available to other people and to me too, I believe. Although I may not be quite as refined aesthetically as he is ... I can appreciate the beauty of a flower. At the same time, I see much more about the flower than he sees. I could imagine the cells in there, the complicated actions inside, which also have a beauty. I mean it's not just beauty at this dimension, at one centimeter; there's also beauty at smaller dimensions, the inner structure, also the processes. The fact that the colors in the flower evolved in order to attract insects to pollinate it is interesting; it means that insects can see the color. It adds a question: does this aesthetic sense also exist in the lower forms? Why is it aesthetic? All kinds of interesting questions which the science knowledge only adds to the excitement, the mystery and the awe of a flower. It only adds. I don't understand how it subtracts.

Bounty

If you answer this challenge in the language DNA#, I will offer a 100 to 200 rep bounty.

Rules

Your encoder and decoder programs must work for any string supplied. Therefore, your encoder must produce a genuine encoding and your decoder should not simply hardcode the example text.

You must support all printable ASCII characters:

```<code> !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
</code>```

If you can support more characters, that is acceptable.

Scoring

Your score is how long in characters (not units) the encoded version of the above text plus the length in bytes of your decoder and your encoder.

Winning

The program with the lowest score wins.

Body:
Node.js (5.6.0), 5104 + 125 + 122 = 5351

I was originally working in JavaScript, but Node.js provides compression much more easily. Thanks Neil for helping trim out 5 bytes on the encoder!

Encoder (125 bytes):

s=>[...require('zlib').deflateRawSync(s)].map(a=>('000'+a.toString(4)).slice(-4).replace(/./g,b=>'ATCG'[b]+'TAGC'[b])).join``

Decoder (122 bytes):

s=>require('zlib').inflateRawSync(Buffer(s.replace(/../g,a=>'ATCG'.search(a[0])).match(/..../g).map(a=>parseInt(a,4))))+''

DNA Sequence (5104 bytes):

TATATATATATATAATGCATCGTACGATGCCGGCTACGGCATGCATATATATGCATGCGCGCTAATTATATATACGATCGATCGGCCGTAGCATGCATATCGTAGCGCATCGATATATTACGTAGCTAGCATATGCCGCGATATCGTATAGCCGCGATCGCGGCCGTAATATGCGCGCTAATATCGGCATGCTACGATCGATGCATGCCGGCATTAATTACGCGTATACGTATAGCTAATTAATTATAATCGCGCGATTAGCCGGCGCGCGCTAGCGCTAATTAGCGCCGCGTATATAGCCGATCGTATACGTAATCGGCATTAATATCGATCGTAGCATCGGCTATACGGCTAATCGATGCGCCGTATAATTAATTATAATGCCGGCCGATATGCATGCATATTATACGGCCGCGCGTATAATGCATCGATTAGCCGTACGCGTAATTAGCTATACGTAATCGTACGTAGCCGCGTATACGTAATATATCGCGTAATTATAATCGATCGGCTACGCGCGGCGCCGATATGCTAGCATCGATCGTAATATGCTAATCGTATACGTATATACGTACGCGATCGGCATGCATGCATCGCGGCTATACGTACGGCCGATATGCATTAGCATATCGTAGCTAATCGATGCGCCGGCGCATATCGATCGATGCGCTAATATGCCGATTAATGCCGTAGCTATACGCGATCGTATAATGCGCGCATCGATGCATGCCGTAATTACGCGGCTACGATTACGCGTACGATGCTATAGCTACGCGTAATTAATTAGCTAGCATCGGCCGATTACGGCCGCGGCTACGTAGCATGCTAATCGCGTAATTATAGCGCCGGCGCATGCTAGCATGCTAATCGCGATGCTAATTAATCGTAATTACGCGCGCGCGTAATCGGCCGCGATGCCGCGTATAATTACGTAATGCCGTATAGCTAATCGATGCCGCGTACGCGGCGCTACGATGCCGCGATATCGCGTACGATCGTAGCTAGCATATTAATATTATAGCCGGCCGCGTAGCATGCATCGCGATTATATACGCGCGGCGCATGCTATAATTAATTAATGCTAATTAATCGCGATGCCGCGCGGCCGATTACGCGCGTAGCCGTATACGTAGCATCGGCGCATCGGCCGCGTAGCTATAATGCGCCGGCTAATCGGCTACGGCATATTAATGCCGCGATCGATCGTACGGCGCTATAATGCCGGCCGCGTAGCCGCGTATAATTAATGCCGATTAATCGCGGCGCTATATAATATATTATAGCGCGCATTATATAGCGCCGATGCTAGCGCTATACGGCGCTACGTAATTATAATATTATATAGCATGCTAGCCGCGATTATAGCATCGATGCTAATGCTACGCGCGCGTACGCGGCTACGATTAATTAGCTAATCGATATATGCTACGATTATATACGGCCGTAATTACGCGCGTAGCCGCGTAATGCCGTAGCATATCGTACGATATATTATACGGCGCTAATTACGCGATCGCGCGATTACGATCGTAGCATTAGCCGTAATTAATATATTATAGCATTAGCATTACGCGATCGCGGCATCGCGCGTAATGCTATAGCATCGCGGCTATAGCCGTAGCTATATAATGCATGCCGGCGCTAGCTAGCGCATATATTACGGCATATGCATTAGCGCATGCCGATATGCTACGATATCGGCTAGCCGATCGTATACGCGATCGGCCGCGTATAATCGCGCGGCGCTACGTATAGCTACGCGCGTAATTATAGCGCCGGCATTACGCGATATATGCCGTAGCATGCCGGCCGCGATTAGCCGCGTAATATATATTACGCGTAGCTAGCTAATTACGGCTACGGCTATAGCCGGCCGATTATAATTAATATTACGGCCGCGGCTATAGCATATATATGCGCATGCATTACGATTATATAGCATGCATATATCGATATCGTAATCGATTATAATATTATACGATCGCGCGATTACGATTATATACGTATAGCATATTAGCTACGTATAGCATTATAGCATATATGCTAGCTAGCCGGCTAATTAATATATGCCGCGATATATATGCGCATTAGCATGCCGATCGCGTAGCGCATCGATTAGCATATCGGCATGCGCGCCGTAATGCTAATGCTATATAATCGCGCGGCGCGCCGGCCGGCGCCGGCATATGCATATATATGCCGGCATGCATGCCGATTATATAGCGCGCCGCGTATATAGCCGCGATGCCGGCATTAGCATCGGCATCGCGGCTAGCGCATCGATCGTACGTACGTATAATTAGCATATCGCGCGCGGCATGCCGCGATTACGTAGCTAGCATTAATATATATCGATTAGCGCATGCTAATATATGCCGATATATATATTATAGCCGATCGGCGCATTATAGCCGATTAATTAATCGCGATTACGTACGGCATTATATACGTATACGCGCGTATAGCGCATATATTAATATCGATATGCGCGCATTATATATAGCCGATTACGTAATGCCGGCGCCGCGATGCATTAATCGATGCTAATATATTATACGTAATATCGGCTACGCGTATAGCATATATTACGCGATTACGATCGGCGCGCGCGCATGCTAGCATATCGATGCGCGCCGTAGCCGATCGCGCGGCATTAGCATGCGCTATAATCGATATATATTAGCCGATCGTATACGGCTACGCGCGTAATGCATTAGCCGTAGCATGCCGATTATAGCATATCGCGGCGCATATCGCGGCTACGGCATTAATCGATTATAATCGATGCATTAGCGCCGTAATGCCGATCGATTAGCATCGCGGCTATACGATCGGCTATAGCATTAATATATATTATACGCGGCATATATTAGCGCATTAGCTACGTAATATGCGCCGATTATACGGCCGGCATGCGCTACGGCATATTAGCCGCGTAATCGTACGCGATATTACGCGCGTAATGCCGTAGCGCATCGGCATATATCGCGATGCTACGTAATGCATGCATGCTAATCGATGCCGCGATCGATGCGCTAGCATCGTATAATATCGGCTAATCGTATACGTATATATAGCGCGCTATACGTAATGCCGGCTATATACGGCCGGCGCATGCGCATATGCATCGGCTAATTACGCGATCGTACGATCGATATATGCTACGGCGCGCATATCGGCTAGCCGCGCGCGGCCGGCTAATGCCGCGCGATATCGGCGCTATACGGCCGTACGATGCCGCGCGATATCGATGCTATAATTACGCGTAATCGATATGCGCTAGCGCCGATCGTATAGCTACGTAGCGCATTACGGCATGCTACGCGGCATGCATTAATCGGCCGATCGGCGCCGTAGCTACGATATCGTACGGCGCCGGCGCATTAGCTAGCGCGCGCGCCGCGGCATGCTATAATATTACGTACGCGTACGTAATATTAGCATGCATTAATTAGCCGGCATTATAGCTACGCGTACGCGATGCATTATACGTAGCGCTAGCATCGCGCGCGCGTATATAATGCCGCGTATACGATTAGCTATAGCCGGCCGCGCGGCTAGCATGCCGATCGATGCTAATCGGCCGTAATTACGATATTATATATATATATAGCTAGCGCATGCCGTACGGCCGTACGGCATATATTAATTAATTATAGCGCTAGCTACGATTATAGCTATATAGCTACGTAATCGCGGCATCGTAATCGGCGCTAGCCGCGATGCTAGCCGATCGCGGCCGGCCGCGTAATATGCCGGCGCCGTAATGCCGATCGTATATACGGCATCGCGGCCGCGATGCATGCCGATATCGTACGCGATATCGCGGCTATAGCCGATATCGTATACGCGTAATGCGCATGCTACGATATGCCGCGCGTATATAGCCGATCGGCCGCGTAATATTATAATCGGCATGCATATGCGCCGCGCGTACGGCGCTAATATCGCGCGATTAATTAATATATATTAGCATCGCGATGCGCATTATAATGCTACGCGGCGCCGGCGCCGATCGTATATAATGCCGGCCGCGATATATTAGCTATACGCGCGCGCGGCGCGCTACGCGTATAGCGCGCATATCGATATTAGCATGCTAATCGTAGCATGCATATCGTATACGCGCGATGCGCCGCGATGCATCGGCGCGCGCATGCCGGCGCGCGCCGCGCGGCATTATACGTAATCGTAGCGCGCGCCGATATGCTAATTAGCGCCGCGTAGCATGCTACGGCCGCGGCCGGCCGGCGCGCCGCGGCGCATATCGCGGCATCGCGGCTAATATCGCGATGCCGCGCGGCGCCGATCGTAGCTAGCTAGCGCGCATCGATATATATGCGCGCATGCCGCGTAGCTAGCGCATCGTAATTATAGCATCGCGCGCGGCATCGCGGCGCGCGCTAATTACGTAGCGCTACGCGATTACGCGATTAATGCGCGCCGGCATCGGCATTAGCGCATGCATTATATATATACGCGCGTACGGCGCTACGATATCGCGGCTATAATATGCTAGCGCCGCGATATATCGGCGCATCGTAATATGCGCTAATATATTAGCGCTAATATGCATCGGCATCGATCGGCTACGTATAATATGCGCGCGCATATATCGATATTAGCCGCGTACGTATACGTACGTATATAATGCTAATGCGCATTATAGCCGATTACGTACGATATGCGCGCATTAATCGTATATAGCTATACGATCGCGGCTATACGATATGCTAGCCGTATAGCGCTAGCATATATTAATATCGGCATATGCTAGCGCCGGCCGCGGCTATATACGGCATGCGCGCTACGGCGCTACGCGCGGCGCGCCGTATAATTATACGCGTAGCCGGCGCATATATCGGCCGTAGCCGGCATATGCGCATCGGCGCTAGCTATAGCTAATGCGCTAGCTACGTATACGTAGCCGTAATGCGCCGATGCGCATTAGCATGCTAGCCGCGCGTATACGTACGTATACGATCGCGCGGCGCTATACGCGGCGCCGTACGATGCGCGCCGATATGCATATCGATATATCGGCATGCGCTATACGTAGCATGCATGCATGCTATACGTACGATGCGCGCGCGCGCATATATTA


答:
TI-Basic, 37 bytes

Works on any TI-83/84 calculator

```<code>Input L1                     gets input into an array
L1(4)²/L1(3                  calculate the fifth number in a geometric series
If not(sum(ΔList(ΔList(L1    if ΔList(ΔList(L1)) yields an array of all zeroes
L1(4)2-L1(3                  calculate the fifth number in an arithmetic series
                             Ans is implicitly returned
</code>```

Title: The Final Number

Body:
Challenge

Write a program that takes an array of 4 integers (which represents a sequence of numbers generated by a certain algorithm)  and returns the next integer that would follow.

We will only be using simple addition, subtraction, multiplication and division algorithms with a constant (i.e non-variable) variation.

For division we will use the floor integer values: 133/4 = 33 and 33/4 = 8

You can assume that there will always be one single valid return value

Test cases

[14,24,34,44] should return 54 (addition Algorithm)

[105,45,-15,-75] should return -135 (subtraction algorithm)

[5,25,125,625] should return 3125 (multiplicative algorithm)

[256,64,16,4] should return 1 (division algorithm)

General rules

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

Standard loopholes are forbidden

Body:
TI-Basic, 37 bytes

Works on any TI-83/84 calculator

Input L1                     gets input into an array
L1(4)²/L1(3                  calculate the fifth number in a geometric series
If not(sum(ΔList(ΔList(L1    if ΔList(ΔList(L1)) yields an array of all zeroes
L1(4)2-L1(3                  calculate the fifth number in an arithmetic series
                             Ans is implicitly returned


答:
GameMaker Language, 70 bytes

```<code>a=argument0;If a[3]+a[1]=a[2]*2return a[4]*2-a[3]return a[4]*a[4]/a[3]
</code>```

Title: The Final Number

Body:
GameMaker Language, 70 bytes

a=argument0;If a[3]+a[1]=a[2]*2return a[4]*2-a[3]return a[4]*a[4]/a[3]