问:
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!

答:
Logo, <s>129</s> 87 bytes

Graphical solution, implemented as function

This was built on Calormen.com's Logo interpreter.  The S function takes the number of characters as a parameter and draws them in a spiral.  <s>The T function outputs letters upright to prevent them from rotating with the spiral.</s>.  I decided that it looked nicer (and golfed out 42 bytes) to omit correcting the letter orientation.  I also tightened up the spacing which did not change the byte count.  If you were to actually roll up an alphabet, it would look more like this anyway.

Updated Version (letters roll)

```<code>TO S:r
PU IF:r[REPEAT:r[LABEL CHAR((REPCOUNT-1)%26)+65
RT 99/SQRT(REPCOUNT)FD 12]]END
</code>```

Invocation

Invoke as follows: S iterations

Sample output

```<code>S 1000
</code>```

Old Version (letters always upright)

<s>

```<code>TO T:l:h
RT:h
LABEL CHAR(:l%26)+65
LT:h
END
TO S:r
PU IF:r[REPEAT:r[T REPCOUNT-1 90-HEADING
RT 95/SQRT(REPCOUNT)FD 15]]END
</code>```

</s>

Old output removed to save space.  See it here.

Title: Roll the Alphabet into a Spiral

Body:
Logo, <s>129</s> 87 bytes

Graphical solution, implemented as function

This was built on Calormen.com's Logo interpreter.  The S function takes the number of characters as a parameter and draws them in a spiral.  <s>The T function outputs letters upright to prevent them from rotating with the spiral.</s>.  I decided that it looked nicer (and golfed out 42 bytes) to omit correcting the letter orientation.  I also tightened up the spacing which did not change the byte count.  If you were to actually roll up an alphabet, it would look more like this anyway.

Updated Version (letters roll)

TO S:r
PU IF:r[REPEAT:r[LABEL CHAR((REPCOUNT-1)%26)+65
RT 99/SQRT(REPCOUNT)FD 12]]END

Invocation

Invoke as follows: S iterations

Sample output

S 1000

Old Version (letters always upright)

<s>

TO T:l:h
RT:h
LABEL CHAR(:l%26)+65
LT:h
END
TO S:r
PU IF:r[REPEAT:r[T REPCOUNT-1 90-HEADING
RT 95/SQRT(REPCOUNT)FD 15]]END

</s>

Old output removed to save space.  See it here.


问:
End the tabs versus space war

End the tabs versus space war

So, there has been a great deal of debate of whether to use tabs or spaces to indent/format code. Can you help the university settle the dispute, by going to an incredibly <s>crazy</s> unique method of formatting.

Your job is to write a full program or function which expands all tabs into four spaces. And then replaces a run of n leading spaces with "/(n - two stars here)/". You will receive input over multiple lines in any reasonable format (single string array of strings for each new line. Columnar array etc.)

Sample input shamelessly stolen. Note that since tabs get automagically expanded to four spaces on SE I represent it as the "^" character, but you must handle tabs (codepoint 0x09) as well. All "^" characters represent a tabulation.

```<code>Calculate the value 256 and test if it's zero
If the interpreter errors on overflow this is where it'll happen
++++++++[>++++++++<-]>[<++++>-]
+<[>-<
    Not zero so multiply by 256 again to get 65536
    [>++++<-]>[<++++++++>-]<[>++++++++<-]
    +>[>
        # Print "32"
        ++++++++++[>+++++<-]>+.-.[-]<
    <[-]<->] <[>>
        # Print "16"
        +++++++[>+++++++<-]>.+++++.[-]<
<<-]] >[>
    # Print "8"
    ++++++++[>+++++++<-]>.[-]<
<-]<
# Print " bit cells\n"
+++++++++++[>+++>+++++++++>+++++++++>+<<<<-]>-.>-.+++++++.+++++++++++.<.
>>.++.+++++++..<-.>>-
Clean up used cells.
[[-]<]l
^this is preceded by a tab
^^two tabs
^^^three tabs etcetera!
</code>```

Sample output

```<code>Calculate the value 256 and test if it's zero
If the interpreter errors on overflow this is where it'll happen
++++++++[>++++++++<-]>[<++++>-]
+<[>-<
/**/Not zero so multiply by 256 again to get 65536
/**/[>++++<-]>[<++++++++>-]<[>++++++++<-]
/**/+>[>
/******/# Print "32"
/******/++++++++++[>+++++<-]>+.-.[-]<
/**/<[-]<->] <[>>
/******/# Print "16"
/******/+++++++[>+++++++<-]>.+++++.[-]<
<<-]] >[>
/**/# Print "8"
/**/++++++++[>+++++++<-]>.[-]<
<-]<
# Print " bit cells\n"
+++++++++++[>+++>+++++++++>+++++++++>+<<<<-]>-.>-.+++++++.+++++++++++.<.
>>.++.+++++++..<-.>>-
Clean up used cells.
[[-]<]l
/**/this is preceded by a tab
/******/two tabs
/**********/three tabs etcetera!
</code>```

Because the university needs space to download both Vim and Emacs, you are allowed very little storage for your code. Therefore this is code-golf and the shortest code wins. You may assume that input is well formed and lines with less than four spaces (after replacement of tabs) may result in undefined behavior.

Disclaimer

This "excellent" formatting strategy came courtesy of Geobits, and is reproduced with his permission. No programmers were harmed during the production of this challenge.

答:
GNU sed, <s>66</s> 64 + 1(r flag) = 65 bytes

Edit: 1 byte less thanks to Riley's suggestion.

s/\t/    /g
s,^ ( *) ,/\1\n,
:
s,^(/\**) ( *\n),\1*\2,
t
s,\n,/,
```

Run: sed -rf formatter.sed input_file

The reason for separating with a \n the leading spaces from the rest of the text on that line, is because otherwise a C++ line starting with a comment like this /*   */ would be turn into /*****/ by a simpler line 4 like s,^(/\**) ,\1*, or even s,^(/\**) ( */),\1*\2,. Since sed executes the script for each input line, no \n is introduced in the pattern space on reading.

ContentLicense: CC BY-SA 3.0

Title: End the tabs versus space war

Body:
GNU sed, <s>66</s> 64 + 1(r flag) = 65 bytes

Edit: 1 byte less thanks to Riley's suggestion.

s/\t/    /g
s,^ ( *) ,/\1\n,
:
s,^(/\**) ( *\n),\1*\2,
t
s,\n,/,

Run: sed -rf formatter.sed input_file

The reason for separating with a \n the leading spaces from the rest of the text on that line, is because otherwise a C++ line starting with a comment like this /*   */ would be turn into /*****/ by a simpler line 4 like s,^(/\**) ,\1*, or even s,^(/\**) ( */),\1*\2,. Since sed executes the script for each input line, no \n is introduced in the pattern space on reading.


问:
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>```

答:
Actually, 10 bytes

Golfing suggestions welcome. Try it online!

```<code>;'\'/2(%I*
</code>```

How it works

```<code>       Implicit input of n
;      Duplicate n
'\'/   The strings "/" and "\"
2(%    n mod 2
I      If n mod 2, then "/", else "\"
*      Multiply by n. Implicit print at the end.
</code>```

Title: The Squiggly Sequence

Body:
Actually, 10 bytes

Golfing suggestions welcome. Try it online!

;'\'/2(%I*

How it works

       Implicit input of n
;      Duplicate n
'\'/   The strings "/" and "\"
2(%    n mod 2
I      If n mod 2, then "/", else "\"
*      Multiply by n. Implicit print at the end.


问:
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.

答:
Actually, 24 bytes

```<code>;"aeiou";╗@s@`╜íu`░╚@♀+Σ
</code>```

Try it online!

Explanation:

```<code>;"aeiou";╗@s@`╜íu`░╚@♀+Σ
;                         dupe input
 "aeiou";╗                push vowels, store a copy in reg0
          @s              split one copy of input on vowels
            @`╜íu`░       take characters from other copy of input where
              ╜íu           the character is a vowel (1-based index of character in vowel string is non-zero)
                   ╚      shuffle the vowels
                    @♀+   interleave and concatenate pairs of strings
                       Σ  concatenate the strings
</code>```

Title: Sheffle tho vawols ureund!

Body:
Actually, 24 bytes

;"aeiou";╗@s@`╜íu`░╚@♀+Σ

Try it online!

Explanation:

;"aeiou";╗@s@`╜íu`░╚@♀+Σ
;                         dupe input
 "aeiou";╗                push vowels, store a copy in reg0
          @s              split one copy of input on vowels
            @`╜íu`░       take characters from other copy of input where
              ╜íu           the character is a vowel (1-based index of character in vowel string is non-zero)
                   ╚      shuffle the vowels
                    @♀+   interleave and concatenate pairs of strings
                       Σ  concatenate the strings


答:
Bash, 75 bytes

```<code>paste -d '' <(tr aeoiu \\n<<<$1) <(grep -o \[aeiou]<<<$1|shuf)|paste -sd ''
</code>```

Takes the string as an argument and prints the result to stdout.

Eg

```<code>for x in "" "a" "cwm" \
         "the quick brown fox jumps over the lazy dog." \
         "abcdefghijklmnopqrstuvwxyz" \
         "programming puzzles & code golf" \
         "fatalize" "martin ender"; do
  echo "$x";. sheffle.sh "$x"; echo
done
</code>```

prints

```<code><blank line>
<blank line>

a
a

cwm
cwm

the quick brown fox jumps over the lazy dog.
tho quuck brown fix jamps ever the lozy dog.

abcdefghijklmnopqrstuvwxyz
ibcdefghajklmnopqrstuvwxyz

programming puzzles & code golf
progremmong pazzlus & cedo gilf

fatalize
fetilaza

martin ender
mertan endir
</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:
Bash, 75 bytes

paste -d '' <(tr aeoiu \\n<<<$1) <(grep -o \[aeiou]<<<$1|shuf)|paste -sd ''

Takes the string as an argument and prints the result to stdout.

Eg

for x in "" "a" "cwm" \
         "the quick brown fox jumps over the lazy dog." \
         "abcdefghijklmnopqrstuvwxyz" \
         "programming puzzles & code golf" \
         "fatalize" "martin ender"; do
  echo "$x";. sheffle.sh "$x"; echo
done

prints

<blank line>
<blank line>

a
a

cwm
cwm

the quick brown fox jumps over the lazy dog.
tho quuck brown fix jamps ever the lozy dog.

abcdefghijklmnopqrstuvwxyz
ibcdefghajklmnopqrstuvwxyz

programming puzzles & code golf
progremmong pazzlus & cedo gilf

fatalize
fetilaza

martin ender
mertan endir


答:
Brachylog, 39 bytes

```<code>@eI:1aToS,I:2f@~:LcS,Tc
.'~e@V;
e.~e@V,
</code>```

Try it online!

Explanation

Main predicate:

```<code>@eI        I is the list of chars of the input.
:1aT       T is I where all vowels are replaced with free variables.
oS,        S is T sorted (all free variables come first).
I:2f       Find all vowels in I.
@~         Shuffle them.
:LcS,      This shuffle concatenated with L (whatever it may be) results in S.
             This will unify the free variables in S with the shuffled vowels.
Tc         Output is the concatenation of elements of T.
</code>```

Predicate 1:

```<code>.          Input = Output…
'~e@V      …provided that it is not a vowel.
;          Otherwise Output is a free variable.
</code>```

Predicate 2:

```<code>e.         Output is an element of the input…
~e@V,      … and it is a vowel.
</code>```

Title: Sheffle tho vawols ureund!

Body:
Brachylog, 39 bytes

@eI:1aToS,I:2f@~:LcS,Tc
.'~e@V;
e.~e@V,

Try it online!

Explanation

Main predicate:

@eI        I is the list of chars of the input.
:1aT       T is I where all vowels are replaced with free variables.
oS,        S is T sorted (all free variables come first).
I:2f       Find all vowels in I.
@~         Shuffle them.
:LcS,      This shuffle concatenated with L (whatever it may be) results in S.
             This will unify the free variables in S with the shuffled vowels.
Tc         Output is the concatenation of elements of T.

Predicate 1:

.          Input = Output…
'~e@V      …provided that it is not a vowel.
;          Otherwise Output is a free variable.

Predicate 2:

e.         Output is an element of the input…
~e@V,      … and it is a vowel.


问:
Implement a Truth-Machine
A truth-machine (credits goes to this guy for coming up with it) is a very simple program designed to demonstrate the I/O and control flow of a language. Here's what a truth-machine does:

Gets a number (either 0 or 1) from STDIN.

If that number is 0, print out 0 and terminate.

If that number is 1, print out 1 forever.

Challenge

Write a truth-machine as described above in your language of choice. The truth-machine must be a full program that follows these rules:

take input from STDIN or an acceptable alternative

If your language cannot take input from STDIN, it may take input from a hardcoded variable or suitable equivalent in the program

must output to STDOUT or an acceptable alternative

If your language is incapable of outputting the characters 0 or 1, byte or unary I/O is acceptable.

when the input is 1, it must continually print 1s and only stop if the program is killed or runs out of memory

the output must only be either a 0 followed by either one or no newline or space, or infinite 1s with each 1 followed by either one or no newline or space. No other output can be generated, except constant output of your language's interpreter that cannot be suppressed (such as a greeting, ANSI color codes or indentation). Your usage of newlines or spaces must be consistent: for example, if you choose to output 1 with a newline after it all 1s must have a newline after them.

if and only if your language cannot possibly terminate on an input of 0 it is acceptable for the code to enter an infinite loop in which nothing is outputted.

Since this is a catalog, languages created after this challenge are allowed to compete. Note that there must be an interpreter so the submission can be tested. It is allowed (and even encouraged) to write this interpreter yourself for a previously unimplemented language. Other than that, all the standard rules of code-golf must be obeyed. Submissions in most languages will be scored in bytes in an appropriate preexisting encoding (usually UTF-8).

Catalog

The Stack Snippet at the bottom of this post generates the catalog from the answers a) as a list of shortest solution per language and b) as an overall leaderboard.

To make sure that your answer shows up, please start your answer with a headline, using the following Markdown template:

```<code>## Language Name, N bytes
</code>```

where N is the size of your submission. If you improve your score, you can keep old scores in the headline, by striking them through. For instance:

```<code>## Ruby, <s>104</s> <s>101</s> 96 bytes
</code>```

If there you want to include multiple numbers in your header (e.g. because your score is the sum of two files or you want to list interpreter flag penalties separately), make sure that the actual score is the last number in the header:

```<code>## Perl, 43 + 2 (-p flag) = 45 bytes
</code>```

You can also make the language name a link which will then show up in the snippet:

```<code>## [><>](http://esolangs.org/wiki/Fish), 121 bytes
</code>```

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

Shortest Solution by Language

Language	User	Score

Leaderboard

	Author	Language	Size

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

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

```

答:
><>, 6 bytes

Takes input from command line i.e. ./fish.py program.fish -v 1

```<code>:?!;:n
</code>```

Explanation:

```<code>:   ?  !; :n      ... (Since this is fish, it wraps around and repeats)
^   ^  ^  ^
|   |  |  |
|   |  |   Duplicates topmost value on stack and outputs it
|   |  |
|   |   Skips the next instruction
|   |
|    Checks if topmost value is 0 and if so, skips the next instruction, going straight to the ; which terminates the program
|
 Duplicates topmost value on stack
</code>```

Title: Implement a Truth-Machine

Body:
><>, 6 bytes

Takes input from command line i.e. ./fish.py program.fish -v 1

:?!;:n

Explanation:

:   ?  !; :n      ... (Since this is fish, it wraps around and repeats)
^   ^  ^  ^
|   |  |  |
|   |  |   Duplicates topmost value on stack and outputs it
|   |  |
|   |   Skips the next instruction
|   |
|    Checks if topmost value is 0 and if so, skips the next instruction, going straight to the ; which terminates the program
|
 Duplicates topmost value on stack


答:
Python 2, 33 bytes

Golfing suggestions welcome :)

```<code>x=input()
while x:print 1
print 0
</code>```

Title: Implement a Truth-Machine

Body:
A truth-machine (credits goes to this guy for coming up with it) is a very simple program designed to demonstrate the I/O and control flow of a language. Here's what a truth-machine does:

Gets a number (either 0 or 1) from STDIN.

If that number is 0, print out 0 and terminate.

If that number is 1, print out 1 forever.

Challenge

Write a truth-machine as described above in your language of choice. The truth-machine must be a full program that follows these rules:

take input from STDIN or an acceptable alternative

If your language cannot take input from STDIN, it may take input from a hardcoded variable or suitable equivalent in the program

must output to STDOUT or an acceptable alternative

If your language is incapable of outputting the characters 0 or 1, byte or unary I/O is acceptable.

when the input is 1, it must continually print 1s and only stop if the program is killed or runs out of memory

the output must only be either a 0 followed by either one or no newline or space, or infinite 1s with each 1 followed by either one or no newline or space. No other output can be generated, except constant output of your language's interpreter that cannot be suppressed (such as a greeting, ANSI color codes or indentation). Your usage of newlines or spaces must be consistent: for example, if you choose to output 1 with a newline after it all 1s must have a newline after them.

if and only if your language cannot possibly terminate on an input of 0 it is acceptable for the code to enter an infinite loop in which nothing is outputted.

Since this is a catalog, languages created after this challenge are allowed to compete. Note that there must be an interpreter so the submission can be tested. It is allowed (and even encouraged) to write this interpreter yourself for a previously unimplemented language. Other than that, all the standard rules of code-golf must be obeyed. Submissions in most languages will be scored in bytes in an appropriate preexisting encoding (usually UTF-8).

Catalog

The Stack Snippet at the bottom of this post generates the catalog from the answers a) as a list of shortest solution per language and b) as an overall leaderboard.

To make sure that your answer shows up, please start your answer with a headline, using the following Markdown template:

```<code>## Language Name, N bytes
</code>```

where N is the size of your submission. If you improve your score, you can keep old scores in the headline, by striking them through. For instance:

```<code>## Ruby, <s>104</s> <s>101</s> 96 bytes
</code>```

If there you want to include multiple numbers in your header (e.g. because your score is the sum of two files or you want to list interpreter flag penalties separately), make sure that the actual score is the last number in the header:

```<code>## Perl, 43 + 2 (-p flag) = 45 bytes
</code>```

You can also make the language name a link which will then show up in the snippet:

```<code>## [><>](http://esolangs.org/wiki/Fish), 121 bytes
</code>```

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

Shortest Solution by Language

Language	User	Score

Leaderboard

	Author	Language	Size

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

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

```

Body:
Python 2, 33 bytes

Golfing suggestions welcome :)

x=input()
while x:print 1
print 0


答:
Java, <s>143</s> <S>141</s> <s>125</s> 88 bytes

```<code>interface T {static void main(String[]a){System.out.print(a[0]);main(a[0].split("0"));}}
</code>```

Ungolfed Test Code

```<code>interface T {

    static void main(String[] a) {
        System.out.print(a[0]);
        main(a[0].split("0"));
    }
}
</code>```

Title: Implement a Truth-Machine

Body:
Java, <s>143</s> <S>141</s> <s>125</s> 88 bytes

interface T {static void main(String[]a){System.out.print(a[0]);main(a[0].split("0"));}}

Ungolfed Test Code

interface T {

    static void main(String[] a) {
        System.out.print(a[0]);
        main(a[0].split("0"));
    }
}


答:
Ru, <s>11</s> 9 bytes

```<code>»Ϟα;¿{»α}
</code>```

<s>This look way too long</s>

Title: Implement a Truth-Machine

Body:
Ru, <s>11</s> 9 bytes

»Ϟα;¿{»α}

<s>This look way too long</s>


答:
T-SQL 50 bytes

Of course no STDIN here, so let's assume a hardcoded INT variable like this: DECLARE @ INT then the solution is:

```<code>PRINT IIF(@%2=0,REPLICATE('\',@),REPLICATE('/',@))
</code>```

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:
T-SQL 50 bytes

Of course no STDIN here, so let's assume a hardcoded INT variable like this: DECLARE @ INT then the solution is:

PRINT IIF(@%2=0,REPLICATE('\',@),REPLICATE('/',@))


问:
As Easy as One-Two-Three
Write a program or function that takes in a positive integer. You can assume the input is valid and may take it as a string. If the number is any of

```<code>123
234
345
456
567
678
789
</code>```

then output a truthy value. Otherwise, output a falsy value. For example, the inputs

```<code>1
2
3
12
122
124
132
321
457
777
890
900
1011
1230
1234
</code>```

must all result in falsy output. (The input will not have leading zeroes so you needn't worry about things like 012.)

The shortest code in bytes wins.

Title: As Easy as One-Two-Three

Body:
C, 71 bytes

Taking the input as int:

f,d,c;F(n){for(f=c=0;n;)d=n%10,c++,f|=d-(n/=10)%10-1&&n;return!f&c==3;}

Test main:

int main() {
  printf("%d\n", F(123));
  printf("%d\n", F(234));
  printf("%d\n", F(345));
  printf("%d\n", F(456));
  printf("%d\n", F(567));
  printf("%d\n", F(678));
  printf("%d\n", F(789));
  printf("%d\n", F(1));
  printf("%d\n", F(2));
  printf("%d\n", F(3));
  printf("%d\n", F(12));
  printf("%d\n", F(122));
  printf("%d\n", F(124));
  printf("%d\n", F(321));
  printf("%d\n", F(457));
  printf("%d\n", F(777));
  printf("%d\n", F(890));
  printf("%d\n", F(900));
  printf("%d\n", F(1011));
  printf("%d\n", F(1230));
  printf("%d\n", F(1234));
}


答:
Javascript (ES5), 47 39 bytes

```<code>function(n){return(n-12)%111==0&&i<1e3}
</code>```

Old solution with 47 did not work correctly.

Title: As Easy as One-Two-Three

Body:
Write a program or function that takes in a positive integer. You can assume the input is valid and may take it as a string. If the number is any of

```<code>123
234
345
456
567
678
789
</code>```

then output a truthy value. Otherwise, output a falsy value. For example, the inputs

```<code>1
2
3
12
122
124
132
321
457
777
890
900
1011
1230
1234
</code>```

must all result in falsy output. (The input will not have leading zeroes so you needn't worry about things like 012.)

The shortest code in bytes wins.

Body:
Javascript (ES5), 47 39 bytes

function(n){return(n-12)%111==0&&i<1e3}

Old solution with 47 did not work correctly.


问:
Highlight the Bounding Box, Part I: Cartesian Grid
You're given a rectangular grid of the characters . and #, like this:

```<code>..........
..#.......
....#..#..
...#......
..........
</code>```

Your task is to fill the entire axis-aligned bounding box of the # with further #:

```<code>..........
..######..
..######..
..######..
..........
</code>```

The axis-aligned bounding box is the smallest rectangle which contains all the #.

Want more? Try Part II!

Rules

You may use any two distinct printable ASCII characters (0x20 to 0x7E, inclusive), in place of # and .. I'll continue referring to them as # and . for the remainder of the specification though.

Input and output may either be a single linefeed-separated string or a list of strings (one for each line), but the format has to be consistent.

You may assume that the input contains at least one # and all lines are the same length.

You may write a program or a function and use any of the our standard methods of receiving input and providing output.

You may use any programming language, but note that these loopholes are forbidden by default.

This is code-golf, so the shortest valid answer – measured in bytes – wins.

Test Cases

Each test case has input and output next to each other.

```<code>#    #

...    ...
#..    #..
...    ...

...    ...
#..    ###
..#    ###

.#.    ###
#..    ###
..#    ###

.....    .....
.#.#.    .###.
.....    .....

...    ...
.#.    .#.
...    .#.
.#.    .#.
...    ...

..........    ..........
..........    ..........
....#.....    ....#.....
..........    ..........

..........    ..........
..........    ..........
....#.....    ...##.....
...#......    ...##.....

..........    ..........
..#.......    ..###.....
....#.....    ..###.....
...#......    ..###.....

..........    ..........
..#.......    ..######..
....#..#..    ..######..
...#......    ..######..

.........#    ..########
..#.......    ..########
....#..#..    ..########
...#......    ..########
</code>```

答:
Perl, 51 bytes

Includes +2 for -0p

Give input on STDIN, off character is A, on character is a, e.g.:

```<code>bounding.pl
AAAAAAAAAA
AAaAAAAAAA
AAAAaAAaAA
AAAaAAAAAA
AAAAAAAAAA
^D
</code>```

bounding.pl:

```<code>#!/usr/bin/perl -0p
s%(?=\D*a).+%$a|=$&%eg;s%.*a.*%$a%g;s/a.*a/\L$&/g
</code>```

Same length:

```<code>#!/usr/bin/perl -0p
s%.+%${a./a/g}|=$&%eg;s%.*a.*%$a1%g;s/a.*a/\L$&/g
</code>```

Body:
Perl, 51 bytes

Includes +2 for -0p

Give input on STDIN, off character is A, on character is a, e.g.:

bounding.pl
AAAAAAAAAA
AAaAAAAAAA
AAAAaAAaAA
AAAaAAAAAA
AAAAAAAAAA
^D

bounding.pl:

#!/usr/bin/perl -0p
s%(?=\D*a).+%$a|=$&%eg;s%.*a.*%$a%g;s/a.*a/\L$&/g

Same length:

#!/usr/bin/perl -0p
s%.+%${a./a/g}|=$&%eg;s%.*a.*%$a1%g;s/a.*a/\L$&/g


问:
Square free Numbers
Given a number N, write the shortest complete program to find the number of square-free integers below N.

```<code>Sample Input
100000
Sample Output
60794
</code>```

Constraints:

Should work for all positive N below 1,000,000

Should not take more than 10 secs.

Please do not use built in functions, please.

答:
Python, 84 characters

```<code>n=input()
R=range(n)
A=[1]*n
for i in R[2:]:
 for x in R[::i*i]:A[x]=0
print sum(A)
</code>```

ContentLicense: CC BY-SA 2.5

Title: Square free Numbers

Body:
Python, 84 characters

n=input()
R=range(n)
A=[1]*n
for i in R[2:]:
 for x in R[::i*i]:A[x]=0
print sum(A)


问:
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.

答:
Score (current): 12038 837/-

The programs assume numbers are loaded in whatever cell is specified, by , or similar. It also assumes that all cells are 8-bit unsigned with wrapping as needed. At the start of each snippet, numbers are loaded at cell 0 (and 1 if needed).

Bit operations - 799

The bit operations follow the same general structure.

```<code>Firstly, we define a divmod 2 (DM2) function.
CELLS:   A  B   C  D
INPUT:  *A  0   0  0
OUTPUT: *0 A/2 A%2 0
dp@A; while{
  dec A,2; inc B,1; dp@A; inc A,1
  while{ #Check if A was 1 at the start
    dec D,1; pour A,C; dp@A;
  }
  dec C,1; pour C,A; inc D,1; dp@D
  #If A was 1 at the start, D will be 1 here
  while{
    dec D,1; inc C,1; dec B,1; dp@D
  }
  dp@A
}
Translated into BF, we have
    [->+<[>>>-<<<[->>+<<]]>>-[<<+>>-]>+[-<+<->>]<<<]
I'm not that good at BF, so my algorithm may not be the smallest.

Next, we define the program.
In this, we assume that the numbers are loaded in $2 (cell 2) and $3.

inc $1,8; dp@1 {
  dec  $1
  pour $3,$6
  DM2  $2        # result in $3,$4
  DM2  $6        # result in $7,$8
  pour $7, $2
  pour $8,$5
  bop  $4,$5     # result in $6
  pour $1,$5
  pour $5,$4,$1
  down $4,$5     # decrease $4 till 0, decrease $5 by same amount
  inc  $5,#7
  shl  $6,$5
  pour $6,$0     # $0 is result
  dp@  1
}
#Now, the result is in $0

Translated to BF (with linebreaks for readability):
  >++++++++[
    ->>[->>>+<<<]<
    [->+<[>>>-<<<[->>+<<]]>>-[<<+>>-]>+[-<+<->>]<<<]>>>>  #DM2 $2
    [->+<[>>>-<<<[->>+<<]]>>-[<<+>>-]>+[-<+<->>]<<<]>     #DM2 $6
    [-<<<<<+>>>>>]>
    [-<<<+>>>]<<<<
    (bop)<<<
    [->>>>+<<<<]>>>>
    [<+<<<+>>>>-]<
    [->-<]>
    +++++++
    [->[-<<++>>]<<[->>+<<]>]
    [-<<<<<<+>>>>>>]
    <<<<<
  ]

Replace (bop) by the appropriate expression.

XOR works like this: (252-5+15=262)
  [->-<]>[[-]>+<]
AND works like this: (252-5+11=258)
  [>[>+<-]<-]
OR  works like this: (252-5+32=279)
  [->>>+<<<]>[->>+<<]>>[[-]<+>]<<<

So, combining these, we have a total of 262+258+279=799 D:
</code>```

Rotate Left A, 1 - 31/-

The number A is loaded in cell 0.

```<code>Pseudocode
    $0 := A
    $1 := $0 << 1    # this has the effect of discarding the top bit of A
    $2 := $0
    $3 := $0 << 1
    $2 -= $1 >> 1    # $2 now contains the top bit of A
    if $2 then $3++  # $3 now contains A rotated left 1
    res:= $3         # the result is in cell 3 now

Real code
    [->++>+>++<<<]>[-->-<]>[>+<[-]]
If you don't always need the pointer in the same position,
substitute [>+>] for the last loop (3 less chars).
However, the pointer will then sometimes end up in position 2, sometimes in position 4.
</code>```

NOT A - 7

The number A is loaded in cell 0.

```<code>Pseudocode
    $0  := A
    $0  += 1
    $1  := 256-$0   #since ~A=255-A
    res := $1

+[->-<]
</code>```

Title: Bitwise Operators in Brainfuck

Body:
Score (current): 12038 837/-

The programs assume numbers are loaded in whatever cell is specified, by , or similar. It also assumes that all cells are 8-bit unsigned with wrapping as needed. At the start of each snippet, numbers are loaded at cell 0 (and 1 if needed).

Bit operations - 799

The bit operations follow the same general structure.

Firstly, we define a divmod 2 (DM2) function.
CELLS:   A  B   C  D
INPUT:  *A  0   0  0
OUTPUT: *0 A/2 A%2 0
dp@A; while{
  dec A,2; inc B,1; dp@A; inc A,1
  while{ #Check if A was 1 at the start
    dec D,1; pour A,C; dp@A;
  }
  dec C,1; pour C,A; inc D,1; dp@D
  #If A was 1 at the start, D will be 1 here
  while{
    dec D,1; inc C,1; dec B,1; dp@D
  }
  dp@A
}
Translated into BF, we have
    [->+<[>>>-<<<[->>+<<]]>>-[<<+>>-]>+[-<+<->>]<<<]
I'm not that good at BF, so my algorithm may not be the smallest.

Next, we define the program.
In this, we assume that the numbers are loaded in $2 (cell 2) and $3.

inc $1,8; dp@1 {
  dec  $1
  pour $3,$6
  DM2  $2        # result in $3,$4
  DM2  $6        # result in $7,$8
  pour $7, $2
  pour $8,$5
  bop  $4,$5     # result in $6
  pour $1,$5
  pour $5,$4,$1
  down $4,$5     # decrease $4 till 0, decrease $5 by same amount
  inc  $5,#7
  shl  $6,$5
  pour $6,$0     # $0 is result
  dp@  1
}
#Now, the result is in $0

Translated to BF (with linebreaks for readability):
  >++++++++[
    ->>[->>>+<<<]<
    [->+<[>>>-<<<[->>+<<]]>>-[<<+>>-]>+[-<+<->>]<<<]>>>>  #DM2 $2
    [->+<[>>>-<<<[->>+<<]]>>-[<<+>>-]>+[-<+<->>]<<<]>     #DM2 $6
    [-<<<<<+>>>>>]>
    [-<<<+>>>]<<<<
    (bop)<<<
    [->>>>+<<<<]>>>>
    [<+<<<+>>>>-]<
    [->-<]>
    +++++++
    [->[-<<++>>]<<[->>+<<]>]
    [-<<<<<<+>>>>>>]
    <<<<<
  ]

Replace (bop) by the appropriate expression.

XOR works like this: (252-5+15=262)
  [->-<]>[[-]>+<]
AND works like this: (252-5+11=258)
  [>[>+<-]<-]
OR  works like this: (252-5+32=279)
  [->>>+<<<]>[->>+<<]>>[[-]<+>]<<<

So, combining these, we have a total of 262+258+279=799 D:

Rotate Left A, 1 - 31/-

The number A is loaded in cell 0.

Pseudocode
    $0 := A
    $1 := $0 << 1    # this has the effect of discarding the top bit of A
    $2 := $0
    $3 := $0 << 1
    $2 -= $1 >> 1    # $2 now contains the top bit of A
    if $2 then $3++  # $3 now contains A rotated left 1
    res:= $3         # the result is in cell 3 now

Real code
    [->++>+>++<<<]>[-->-<]>[>+<[-]]
If you don't always need the pointer in the same position,
substitute [>+>] for the last loop (3 less chars).
However, the pointer will then sometimes end up in position 2, sometimes in position 4.

NOT A - 7

The number A is loaded in cell 0.

Pseudocode
    $0  := A
    $0  += 1
    $1  := 256-$0   #since ~A=255-A
    res := $1

+[->-<]


问:
Print numbers from 1 to 10
This might be a very simple challenge, but I am surprised it hasn't been done on code-golf yet:

Print all Integers from 1 to 10 inclusive in ascending order to standard output.

Your output format can be whatever your language supports. This includes arbitrary separators (commas, semicolons, newlines, combinations of those, etc., but no digits), and prefixes and postfixes (like [...]). However, you may not output any other numbers than 1 through 10. Your program may not take any input. Standard loopholes are disallowed.

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

Leaderboard

var QUESTION_ID=86075,OVERRIDE_USER=42570;function answersUrl(e){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"https://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="
"+e.body.replace(OVERRIDE_REG,"")+"
")});var a=r.match(SCORE_REG);a&&e.push({user:getAuthorName(s),size:+a[2],language:a[1],link:s.share_link})}),e.sort(function(e,s){var r=e.size,a=s.size;return r-a});var s={},r=1,a=null,n=1;e.forEach(function(e){e.size!=a&&(n=r),a=e.size,++r;var t=jQuery("#answer-template").html();t=t.replace("{{PLACE}}",n+".").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SIZE}}",e.size).replace("{{LINK}}",e.link),t=jQuery(t),jQuery("#answers").append(t);var o=e.language;/s.lang?1:e.lang<s.lang?-1:0});for(var c=0;c<t.length;++c){var i=jQuery("#language-template").html(),o=t[c];i=i.replace("{{LANGUAGE}}",o.lang).replace("{{NAME}}",o.user).replace("{{SIZE}}",o.size).replace("{{LINK}}",o.link),i=jQuery(i),jQuery("#languages").append(i)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;getAnswers();var SCORE_REG=/<h\d>\s*([^\n,]*[^\s,]),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/,OVERRIDE_REG=/^Override\s*header:\s*/i;```
<pre class="snippet-code-css lang-css prettyprint-override"><code>body{text-align:left!important}#answer-list,#language-list{padding:10px;width:290px;float:left}table thead{font-weight:700}table td{padding:5px}</code>```

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

Leaderboard

	Author	Language	Size

Winners by Language

Language	User	Score

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

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

```

答:
GNU sed, <s>22</s> 21 bytes

c1 2 3 4 5 6 7 8 9 10
```

<p>With <code>coreutils</code>, the code is only 7 bytes long!</p>

<pre class="lang-sed prettyprint-override"><code>eseq 10
</code>```

Adding to the diversity of languages used so far, I present a sed solution. The consensus is that sed is exempt from the "no input" rule, since the script doesn't start without.

Run:

echo | sed -f script.sed
```

Title: Print numbers from 1 to 10

Body:
GNU sed, <s>22</s> 21 bytes

c1 2 3 4 5 6 7 8 9 10

With coreutils, the code is only 7 bytes long!

eseq 10

Adding to the diversity of languages used so far, I present a sed solution. The consensus is that sed is exempt from the "no input" rule, since the script doesn't start without.

Run:

echo | sed -f script.sed


答:
Retina, 25 bytes

The \t should be replaced with an actual tab character (0x09).

```<code>\t
4$*
%`^  ( +)
/$.1$**/
</code>```

Try it online!

Explanation

```<code>\t
4$*
</code>```

Replace each tab with four spaces.

```<code>%`^  ( +)
/$.1$**/
</code>```

Transform each line separately (%) by matching 2+N spaces at the beginning of the line and replacing it with /.../ where ... is N copies of *.

Title: End the tabs versus space war

Body:
End the tabs versus space war

So, there has been a great deal of debate of whether to use tabs or spaces to indent/format code. Can you help the university settle the dispute, by going to an incredibly <s>crazy</s> unique method of formatting.

Your job is to write a full program or function which expands all tabs into four spaces. And then replaces a run of n leading spaces with "/(n - two stars here)/". You will receive input over multiple lines in any reasonable format (single string array of strings for each new line. Columnar array etc.)

Sample input shamelessly stolen. Note that since tabs get automagically expanded to four spaces on SE I represent it as the "^" character, but you must handle tabs (codepoint 0x09) as well. All "^" characters represent a tabulation.

```<code>Calculate the value 256 and test if it's zero
If the interpreter errors on overflow this is where it'll happen
++++++++[>++++++++<-]>[<++++>-]
+<[>-<
    Not zero so multiply by 256 again to get 65536
    [>++++<-]>[<++++++++>-]<[>++++++++<-]
    +>[>
        # Print "32"
        ++++++++++[>+++++<-]>+.-.[-]<
    <[-]<->] <[>>
        # Print "16"
        +++++++[>+++++++<-]>.+++++.[-]<
<<-]] >[>
    # Print "8"
    ++++++++[>+++++++<-]>.[-]<
<-]<
# Print " bit cells\n"
+++++++++++[>+++>+++++++++>+++++++++>+<<<<-]>-.>-.+++++++.+++++++++++.<.
>>.++.+++++++..<-.>>-
Clean up used cells.
[[-]<]l
^this is preceded by a tab
^^two tabs
^^^three tabs etcetera!
</code>```

Sample output

```<code>Calculate the value 256 and test if it's zero
If the interpreter errors on overflow this is where it'll happen
++++++++[>++++++++<-]>[<++++>-]
+<[>-<
/**/Not zero so multiply by 256 again to get 65536
/**/[>++++<-]>[<++++++++>-]<[>++++++++<-]
/**/+>[>
/******/# Print "32"
/******/++++++++++[>+++++<-]>+.-.[-]<
/**/<[-]<->] <[>>
/******/# Print "16"
/******/+++++++[>+++++++<-]>.+++++.[-]<
<<-]] >[>
/**/# Print "8"
/**/++++++++[>+++++++<-]>.[-]<
<-]<
# Print " bit cells\n"
+++++++++++[>+++>+++++++++>+++++++++>+<<<<-]>-.>-.+++++++.+++++++++++.<.
>>.++.+++++++..<-.>>-
Clean up used cells.
[[-]<]l
/**/this is preceded by a tab
/******/two tabs
/**********/three tabs etcetera!
</code>```

Because the university needs space to download both Vim and Emacs, you are allowed very little storage for your code. Therefore this is code-golf and the shortest code wins. You may assume that input is well formed and lines with less than four spaces (after replacement of tabs) may result in undefined behavior.

Disclaimer

This "excellent" formatting strategy came courtesy of Geobits, and is reproduced with his permission. No programmers were harmed during the production of this challenge.

Body:
Retina, 25 bytes

The \t should be replaced with an actual tab character (0x09).

\t
4$*
%`^  ( +)
/$.1$**/

<a href="http://retina.tryitonline.net/#code=CQo0JCogCiVgXiAgKCArKQovJC4xJCoqLw&input=Q2FsY3VsYXRlIHRoZSB2YWx1ZSAyNTYgYW5kIHRlc3QgaWYgaXQncyB6ZXJvCklmIHRoZSBpbnRlcnByZXRlciBlcnJvcnMgb24gb3ZlcmZsb3cgdGhpcyBpcyB3aGVyZSBpdCdsbCBoYXBwZW4KKysrKysrKytbPisrKysrKysrPC1dPls8KysrKz4tXQorPFs-LTwKICAgIE5vdCB6ZXJvIHNvIG11bHRpcGx5IGJ5IDI1NiBhZ2FpbiB0byBnZXQgNjU1MzYKICAgIFs-KysrKzwtXT5bPCsrKysrKysrPi1dPFs-KysrKysrKys8LV0KICAgICs-Wz4KICAgICAgICAjIFByaW50ICIzMiIKICAgICAgICArKysrKysrKysrWz4rKysrKzwtXT4rLi0uWy1dPAogICAgPFstXTwtPl0gPFs-PgogICAgICAgICMgUHJpbnQgIjE2IgogICAgICAgICsrKysrKytbPisrKysrKys8LV0-LisrKysrLlstXTwKPDwtXV0gPls-CiAgICAjIFByaW50ICI4IgogICAgKysrKysrKytbPisrKysrKys8LV0-LlstXTwKPC1dPAojIFByaW50ICIgYml0IGNlbGxzXG4iCisrKysrKysrKysrWz4rKys-KysrKysrKysrPisrKysrKysrKz4rPDw8PC1dPi0uPi0uKysrKysrKy4rKysrKysrKysrKy48Lgo-Pi4rKy4rKysrKysrLi48LS4-Pi0KQ2xlYW4gdXAgdXNlZCBjZWxscy4KW1stXTxdbAoJdGhpcyBpcyBwcmVjZWRlZCBieSBhIHRhYgoJCXR3byB0YWJzCgkJCXRocmVlIHRhYnMgZXRjZXRlcmEhIA" rel="nofollow">Try it online!

Explanation

\t
4$*

Replace each tab with four spaces.

%`^  ( +)
/$.1$**/

Transform each line separately (%) by matching 2+N spaces at the beginning of the line and replacing it with /.../ where ... is N copies of *.


答:
Bash, 89

Assumes all input to be lowercase.

```<code>a=`tee z|grep -o [aeiou]`
[ -n "$a" ]&&tr `tr -d \ <<<$a` `shuf -e $a|tr -d '
'`<z||cat z
</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:
Bash, 89

Assumes all input to be lowercase.

a=`tee z|grep -o [aeiou]`
[ -n "$a" ]&&tr `tr -d \ <<<$a` `shuf -e $a|tr -d '
'`<z||cat z


问:
Subtract the next numbers

Description

Subtract the next P numbers from a N number. The next number of N is N + 1.

Look at the examples to get what I mean.

Examples:

```<code>Input: N=2,P=3
Calculate: n - (n+1) - (n+2) - (n+3)     //Ending with 3, because P=3
Calculate: 2 -  2+1  -  2+2  - 2+3       //Replacing N with 2 from Input
Calculate: 2 -  3    -  4    - 5
Output: -10

Input: N=100,P=5
Calculate: n - (n+1) - (n+2) - (n+3) - (n+4) - (n+5)
Calculate: 100-  101 -  102  -  103  -  104  - 105
Output: -415

Input: N=42,P=0
Calculate: n
Calculate: 42
Output: 42

Input: N=0,P=3
Calculate: n - (n+1) - (n+2) - (n+3)
Calculate: 0 -  1    -  2    -  3
Output: -6

Input: N=0,P=0
Calulate: n
Calculate: 0
Output: 0
</code>```

Input:

N: Integer, positive, negative or 0

P: Integer, positive or 0, not negative

Output:

Integer or String, leading 0 allowed, trailing newline allowed

Rules:

No loopholes

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

Input and Output must be as described

答:
Fourier, 34 bytes

```<code>I~No~OI~P>0{1}{@P+N(N^~NO-N~ON)Oo}
</code>```

Try it online!

Title: Subtract the next numbers

Body:
Fourier, 34 bytes

I~No~OI~P>0{1}{@P+N(N^~NO-N~ON)Oo}

Try it online!


答:
Batch, 30 bytes

```<code>@cmd/cset/a%1-(%1*2+%2+1)*%2/2
</code>```

Takes n and p as command-line parameters and prints the result without a trailing newline.

Title: Subtract the next numbers

Body:
Description

Subtract the next P numbers from a N number. The next number of N is N + 1.

Look at the examples to get what I mean.

Examples:

```<code>Input: N=2,P=3
Calculate: n - (n+1) - (n+2) - (n+3)     //Ending with 3, because P=3
Calculate: 2 -  2+1  -  2+2  - 2+3       //Replacing N with 2 from Input
Calculate: 2 -  3    -  4    - 5
Output: -10

Input: N=100,P=5
Calculate: n - (n+1) - (n+2) - (n+3) - (n+4) - (n+5)
Calculate: 100-  101 -  102  -  103  -  104  - 105
Output: -415

Input: N=42,P=0
Calculate: n
Calculate: 42
Output: 42

Input: N=0,P=3
Calculate: n - (n+1) - (n+2) - (n+3)
Calculate: 0 -  1    -  2    -  3
Output: -6

Input: N=0,P=0
Calulate: n
Calculate: 0
Output: 0
</code>```

Input:

N: Integer, positive, negative or 0

P: Integer, positive or 0, not negative

Output:

Integer or String, leading 0 allowed, trailing newline allowed

Rules:

No loopholes

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

Input and Output must be as described

Body:
Batch, 30 bytes

@cmd/cset/a%1-(%1*2+%2+1)*%2/2

Takes n and p as command-line parameters and prints the result without a trailing newline.


答:
S.I.L.O.S, 80 bytes

```<code>GOTO b
lbla
n+1
m-n
i-1
GOTO d
lblb
readIO
n=i
m=n
readIO
lbld
if i a
printInt m
</code>```

Try it online with test cases:

2,3

100,5

42,0

0,3

0,0

Title: Subtract the next numbers

Body:
S.I.L.O.S, 80 bytes

GOTO b
lbla
n+1
m-n
i-1
GOTO d
lblb
readIO
n=i
m=n
readIO
lbld
if i a
printInt m

Try it online with test cases:

2,3

100,5

42,0

0,3

0,0


答:
Javascript (ES6), <s>20</s> <s>19</s> 18 bytes

```<code>n=>p=>n+p*(~p/2-n)
</code>```

Saved 1 byte by currying, as suggested by Zwei

Saved 1 byte thanks to user81655

Test

let f =
n=>p=>n+p*(~p/2-n)

console.log(f(2)(3))
console.log(f(100)(5))
console.log(f(42)(0))
console.log(f(0)(3))
console.log(f(0)(0))```

Title: Subtract the next numbers

Body:
Javascript (ES6), <s>20</s> <s>19</s> 18 bytes

n=>p=>n+p*(~p/2-n)

Saved 1 byte by currying, as suggested by Zwei

Saved 1 byte thanks to user81655

Test

let f =
n=>p=>n+p*(~p/2-n)

console.log(f(2)(3))
console.log(f(100)(5))
console.log(f(42)(0))
console.log(f(0)(3))
console.log(f(0)(0))


答:
CJam, 8 bytes

```<code>{),f+:-}
</code>```

Test suite.

Too bad that the closed form solution is longer. :|

Explanation

```<code>),  e# Get range [0 1 ... P].
f+  e# Add N to each value to get [N N+1 ... N+P].
:-  e# Fold subtraction over the list, computing N - (N+1) - (N+2) - ... - (N+P).
</code>```

Title: Subtract the next numbers

Body:
CJam, 8 bytes

{),f+:-}

Test suite.

Too bad that the closed form solution is longer. :|

Explanation

),  e# Get range [0 1 ... P].
f+  e# Add N to each value to get [N N+1 ... N+P].
:-  e# Fold subtraction over the list, computing N - (N+1) - (N+2) - ... - (N+P).


答:
R, <s>17</s> 14 bytes

```<code>N-N*P-sum(0:P)
</code>```

Thanks to billywob for golfing away 3 bytes. Previous answer:

```<code>N-sum(N+if(P)1:P)
</code>```

Note that 1:0 expands to the vector (1,0) so we need the if(P) condition (or to use seq_len, but that is more bytes). Without the condition, we would get the wrong output if P=0.

If P is zero, then the sum expands to sum(N+NULL), then to sum(numeric(0)), which is zero.

Title: Subtract the next numbers

Body:
R, <s>17</s> 14 bytes

N-N*P-sum(0:P)

Thanks to billywob for golfing away 3 bytes. Previous answer:

N-sum(N+if(P)1:P)

Note that 1:0 expands to the vector (1,0) so we need the if(P) condition (or to use seq_len, but that is more bytes). Without the condition, we would get the wrong output if P=0.

If P is zero, then the sum expands to sum(N+NULL), then to sum(numeric(0)), which is zero.


答:
Pyke, 6 bytes

```<code>m+mhs-
</code>```

Try it here!

```<code>m+     -    map(range(input_2), +input_1)
  mh   -   map(^, +1)
    s  -  sum(^)
     - - input_1 - ^
</code>```

Title: Subtract the next numbers

Body:
Pyke, 6 bytes

m+mhs-

Try it here!

m+     -    map(range(input_2), +input_1)
  mh   -   map(^, +1)
    s  -  sum(^)
     - - input_1 - ^


答:
05AB1E, <s>5</s> 3 bytes

Saved 2 bytes thanks to Adnan

```<code>Ý+Æ
</code>```

Explanation

Takes P then N as input.

```<code>       # implicit input, ex 5, 100
Ý      # range(0,X): [0,1,2,3,4,5]
 +     # add: [100,101,102,103,104,105]
  Æ    # reduced subtraction: 100-101-102-103-104-105
</code>```

Title: Subtract the next numbers

Body:
05AB1E, <s>5</s> 3 bytes

Saved 2 bytes thanks to Adnan

Ý+Æ

Explanation

Takes P then N as input.

       # implicit input, ex 5, 100
Ý      # range(0,X): [0,1,2,3,4,5]
 +     # add: [100,101,102,103,104,105]
  Æ    # reduced subtraction: 100-101-102-103-104-105


答:
Perl, <s>23</s> 22 bytes

Includes +1 for -p

Give n and p (in that order) on separate lines of STDIN:

```<code>subtract.pl
2
3
^D
</code>```

subtract.pl:

```<code>#!/usr/bin/perl -p
$_-=eval"+2+\$_++"x<>
</code>```

(using '' quotes to save the \ invokes a 2 byte penalty because it can't be combined with -e)

Same idea and length:

```<code>#!/usr/bin/perl -p
$_+=eval"-1-++\$_"x<>
</code>```

Surprisingly doing the actual calculation is shorter than using the direct formula (these $'s really hurt for arithmetic)

Title: Subtract the next numbers

Body:
Perl, <s>23</s> 22 bytes

Includes +1 for -p

Give n and p (in that order) on separate lines of STDIN:

subtract.pl
2
3
^D

subtract.pl:

#!/usr/bin/perl -p
$_-=eval"+2+\$_++"x<>

(using '' quotes to save the \ invokes a 2 byte penalty because it can't be combined with -e)

Same idea and length:

#!/usr/bin/perl -p
$_+=eval"-1-++\$_"x<>

Surprisingly doing the actual calculation is shorter than using the direct formula (these $'s really hurt for arithmetic)


答:
Python 2, <s>26 24</s> 23 bytes

-2 bytes thanks to @Adnan (replace p*(p+1)/2 with p*-~p/2)

-1 byte thanks to @MartinEnder (replace -p*-~p/2 with +p*~p/2

lambda n,p:n-p*n+p*~p/2
```

Tests are on ideone

Title: Subtract the next numbers

Body:
Python 2, <s>26 24</s> 23 bytes

-2 bytes thanks to @Adnan (replace p*(p+1)/2 with p*-~p/2)

-1 byte thanks to @MartinEnder (replace -p*-~p/2 with +p*~p/2

lambda n,p:n-p*n+p*~p/2

Tests are on ideone


答:
C++, <s>54</s> 51 bytes

```<code>  [](int N,int P){int F=N;while(P--)F-=++N;return F;}
</code>```

<s>[](int N,int P){int F;for(F=N;P;F-=++N,P--);return F;}</s>

Test:

```<code>#include <iostream>
int main(void)
{
    int N, P;
    std::cin >> N >> P;
    auto f = [](int N,int P){int F=N;while(P--)F-=++N;return F;};
    std::cout << f(N,P) << std::endl;
    return 0;
}
</code>```

Title: Subtract the next numbers

Body:
C++, <s>54</s> 51 bytes

  [](int N,int P){int F=N;while(P--)F-=++N;return F;}

<s>[](int N,int P){int F;for(F=N;P;F-=++N,P--);return F;}</s>

Test:

#include <iostream>
int main(void)
{
    int N, P;
    std::cin >> N >> P;
    auto f = [](int N,int P){int F=N;while(P--)F-=++N;return F;};
    std::cout << f(N,P) << std::endl;
    return 0;
}


答:
Java, <s>67</s>, 63 bytes

Golfed:

```<code>int x(int n,int p){return-((p%2<1)?p*p/2+p:p/2*(p+2)+1)+n-p*n;}
</code>```

Ungolfed:

```<code>int x(int n, int p)
{
    return -((p%2<1) ? p*p/2+p : p/2 * (p+2) + 1) + n - p*n;
}
</code>```

Basically I did some math on the formula. The n - p*n part takes care of the all n's in the formula. Then I used a super fun property of summing together linearly increasing set of integers (arithmetic series): I used the sum of first and last integer and then multiply it by set.length / 2 (I also check for the parity and handle it appropriately).

Try it: https://ideone.com/DEd85A

Title: Subtract the next numbers

Body:
Java, <s>67</s>, 63 bytes

Golfed:

int x(int n,int p){return-((p%2<1)?p*p/2+p:p/2*(p+2)+1)+n-p*n;}

Ungolfed:

int x(int n, int p)
{
    return -((p%2<1) ? p*p/2+p : p/2 * (p+2) + 1) + n - p*n;
}

Basically I did some math on the formula. The n - p*n part takes care of the all n's in the formula. Then I used a super fun property of summing together linearly increasing set of integers (arithmetic series): I used the sum of first and last integer and then multiply it by set.length / 2 (I also check for the parity and handle it appropriately).

Try it: https://ideone.com/DEd85A


答:
><>, 15 + 3 = 18 bytes

```<code>\/:l2-),:2%0go:
</code>```

+3 bytes for the -v flag to initialise the stack with the input. Try it online!

 ><> is a toroidal 2D language, so the following runs in a loop:

```<code>\/          Mirrors that reflect the instruction pointer. Since the code is
            one row high, the reflection wraps and the IP ends up moving in the
            same direction anyway, so these are no-ops.

:l2-)       Push (input > length of stack - 1) - note that the actual subtraction
            is by 2 to account for the fact that we duplicated an element with :

,           Divide the input by the above. If (input == length of stack - 1),
            then the program errors out due to division by 0. Otherwise, the
            input is unchanged.

:2%0g       Push the char at (input % 2, 0), which will be one of the two slashes
            at the beginning of the code

o           Output this char

:           Duplicate the input, increasing the length of the stack by 1
</code>```

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:
><>, 15 + 3 = 18 bytes

\/:l2-),:2%0go:

+3 bytes for the -v flag to initialise the stack with the input. Try it online!

 ><> is a toroidal 2D language, so the following runs in a loop:

\/          Mirrors that reflect the instruction pointer. Since the code is
            one row high, the reflection wraps and the IP ends up moving in the
            same direction anyway, so these are no-ops.

:l2-)       Push (input > length of stack - 1) - note that the actual subtraction
            is by 2 to account for the fact that we duplicated an element with :

,           Divide the input by the above. If (input == length of stack - 1),
            then the program errors out due to division by 0. Otherwise, the
            input is unchanged.

:2%0g       Push the char at (input % 2, 0), which will be one of the two slashes
            at the beginning of the code

o           Output this char

:           Duplicate the input, increasing the length of the stack by 1


答:
Mathematica, 15 bytes

```<code>#2-##-#(#+1)/2&
</code>```

An unnamed function that receives P and n as its parameters in that order.

Uses the closed form solution n - n*p - p(p+1)/2.

Title: Subtract the next numbers

Body:
Mathematica, 15 bytes

#2-##-#(#+1)/2&

An unnamed function that receives P and n as its parameters in that order.

Uses the closed form solution n - n*p - p(p+1)/2.


问:
10 PRINT CHR$(205.5+RND(1)); : GOTO 10 in PHP (or anything else, for that matter)
Just had a 'spirited' conversation with a co-worker about the succinctness of the following BASIC statement:

```<code>10 PRINT CHR$(205.5+RND(1)); : GOTO 10
</code>```

It's the title of this book, and will simply print a sequence of / and \ characters, alternating between the two randomly, resulting in a pattern similar to this:

(Image borrowed from http://www.flickr.com/photos/rndmcnlly/5058442151/sizes/o/in/photostream/)

Being of a PHP proclivity, we wondered what the most compact way of writing the same thing in PHP would be, and came up with this:

```<code>while(1) { echo chr(47 + 45 * rand(0,1)); }
</code>```

chr(47) is a / character, and chr(92) is a \. So the statement echo chr(47 + 45 * rand(0,1)); will randomly alternate between the two, ad nauseam.

In a language of your choosing, write the shortest program or function to output an infinite random sequence of \ and / characters, where each character has an equal probability of being chosen.

答:
ruby, 27 23 chars

```<code>loop{$><<"/\\"[rand 2]}
</code>```

$><< is 'print to stdout'.

OwnerDisplayName: Judy

ContentLicense: CC BY-SA 4.0

Body:
ruby, 27 23 chars

loop{$><<"/\\"[rand 2]}

$><< is 'print to stdout'.


答:
Haskell, 21 bytes

```<code>a#b=foldl1(-)[a..a+b]
</code>```

Title: Subtract the next numbers

Body:
Haskell, 21 bytes

a#b=foldl1(-)[a..a+b]


答:
Brachylog, <s>19</s> 17 bytes

```<code>hHyL,?+y:Lx+$_:H+
</code>```

Explanation

```<code>hH                  Input = [H, whatever]
 HyL,               L = [0, …, H]
     ?+             Sum the two elements in the Input
       y            Yield the range from 0 to the result of the sum
        :Lx         Remove all elements of L from that range
           +        Sum the remaining elements
            $_      Negate the result
              :H+   Add H
</code>```

Title: Subtract the next numbers

Body:
Description

Subtract the next P numbers from a N number. The next number of N is N + 1.

Look at the examples to get what I mean.

Examples:

```<code>Input: N=2,P=3
Calculate: n - (n+1) - (n+2) - (n+3)     //Ending with 3, because P=3
Calculate: 2 -  2+1  -  2+2  - 2+3       //Replacing N with 2 from Input
Calculate: 2 -  3    -  4    - 5
Output: -10

Input: N=100,P=5
Calculate: n - (n+1) - (n+2) - (n+3) - (n+4) - (n+5)
Calculate: 100-  101 -  102  -  103  -  104  - 105
Output: -415

Input: N=42,P=0
Calculate: n
Calculate: 42
Output: 42

Input: N=0,P=3
Calculate: n - (n+1) - (n+2) - (n+3)
Calculate: 0 -  1    -  2    -  3
Output: -6

Input: N=0,P=0
Calulate: n
Calculate: 0
Output: 0
</code>```

Input:

N: Integer, positive, negative or 0

P: Integer, positive or 0, not negative

Output:

Integer or String, leading 0 allowed, trailing newline allowed

Rules:

No loopholes

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

Input and Output must be as described

Body:
Brachylog, <s>19</s> 17 bytes

hHyL,?+y:Lx+$_:H+

Explanation

hH                  Input = [H, whatever]
 HyL,               L = [0, …, H]
     ?+             Sum the two elements in the Input
       y            Yield the range from 0 to the result of the sum
        :Lx         Remove all elements of L from that range
           +        Sum the remaining elements
            $_      Negate the result
              :H+   Add H


问:
Lucas Vs. The Garage Door Remote

Disclaimer

While I know there is this particular related question, my question uses two garage doors, a randomizing component, and I'm also basing this on real life events, seeing my son accidentally lowered one of said garage doors whilst I was walking out of the garage last week... Nothing like a blow to the head to get the creative juices flowing! ;)

The Background

Lucas (my 15 month old son) likes to play with the garage remote. There are two buttons on this remote, one for the left garage door, and one for the right garage door. Both buttons work in the same manner; press once to get the door to start opening, press again to stop, press again to start closing, press again to stop again, and so on.

Lucas loves this remote, he'll randomly press one of the buttons, or both, or none at all. If both are pressed, no signal is sent, but a press of one button will send out a signal.

So, the code-golf challenge is divided on two parts:

Part One

Generate a 60 character long string representing Lucas random button presses over a minute. "Random" in this case means "with an equal chance of each input at each tick". The characters are as follows:

0: Lucas has either pressed no button, or has pressed both buttons. Either way, no signal has been sent.

1: The button for the left garage door has been pressed by Lucas

2: The button for the right garage door has been pressed by Lucas

Part Two

Using the string generated in Part One, simulate the opening and closing of the two-car garage using the numbers as triggers for opening, stopping and closing these doors.

My garage doors are pretty quick (see Disclaimer above as to why).  Once you press the button it takes four seconds to be fully open or closed.

So, if closed:

0 sec: 0% open (closed); when button is pressed, door starts opening

1 sec: 25% open

2 sec: 50% open

3 sec: 75% open

4 sec: 100% open, door stops

And therefore, if open:

0 sec: 100% open; when button is pressed, door starts closing

1 sec: 75% open

2 sec: 50% open

3 sec: 25% open

4 sec: 0% open (closed), door stops

If a particular door is in motion, a signal to that same door will stop it. The next signal sent to that same door after that will send it moving in the opposite direction. If a door is stopped when it has previously been in motion and is now fully open or fully closed when the "stop" signal is received, the door will register as "stopped" in the fully-open or fully-closed state, ready to move in the opposite direction when it receives a new signal.

With this simulation, both garage doors will be initially in the closed position. So, let's look at a 10 second list of commands and see what happens if Lucas was to perform them on the remote:

```<code>2120221120
2: (L:0% stopped, R:0% opening)
1: (L:0% opening, R:25% opening)
2: (L:25% opening, R:50% stopped)
0: (L:50% opening, R:50% stopped)
2: (L:75% opening, R:50% closing)
2: (L:100% stopped, R:25% stopped)
1: (L:100% closing, R:25% stopped)
1: (L:75% stopped, R:25% stopped)
2: (L:75% stopped, R:25% opening)
0: (L:75% stopped, R:50% opening)
</code>```

Output

The first part of the output requires the display of the 60 character long string of random "0", "1" and "2" characters generated from Part One. eg.
212022112021202211202120221120212022112021202211202120221120

Below this string, is the processing of these "signals" according to the rules mentioned above of how the garage doors will behave with each respective character (on a second by second basis). You should end up with 60 lines as a result below the initial display string.

Each of these processed lines will be in the form of:
N: (L:X% XXXXXXX, R:Y% YYYYYYY) where:

N is the nth character from the respective random string, which will be in the form of a 0, 1, or 2.

X% is the percentage of openness of the left door (there is no zero padding)

XXXXXXX is the status of the left door. If the door is not in motion (i.e. not opening or closing) the status "stopped" is enforced, meaning it has been stopped in motion (only possible at 25%, 50% or 75%) or stopped when fully open (100%) or fully closed (0%). Otherwise, the door will either be "opening" or "closing".

Y% is the percentage of openness of the right door (there is no zero padding)

YYYYYYY is the status of the right door. If the door is not in motion (i.e. not opening or closing) the status "stopped" is enforced, meaning it has been stopped in motion (only possible at 25%, 50% or 75%) or stopped when fully open (100%) or fully closed (0%). Otherwise, the door will either be "opening" or "closing".

Example shown below using 10 "signals" and 10 processed lines

```<code>2120221120
2: (L:0% stopped, R:0% opening)
1: (L:0% opening, R:25% opening)
2: (L:25% opening, R:50% stopped)
0: (L:50% opening, R:50% stopped)
2: (L:75% opening, R:50% closing)
2: (L:100% stopped, R:25% stopped)
1: (L:100% closing, R:25% stopped)
1: (L:75% stopped, R:25% stopped)
2: (L:75% stopped, R:25% opening)
0: (L:75% stopped, R:50% opening)
</code>```

This is code-golf, so the shortest code will be the clear winner. I've made this a little easy by using phrases like "opening", "stopped" and "closing", which are all seven letters... so you may want to work that into your strategy.

Best of luck!

答:
Pyth, <s>156</s> <s>149</s> 145 bytes

```<code>jkJmO3U60K=G*]Z3=b*3]_1VJFHS2I&=T@KHq*2hT@XHGTH XbHT XKH0)) XKN*_@XbN|@KN@bNN!@KN%+N": (L:%s, R:%s)"m++*@Gd25"% "%3>"csoltpooespnipinengdg"h@KdS2
</code>```

A direct translation of my Python answer.

Try it online!

Explanation:

```<code>jk                              " print ''.join(map(str,                   "
JmO3U60                         "  J = [randint(0,2) for _ in range(60)])) "
K=G*]Z3                         " K = copy(G = [0] * 3)                    "
=b*3]_1                         " b = [-1] * 3                             "
VJ                              " for N in J:                              "
FHS2                            "  for H in range(1, 3):                   "
I&=T@KH                         "   if ((T = K[H]) and                     "
q*2hT@XHGTH                     "       (2 * (T + 1) == (G[H] += T)[H]):   "
 XbHT                           "    b[H] = T                              "
 XKH0))                         "    K[H] = 0                              "
 XKN*_@XbN|@KN@bNN              "  K[N] = (-(b[N] = K[N] or B[N])[N] *     "
!@KN                            "   (not K[N]))                            "
%+N": (L:%s, R:%s)"             "  print(str(N) + ': (L:%s, R:%s)' %       "
m++                             "   map(lambda d:                          "
*@Gd25                          "    G[d] * 25 +                           "
"% "                            "    '% ' +                                "
%3>"csoltpooespnipinengdg"h@Kd  "    'csoltpooespnipinengdg'[K[d]+1::3]]   "
S2                              "   ), range(1, 3))                        "
</code>```

Title: Lucas Vs. The Garage Door Remote

Body:
Pyth, <s>156</s> <s>149</s> 145 bytes

jkJmO3U60K=G*]Z3=b*3]_1VJFHS2I&=T@KHq*2hT@XHGTH XbHT XKH0)) XKN*_@XbN|@KN@bNN!@KN%+N": (L:%s, R:%s)"m++*@Gd25"% "%3>"csoltpooespnipinengdg"h@KdS2

A direct translation of my Python answer.

Try it online!

Explanation:

jk                              " print ''.join(map(str,                   "
JmO3U60                         "  J = [randint(0,2) for _ in range(60)])) "
K=G*]Z3                         " K = copy(G = [0] * 3)                    "
=b*3]_1                         " b = [-1] * 3                             "
VJ                              " for N in J:                              "
FHS2                            "  for H in range(1, 3):                   "
I&=T@KH                         "   if ((T = K[H]) and                     "
q*2hT@XHGTH                     "       (2 * (T + 1) == (G[H] += T)[H]):   "
 XbHT                           "    b[H] = T                              "
 XKH0))                         "    K[H] = 0                              "
 XKN*_@XbN|@KN@bNN              "  K[N] = (-(b[N] = K[N] or B[N])[N] *     "
!@KN                            "   (not K[N]))                            "
%+N": (L:%s, R:%s)"             "  print(str(N) + ': (L:%s, R:%s)' %       "
m++                             "   map(lambda d:                          "
*@Gd25                          "    G[d] * 25 +                           "
"% "                            "    '% ' +                                "
%3>"csoltpooespnipinengdg"h@Kd  "    'csoltpooespnipinengdg'[K[d]+1::3]]   "
S2                              "   ), range(1, 3))                        "


答:
Ruby, 114 bytes

```<code>i = gets.chomp.to_i
l = [123, 234, 345, 456, 567, 678, 789]
y=false
l.each {|x| if i==x then y=true end;}
puts y
</code>```

I don't know how many bytes this answer is, but I'm guessing it's not that small.

Title: As Easy as One-Two-Three

Body:
Write a program or function that takes in a positive integer. You can assume the input is valid and may take it as a string. If the number is any of

```<code>123
234
345
456
567
678
789
</code>```

then output a truthy value. Otherwise, output a falsy value. For example, the inputs

```<code>1
2
3
12
122
124
132
321
457
777
890
900
1011
1230
1234
</code>```

must all result in falsy output. (The input will not have leading zeroes so you needn't worry about things like 012.)

The shortest code in bytes wins.

Body:
Ruby, 114 bytes

i = gets.chomp.to_i
l = [123, 234, 345, 456, 567, 678, 789]
y=false
l.each {|x| if i==x then y=true end;}
puts y

I don't know how many bytes this answer is, but I'm guessing it's not that small.


Title: Subtract the next numbers

Body:
Labyrinth, 15 bytes

?:?:}*-{:)*#/-!

or

??:}`)*{:)*#/-!

Uses the closed form solution n - n*P - P*(P+1)/2.


答:
MATL, 5 bytes

```<code>:y+s-
</code>```

Inputs are P and then N.

Try it at MATL Online!

Explanation

```<code>:     % Take P implicitly. Range [1 2 ... P]
      %     Stack: [1 2 ... P]
y     % Take N implicitly at the bottom of the stack, and push another copy
      %     Stack: N, [1 2 ... P], N
+     % Add the top two arrays in the stack , element-wise
      %     Stack: N, [N+1 N+2 ... N+P]
s     % Sum of array
      %     Stack: N, N+1+N+2+...+N+P
-     % Subtract the top two numbers
      %     Stack: N-(N+1+N+2+...+N+P)
      % Implicitly display
</code>```

Title: Subtract the next numbers

Body:
MATL, 5 bytes

:y+s-

Inputs are P and then N.

Try it at MATL Online!

Explanation

:     % Take P implicitly. Range [1 2 ... P]
      %     Stack: [1 2 ... P]
y     % Take N implicitly at the bottom of the stack, and push another copy
      %     Stack: N, [1 2 ... P], N
+     % Add the top two arrays in the stack , element-wise
      %     Stack: N, [N+1 N+2 ... N+P]
s     % Sum of array
      %     Stack: N, N+1+N+2+...+N+P
-     % Subtract the top two numbers
      %     Stack: N-(N+1+N+2+...+N+P)
      % Implicitly display


问:
Tips for golfing in C++
What general tips do you have for golfing in C++?

I'm looking for ideas that can be applied to code golf problems in general that are at least somewhat specific to C++ (e.g. "remove comments" is not an answer). Please post one tip per answer.

(Tips that apply to C as well can be found in Tips for golfing in C - but note that some C tips don't work in C++.  For example, C++ does require function prototypes and return values.)

答:
In my first attempt at code golf for task "Subtract the next numbers" I have started from function (58 bytes)

int f(int N, int P){int F;for(F=N;P;F-=++N,P--);return F;}
```

<p>then safe 5 bytes with shifting to lambda and moving initialization out of <code>for</code> (53)</p>

<pre class="lang-cpp prettyprint-override"><code>[](int N,int P){int F=N;for(;P;F-=++N,P--);return F;}
</code>```

and finally after switching from for to while I got 51 bytes:

[](int N,int P){int F=N;while(P--)F-=++N;return F;}
```

<p>The ungolfed test code is something like:</p>

<pre class="lang-cpp prettyprint-override"><code>#include <iostream>
int main(void)
{
    int N, P;
    std::cin >> N >> P;
    auto f = [](int N,int P)
    {
        int F = N;
        while (P--)
            F -= ++N;
        return F;
    };
    std::cout << f(N, P) << std::endl;
    return 0;
}
</code>```

UPDATE:

Actually for can reach the same length as while:

[](int N,int P){int F=N;for(;P--;F-=++N);return F;}
```

Title: Tips for golfing in C++

Body:
In my first attempt at code golf for task "Subtract the next numbers" I have started from function (58 bytes)

int f(int N, int P){int F;for(F=N;P;F-=++N,P--);return F;}

then safe 5 bytes with shifting to lambda and moving initialization out of for (53)

[](int N,int P){int F=N;for(;P;F-=++N,P--);return F;}

and finally after switching from for to while I got 51 bytes:

[](int N,int P){int F=N;while(P--)F-=++N;return F;}

The ungolfed test code is something like:

#include <iostream>
int main(void)
{
    int N, P;
    std::cin >> N >> P;
    auto f = [](int N,int P)
    {
        int F = N;
        while (P--)
            F -= ++N;
        return F;
    };
    std::cout << f(N, P) << std::endl;
    return 0;
}

UPDATE:

Actually for can reach the same length as while:

[](int N,int P){int F=N;for(;P--;F-=++N);return F;}


答:
Rust, <s>210</s> 190 Bytes

```<code>fn main(){let x:usize=std::env::args().nth(1).unwrap().parse::<usize>().unwrap();let l:&str=match x%2{0=>"\\",1=>"/",_=>"",};println!("{}",std::iter::repeat(l).take(x).collect::<String>());}
</code>```

Ungolfed:

```<code>fn main() {
    let x : usize = std::env::args().nth(1)
                                    .unwrap()
                                    .parse::<usize>()
                                    .unwrap();
    let l : &str = match x % 2 {
        0 => "\\",
        1 => "/",
        _ => "",
    };
    println!("{}", std::iter::repeat(l).take(x)
                                       .collect::<String>());
}
</code>```

I don't usually golf (so I bet this isn't a great score, at least for Rust), but I figured this would be good Rust practice. This compiles into an executable run as squiggly.exe x where x is the number of times to repeat the character.

Title: The Squiggly Sequence

Body:
Rust, <s>210</s> 190 Bytes

fn main(){let x:usize=std::env::args().nth(1).unwrap().parse::<usize>().unwrap();let l:&str=match x%2{0=>"\\",1=>"/",_=>"",};println!("{}",std::iter::repeat(l).take(x).collect::<String>());}

Ungolfed:

fn main() {
    let x : usize = std::env::args().nth(1)
                                    .unwrap()
                                    .parse::<usize>()
                                    .unwrap();
    let l : &str = match x % 2 {
        0 => "\\",
        1 => "/",
        _ => "",
    };
    println!("{}", std::iter::repeat(l).take(x)
                                       .collect::<String>());
}

I don't usually golf (so I bet this isn't a great score, at least for Rust), but I figured this would be good Rust practice. This compiles into an executable run as squiggly.exe x where x is the number of times to repeat the character.


答:
Java 7, <s>43</s> 40 bytes

```<code>int c(int n,int p){return n-p*n+p*~p/2;}
</code>```

Java 8, 19 bytes

```<code>(n,p)->n-p*n+p*~p/2
</code>```

Shamelessly stolen from @JonathanAllan's amazing Python 2 formula.

Original answer (<s>61</s> 60 bytes):

```<code>int c(int n,int p){int r=n,i=1;for(;i<p;r-=n+++i);return r;}
</code>```

Ungolfed & test cases:

Try it here.

```<code>class M{
  static int c(int n, int p){
    return n - p*n + p*~p / 2;
  }

  public static void main(String[] a){
    System.out.println(c(2, 3));
    System.out.println(c(100, 5));
    System.out.println(c(42, 0));
    System.out.println(c(0, 3));
    System.out.println(c(0, 0));
  }
}
</code>```

Output:

```<code>-10
-415
42
-6
0
</code>```

Title: Subtract the next numbers

Body:
Java 7, <s>43</s> 40 bytes

int c(int n,int p){return n-p*n+p*~p/2;}

Java 8, 19 bytes

(n,p)->n-p*n+p*~p/2

Shamelessly stolen from @JonathanAllan's amazing Python 2 formula.

Original answer (<s>61</s> 60 bytes):

int c(int n,int p){int r=n,i=1;for(;i<p;r-=n+++i);return r;}

Ungolfed & test cases:

Try it here.

class M{
  static int c(int n, int p){
    return n - p*n + p*~p / 2;
  }

  public static void main(String[] a){
    System.out.println(c(2, 3));
    System.out.println(c(100, 5));
    System.out.println(c(42, 0));
    System.out.println(c(0, 3));
    System.out.println(c(0, 0));
  }
}

Output:

-10
-415
42
-6
0


答:
Pyth, 11 bytes

```<code>Ms+Gm_+GdSH
</code>```

A function g that takes input of n and p via argument and prints the result. It can be called in the form gn p.

Try it online

How it works

```<code>Ms+Gm_+GdSH  Function g. Inputs: G, H
M            g=lambda G,H:
         SH   1-indexed range, yielding [1, 2, 3, ..., H]
    m_+Gd     Map lambda d:-(G+d) over the above, yielding [-(G+1), -(G+2), -(G+3),
              ..., -(G+H)]
  +G          Add G to the above, yielding [G, -(G+1), -(G+2), -(G+3), ..., -(G+H)]
 s            Reduce on addition with base case 0, yielding G-(G+1)-(G+2)-(G+3)...
              -(G+H)
              Implicitly print
</code>```

Title: Subtract the next numbers

Body:
Pyth, 11 bytes

Ms+Gm_+GdSH

A function g that takes input of n and p via argument and prints the result. It can be called in the form gn p.

Try it online

How it works

Ms+Gm_+GdSH  Function g. Inputs: G, H
M            g=lambda G,H:
         SH   1-indexed range, yielding [1, 2, 3, ..., H]
    m_+Gd     Map lambda d:-(G+d) over the above, yielding [-(G+1), -(G+2), -(G+3),
              ..., -(G+H)]
  +G          Add G to the above, yielding [G, -(G+1), -(G+2), -(G+3), ..., -(G+H)]
 s            Reduce on addition with base case 0, yielding G-(G+1)-(G+2)-(G+3)...
              -(G+H)
              Implicitly print


答:
C, 39 chars (38 on MSVC)

```<code>main(){while(putchar(rand()%2?47:92));}
</code>```

See it run.

On MSVC, we can replace putchar() with _putch() and save a byte, but it doesn't work in IDEOne.

```<code>main(){while(_putch(rand()%2?47:92));}
</code>```

Title: 10 PRINT CHR$(205.5+RND(1)); : GOTO 10 in PHP (or anything else, for that matter)

Body:
Just had a 'spirited' conversation with a co-worker about the succinctness of the following BASIC statement:

```<code>10 PRINT CHR$(205.5+RND(1)); : GOTO 10
</code>```

It's the title of this book, and will simply print a sequence of / and \ characters, alternating between the two randomly, resulting in a pattern similar to this:

(Image borrowed from http://www.flickr.com/photos/rndmcnlly/5058442151/sizes/o/in/photostream/)

Being of a PHP proclivity, we wondered what the most compact way of writing the same thing in PHP would be, and came up with this:

```<code>while(1) { echo chr(47 + 45 * rand(0,1)); }
</code>```

chr(47) is a / character, and chr(92) is a \. So the statement echo chr(47 + 45 * rand(0,1)); will randomly alternate between the two, ad nauseam.

In a language of your choosing, write the shortest program or function to output an infinite random sequence of \ and / characters, where each character has an equal probability of being chosen.

Body:
C, 39 chars (38 on MSVC)

main(){while(putchar(rand()%2?47:92));}

See it run.

On MSVC, we can replace putchar() with _putch() and save a byte, but it doesn't work in IDEOne.

main(){while(_putch(rand()%2?47:92));}


答:
R, 46 or 51 bytes, depending on spacing

```<code>s=1:scan();plot(s*sin(s),s*cos(s),pch=letters)
</code>```

(updated version of plot: the gray spiral isn't plotted by default but I added it after to show that the letters indeed lie on a spiral.)

The spiral isn't of constant spacing, so I hope this is okay. If constant spacing is required, start with s=(1:scan())^.5 instead, and add 5 bytes to the total. Then the output is as below (n=150):

Title: Roll the Alphabet into a Spiral

Body:
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!

Body:
R, 46 or 51 bytes, depending on spacing

s=1:scan();plot(s*sin(s),s*cos(s),pch=letters)

(updated version of plot: the gray spiral isn't plotted by default but I added it after to show that the letters indeed lie on a spiral.)

The spiral isn't of constant spacing, so I hope this is okay. If constant spacing is required, start with s=(1:scan())^.5 instead, and add 5 bytes to the total. Then the output is as below (n=150):


答:
Haskell, <s>19</s> 18 bytes

```<code>n#p=n+sum[-n-p..n]
</code>```

Previous 19 bytes solutions

```<code>n#p=n-n*p-(p*p+p)/2
n#p=n-sum[n+1..n+p]
</code>```

Title: Subtract the next numbers

Body:
Haskell, <s>19</s> 18 bytes

n#p=n+sum[-n-p..n]

Previous 19 bytes solutions

n#p=n-n*p-(p*p+p)/2
n#p=n-sum[n+1..n+p]


Title: Simple integer operation calculator

Body:
Implement a simple integer operation scriptable calculator.

Concept

The accumulator starts at 0 and has operations performed on it. At the end of the program output the value of the accumulator.

Operations:

+ adds 1 to the accumulator

- subtracts 1 from the accumulator

* multiplies the accumulator by 2

/ divides the accumulator by 2

Sample script

The input ++**--/ should give the output 3.

Example implementation

```<code>def calc(s)
    i = 0
    s.chars.each do |o|
        case o
            when '+'
                i += 1
            when '-'
                i -= 1
            when '*'
                i *= 2
            when '/'
                i /= 2
        end
    end
    return i
end
</code>```

Rules

This is code-golf, so lowest answer in bytes wins, but is not selected.

Creative implementations are encouraged.

Standard loopholes are prohibited.

You get the program via stdin or arguments, and you can output the answer via return value or stdout.

Have fun.

Division truncates down because it is integer division.

The program -/ returns -1.

Test cases

```<code>*///*-*+-+
-1
/*+/*+++/*///*/+-+//*+-+-/----*-*-+++*+**+/*--///+*-/+//*//-+++--++/-**--/+--/*-/+*//*+-*-*/*+*+/+*-
-17
+++-+--/-*/---++/-+*-//+/++-*--+*+/*/*/++--++-+//++--*/***-*+++--+-*//-*/+*/+-*++**+--*/*//-*--**-/-*+**-/*-**/*+*-*/--+/+/+//-+*/---///+**////-*//+-+-/+--/**///*+//+++/+*++**++//**+**+-*/+/*/*++-/+**+--+*++++/-*-/*+--/++*/-++/-**++++/-/+/--*/-/+---**//*///-//*+-*----+//--/-/+*/-+++-+*-*+*+-/-//*-//+/*-+//+/+/*-/-/+//+**/-****/-**-//+/+-+/*-+*++*/-/++*/-//*--+*--/-+-+/+/**/-***+/-/++-++*+*-+*+*-+-//+/-++*+/*//*-+/+*/-+/-/*/-/-+*+**/*//*+/+---+*+++*+/+-**/-+-/+*---/-*+/-++*//*/-+-*+--**/-////*/--/*--//-**/*++*+/*+/-+/--**/*-+*+/+-*+*+--*///+-++/+//+*/-+/**--//*/+++/*+*////+-*-//--*+/*/-+**/*//+*+-//+--+*-+/-**-*/+//*+---*+//*/+**/*--/--+/*-*+*++--*+//+*+-++--+-*-*-+--**+/+*-/+*+-/---+-*+-+-/++/+*///*/*-+-*//-+-++/++/*/-++/**--+-////-//+/*//+**/*+-+/+/+///*+*///*-/+/*/-//-*-**//-/-+--+/-*--+-++**++//*--/*++--*-/-///-+/+//--+*//-**-/*-*/+*/-*-*//--++*//-*/++//+/-++-+-*/*-+++**-/-*++++**+-+++-+-***-+//+-/**-+/*+****-*+++*/-*-/***/-/*+/*****++*+/-/-**-+-*-*-++**/*+-/*-+*++-/+/-++*-/*-****-*
18773342
</code>```

Body:
Java 8, 56 bytes

s->s.chars().reduce(0,(r,c)->c<43?r*2:c<46?r+44-c:r>>1);