Random ASCII Art of the Day #5: Diamond Tilings Mash Up Time!

This is instalment #5 of both my Random Golf of the Day and Optimizer's ASCII Art of the Day series. Your submission(s) in this challenge will count towards both leaderboards (which you can find the linked posts). Of course, you may treat this like any other code golf challenge, and answer it without worrying about either series at all.

Hole 5: Diamond Tilings

A regular hexagon can always be tiled with diamonds like so:

We will use an ASCII art representation of these tilings. For a hexagon of side-length 2, there are 20 such tilings:

   ____     ____     ____     ____     ____     ____     ____     ____     ____     ____
  /\_\_\   /\_\_\   /\_\_\   /\_\_\   /_/\_\   /_/\_\   /\_\_\   /_/\_\   /_/\_\   /_/\_\
 /\/\_\_\ /\/_/\_\ /\/_/_/\ /\/_/\_\ /\_\/\_\ /\_\/_/\ /\/_/_/\ /\_\/\_\ /\_\/_/\ /_/\/\_\
 \/\/_/_/ \/\_\/_/ \/\_\_\/ \/_/\/_/ \/\_\/_/ \/\_\_\/ \/_/\_\/ \/_/\/_/ \/_/\_\/ \_\/\/_/
  \/_/_/   \/_/_/   \/_/_/   \_\/_/   \/_/_/   \/_/_/   \_\/_/   \_\/_/   \_\/_/   \_\/_/
   ____     ____     ____     ____     ____     ____     ____     ____     ____     ____
  /_/_/\   /\_\_\   /_/\_\   /_/_/\   /_/\_\   /_/\_\   /_/_/\   /_/_/\   /_/_/\   /_/_/\
 /\_\_\/\ /\/_/_/\ /_/\/_/\ /\_\_\/\ /\_\/_/\ /_/\/_/\ /_/\_\/\ /\_\_\/\ /_/\_\/\ /_/_/\/\
 \/\_\_\/ \/_/_/\/ \_\/\_\/ \/_/\_\/ \/_/_/\/ \_\/_/\/ \_\/\_\/ \/_/_/\/ \_\/_/\/ \_\_\/\/
  \/_/_/   \_\_\/   \_\/_/   \_\/_/   \_\_\/   \_\_\/   \_\/_/   \_\_\/   \_\_\/   \_\_\/

Given a side length N, you should generate such a tiling for a hexagon of side length N at random. The exact distribution doesn't matter, but each tiling must be returned with non-zero probability.

For N ≤ 4, your submission must produce a tiling within 1 minute at least 80% of the time and at least 80% of the tilings must potentially be generated within 1 minute. Most approaches won't have to worry about this rule (it's very lenient) - this is just to rule out very naive rejection-based algorithms that generate arbitrary strings until one happens to be a tiling.

You might like to know that the total number of possible tilings for given N can be found in OEIS A008793.

You may write a full program or a function and take input via STDIN (or closest alternative), command-line argument or function argument and produce output via STDOUT (or closest alternative), function return value or function (out) parameter.

You must not output more leading spaces than necessary to align the hexagon (that is the left corner of the hexagon should have no spaces in front of it). Each line may contain up to N trailing spaces (not necessarily consistently, so you could e.g. have a rectangular output, printing the hexagon's bounding box).

This is code golf, so the shortest submission (in bytes) wins. And of course, the shortest submission per user will also enter into the overall leaderboard of the series.

Leaderboards

The first post of each series generates a leaderboard.

Random Golf Leaderboard
ASCII Art Leaderboard

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

# Language Name, N bytes

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:

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

(The language is not currently shown, but the snippet does require and parse it, and I may add a by-language leaderboard in the future.)

CJam, 105 bytes

ri:A" __"e*A,2f*:B,[W1]{J+B:):B,{N1$S*"\/"J%A2*4$-:D*
0{;B{_1&!2mr+J*m1e>D(2*e<}%__:)&}g:B{'_t}/+@J+}*}fJ;

Newline added to avoid scrolling. Try it online

Explanation:

This solution starts each line as a zigzag, then places N underscores on it, based on their position on the previous line and a couple of rules. I got this from a series of observations while looking at the output as a plain 2D matrix of characters:

each line has exactly N underscores
the underscores can be replaced with / or \ to make a perfectly repeating zigzag pattern (/\ in the top half, \/ in the bottom half)
underscores can not touch the sides, and can't be adjacent to another underscore
when going to the next line, the position of each underscore changes by -1, 0 or 1
more than that, /_/ can only change by -1 or 0, and \_\ can only change by 0 or 1
for the initial underscore positions we can either use a "_ " pattern or a " _" pattern, both are fine
the above rules are sufficient to obtain all the tilings

So I decided to implement it by keeping the previous underscore positions, modifying them with a random factor (2 choices for each underscore) and repeating until the rules are satisfied. In the process of optimizing, I switched to underscore positions relative to the left side of the hexagon (not including spaces).

ri:A" __"e*       read the input (A) and generate the top line
A,2f*:B           make an array [0 2 4 ... 2A-2] and store in B
                  these are the initial positions for the underscores
,                 B's length = A, used as the initial number of leading spaces
                  let's call it C
[W1]{…}fJ         for J in [-1 1] (top half, bottom half)
  J+              add J to C
  B:):B           increment the underscore positions (adjustment before each half)
  ,{…}*           repeat A times
    N1$S*         add a newline and C spaces
    "\/"J%        take "\/" and reverse it if J=-1 (zigzag pattern)
    A2*4$-:D*     calculate D=A*2-C and repeat the pattern
    0             dummy value (for the next loop)
    {…}g          do-while
      ;B          pop last value and push B
      {…}%        apply block to each item (say x)
        _1&!      duplicate x and calculate !(x&1) (for /_/ vs \_\)
        2mr+      randomly add 0 or 1
        J*m       multiply by J and subtract from x
        1e>       limit the minimum value to 1
        D(2*e<    and the maximum value to 2*(D-1)
      __:)&       check if the modified array has any adjacent values
    :B            store the new positions in B
    {'_t}/        place underscores over the zigzag pattern
    +@J+          bring C to the top and add J to it
;                 pop C

Old "3D" version, 189 bytes:

ri:A" __"e*aA4*S*aA2**+[0-2XXW1]:C;"/\_\\\/_/":D;A3m*{{C2/.f*:.+~
A(2*+:V;A+:U;2{UI+1$1$=4{_V+D4/I=@=t}/t}fI}:F~}/[0Y1WWW]:C;
"/_/\\\_\/":D;AaA*:B;A{A[_{_BI=e<)mr}fI]:B;{BQ={[PQR]F}fR}fQ}fPN*

Try it online


Reduce and generalize a list of string The goal of this challenge is to reduce a list of string to a shorter more general list of string.

Input

The Input is provided with space between the string (a b c) or in list form (["a","b", "c"]). It's a list list of string that can be of the following form :

aaa
aaaX
aaaX/Y

With aaa any set of non capital alphabetic letter, and X or Y any digit between 0 and 9.

Ouput

A list of generalized string that can be separated by anything. String are of the form :

aaa
aaaX
aaaX/Y

With aaa any set of non capital alphabetic letter that were in the input list. X and Y stay the same and symbolise the digit. The goal of the challenge is to reduce the input list of string into their generic representation.

Examples

Two strings can be reduced :

Input : regex1 regex2 split1/0
Output : regexX splitX/Y

Full example :

Input : toto toto titi titi1 titi2 titi5 tutu tutu0 tutu1 tutu1/2 tutu0/1
Output : toto titi titiX tutu tutuX tutuX/Y

Another example :

Input: ["foo0","bar0","baz0/0","eth0/0","eth0/1","eth1/0","eth1/1","vlan8","modem0"]

Output: ["fooX","barX","bazX/Y","ethX/Y","vlanX","modemX"]

Scoring

This is code-golf; shortest code in bytes wins.

Retina, 25 18 13 bytes

6 byte thanks to FryAmTheEggman, and for inspiration of extra 1 byte.

\d
X
/X
/Y
D`

Try it online!


Chained Binary Operations Chained Binary Operations

Here's a challenge involving truth tables and binary operations. For this specific challenge, your task is to use the following table of operations:

To create a function that takes in two inputs f(p,a), where p is the initial truthy/falsy value and a is a list of tuples representing multiple values of q and the operations to be performed. For instance, f(T,[[T,0],[T,1]]) would return ContradictionOP(T,T)=F. You would then chain the output of this result into the next operation, which would be LogicalNOR(F,T)=F, where the 2nd p is the previous output of F. The final result being false. A better breakdown of what each operation actually is is described below:

The first part should be rather simplistic in nature, as the operators are arranged in an increasing binary pattern (hint, hint). However, recursing through the additional inputs to chain binary operations is probably the harder part to accomplish.

Examples:

f(T,[])=T
f(F,[[F,15]])=T
f(T,[[F,15],[T,0],[F,6]])=F
f(T,[[F,15],[F,14],[F,13],[F,12],[F,11]])=F

Extrapolated Example:

f(T,[[F,15],[F,14],[F,13],[F,12],[F,11]])=F
[T,[F,15]]=T*
[T*,[F,14]=T*
[T*,[F,13]=T*
[T*,[F,12]=T*
[T*,[F,11]=F
FALSE.

Rules:

You MUST use the order specified for the operations as stated above.
The input format for a can be a 2D array, array of tuples, command line pairwise arguments or any other representation of pairs of boolean/operations. Could even be a single array that you parse pairwise.
You may use 0 for false and 1 for true, it is not acceptable to reverse the two.
The output should be simply a truthy or falsy value.
No loopholes, this is code-golf, standard CG rules apply.

Example Single Iteration Algorithm:

f={
    p,q,o->
    op=Integer.toBinaryString(o);     // Calculate the binary OP string (15=1111)
    binaryIndex="$p$q"                // Calculate binary combination of p/q (T/F=10)
    i=Integer.parseInt(binaryIndex,2) // Convert to decimal index (T/F=2)
    op.charAt(i)                      // Get the binary char at the calculated index (T/F/15=1).
}
f(1,0,15)                             // "1"

JavaScript (ES6), 34 bytes

a=>a.reduce((l,[r,o])=>o>>l+l+r&1)

Accepts true/false but prefers 1/0 format.


Count the number of ones in an unsigned 16-bit integer Write some statement(s) which will count the number of ones in an unsigned sixteen-bit integer.

For example, if the input is 1337, then the result is 6 because 1337 as a sixteen bit binary number is 0000010100111001, which contains six ones.

80386 Machine Code, 4 bytes

F3 0F B8 C1

which takes the integer in cx and outputs the count in ax, and is equivalent to:

popcnt ax, cx     ; F3 0F B8 C1

And here is an 11 10 byte solution not using POPCNT:

31 C0 D1 E9 10 E0 85 C9 75 F8

which is equivalent to:

xor ax, ax        ; 31 C0   Set ax to 0
shr cx, 1         ; D1 E9   Shift cx to the right by 1 (cx >> 1)
adc al, ah        ; 10 E0   al += (ah = 0) + (cf = rightmost bit before shifting)
test cx, cx       ; 85 C9   Check if cx == 0
jnz $-6           ; 75 F8   Jump up to shr cx, 1 if not


Recursive Mathematical Puzzle from a high school contest The problem appeared on the 2013 SJCNY High School Programming Contest. It was the last question in the set of problems and no team produced a correct answer during the 2.5 hours they had to work on it. Shortest solution that can handle the full range of inputs with a reasonable run time (say under 2 minutes on a Pentium i5) wins.

Vases

Ryan’s mom gave him a vase with a cherished inscription on it, which he often places on his
window ledge. He is moving into a high rise apartment complex and wants to make sure that if the vase falls off the ledge, it won’t break. So he plans to purchase several identical vases and drop them out of the window to determine the highest floor he can live on without the vase breaking should it fall off the window ledge. Time is short, so Ryan would like to minimize the number of drops he has to make.

Suppose that one vase was purchased and the building was 100 stories. If it was dropped out of the first floor window and broke, Ryan would live on the first floor. However if it did not break, it would have to be dropped from all subsequent floors until it broke. So the worst case minimum number of drops for one vase (V=1) and an N story building is always N drops. It turns out that if Ryan’s drop scheme is used, the worst case minimum number of drops falls off rapidly as the number of vases increases. For example, only 14 drops are required (worst case) for a 100 story building if two (V = 2) vases are used, and the worst case number of drops decreases to 9 if three vases are used.

Your task is to discover the optimum drop algorithm, and then code it into a program to
determine the minimum number of drops (worst case) given the number of vases Ryan purchased, V, and the number of floors in the building, N. Assume that if a vase is dropped and it does not break, it can be reused.

Inputs: (from a text file)
The first line of input contains the number of cases to consider. This will be followed by one line of input per case. Each line will contain two integers: the number of vases Ryan purchased, V, followed by the number of stories in the building, N. N < 1500 and V < 200

Output: (to console)
There will be one line of output per case, which will contain the minimum number of drops, worst case.

Sample Input

   5
   2 10
   2 100
   3 100
   25 900
   5 100

Sample Output  (1 for each input)

    4
    14
    9
    10
    7

I solved this in excel, as my work machine doesn't have any languages on it. obviously the input/output part doesn't quite match the question... so psuedocode answer :

Setup

Array Heights[200][1500]

for v = 1 to 200
  Heights[v][1] = 1
for d = 1 to 1500
  Heights[1][d] = d
for d = 2 to 200
  for d = 2 to 1500
    Heights[v][d] = Heights[v-1][d-1] + Heights[v][d-1] + 1

'Heights' now contains all the answers within range. (sort of)

Solutions

for each input (V,N) :
d = 1
while (d <= 1500) and (Heights[V][d] < N)
  d++
print d

A few notes:

if speed is vital the search in the 'solution' part can be replaced with a binary search
because of the 1500 limit on floors, you never need to consider more than 11 vases. (in fact if V > log2(N+1), then answer is just round up log2(N+1) )  ((ie binary vase drop search))
There is slight ambiguity in the question regarding the first floor. It says 'if it breaks on the 1st floor, he will live on the 1st floor' which leads to 'if it breaks on the 2nd floor, he will live on the 1st floor regardless of whether or not it breaks on the 1st'...


Determining the continued fractions of square roots The continued fraction of a number n is a fraction of the following form:

which converges to n.

The sequence a in a continued fraction is typically written as: [a0; a1, a2, a3, ... an].
We will write ours in the same fashion, but with the repeating part between semicolons.

Your goal is to return the continued fraction of the square root of n.
Input: An integer, n. n will never be a perfect square.
Output: The continued fraction of sqrt(n).

Test Cases:
2 -> [1; 2;]
3 -> [1; 1, 2;]
19 -> [4; 2, 1, 3, 1, 2, 8;]

Shortest code wins. Good luck!

GolfScript (66 60 chars)

~:^,{.*^>}?(:?';'[1?{^1$.*-@/?@+.2$/@@1$%?\- 1$(}do;;]','*1$

Warning: most of the ? in there are the variable representing floor(sqrt(input)) rather than the builtin. But the first one is the builtin.

Takes input on stdin and outputs to stdout.

Psuedocode of the algorithm (proof of correctness currently left as an exercise for the reader):

n := input()
m := floor(sqrt(n))
output(m)
x := 1
y := m
do
  x := (n - y * y) / x
  output((m + y) / x)
  y := m - (m + y) % x
while (x > 1)

Yet again I find myself wanting a single operator which takes a b on the stack and leaves a/b a%b on the stack.


579085261 is CRAZY, 725582 is GOLF, 10757494 is ...? Your task is to translate a 103-smooth number into an English word, using the method described below.

How?

Generate the list of prime factors (with repetition) of the input number.
Sort the list:

If 2 is not one of the prime factors, sort the list in ascending order.
If 2 is one of the prime factors, remove it from the list and sort the remaining factors in descending order.

Translate each factor into a letter, using the following table:

 3 = S   13 = L   29 = X   43 = O   61 = Z   79 = H  101 = K
 5 = P   17 = Q   31 = N   47 = R   67 = T   83 = V  103 = Y
 7 = M   19 = U   37 = C   53 = A   71 = E   89 = D
11 = F   23 = I   41 = W   59 = G   73 = J   97 = B

Note: This table was built empirically to maximize the number of possible words. For the curious, here is a list of 2,187 words that can be encoded that way (may include rude language). It's definitely not guaranteed to be optimal, but it's good enough for this challenge.

Examples

Example 1: 579085261 (ascending order)

The prime factors are [ 37, 47, 53, 61, 103 ].
2 is not a prime factor, so we keep the list sorted in ascending order.
37 = C, 47 = R, etc. The output is "CRAZY".

Example 2: 725582 (descending order)

The prime factors are [ 2, 11, 13, 43, 59 ].
2 is a prime factor, so we remove it and sort the list in descending order, which gives:
[ 59, 43, 13, 11 ].
59 = G, 43 = O, etc. The output is "GOLF".

Example 3: 10757494 (with a repeated factor)

The prime factors are [ 2, 11, 71, 71, 97 ].
2 is a prime factor, so we remove it and sort the list in descending order, which gives:
[ 97, 71, 71, 11 ].
97 = B, 71 = E, 11 = F. The output is "BEEF".

Clarifications and rules

The input number is guaranteed to be 103-smooth and divisible by 2 at most once.
By definition, a smooth-number is a positive integer.
Input and output can be handled in any reasonable format. The output can be in lowercase or uppercase. Trailing whitespace is acceptable. Leading whitespace is not.
If your program/function can't support large inputs, please specify it in your answer.
This is code golf, so the shortest answer in bytes wins.

Test cases

34874          --> ARM
483254         --> BAR
353722         --> EAR
494302         --> EGG
39061          --> FAT
6479           --> FUN
60421          --> ICE
54166          --> JAM
48911474       --> BETA
2510942        --> BOOM
2303854        --> DOOM
844261         --> FIRE
1606801        --> MAZE
1110085        --> PAGE
5212974        --> BALLS
67892046       --> BEANS
885396199      --> CREEK
67401037       --> FUNKY
27762173       --> QUICK
1238440506     --> ARROWS
33045832681    --> CRAGGY
1362714005     --> PIRATE
137302698      --> TROLLS
358310128062   --> BEGGARS
40255151586    --> DETAILS
164633248153   --> FIXATED
621172442227   --> UNRATED
2467812606     --> VACUUMS
86385078330    --> GROWNUPS
26607531423091 --> UNWORTHY

Jelly, 29 27 bytes

ÆEµØA“¡3ḅḲ+Ṿɼ¡ẏƙẊƘ’œ?xḊṚḢ}¡

Thanks to @JonathanAllan for golfing off 1 byte!

Try it online!

Background

“¡3ḅḲ+Ṿɼ¡ẏƙẊƘ’

is a numeric literal. The characters between the quotes are replaced with their 1-based indices in the Jelly code page, and the resulting array is interpreted as a base-250 number. This yields the integer c := 288824892868083015619552399.

How it works

ÆEµØA“¡3ḅḲ+Ṿɼ¡ẏƙẊƘ’œ?xḊṚḢ}¡  Main link. Argument: n

ÆE                           Yield the exponents of n's prime factorization, with.
                             zeroes. This yields an array A.
  µ                          Begin a new monadic chain with argument A.
   ØA                        Set the return value to “ABC...XYZ”.
     “¡3ḅḲ+Ṿɼ¡ẏƙẊƘ’œ?        Select the c-th permutation of the alphabet, yielding
                             s := “SPMFLQUIXNCWORAGZTEJHVDBKY”.
                      Ḋ      Dequeue; yield A without its first element, stripping
                             the exponent of 2.
                     x       Repeat the k-th letter of s r times, where r is the
                             exponent of the k-th odd prime number.
                          ¡  Combine the two links to the left into a quicklink:
                        Ḣ}     - Apply head to the right argument (A), yielding the
                                 exponent of 2. Since n is at most divisible by the
                                 first power of 2, this yields 1 for even numbers
                                 and 0 for odd ones. Call the link to the left that
                                 many times on the previous return value.
                       Ṛ       - Reverse the string to the left.


How many decimals are there before I'd need to add 1 when rounding? When you round a number, if the next digit is >= 5 you add 1. For example:

3.1415926535 rounded to 1dp is 3.1
3.1415926535 rounded to 4dp is 3.1416    <-- Note the 5 changed to 6
3.1415926535 rounded to 5dp is 3.14159

3.1415926535 rounded to 9dp is 3.141592654  <-- Note the 3 changed to 4

You challenge is to receive an integer as input and output the number of decimal places before which you would have to round the square root of the number - i.e. the number of decimal places before anumber digit which is >= 5 occurs.

The integer will be between 0 and 100,000 inclusive so for the edge case of 59752 you need to support 17 decimal points (to check the 17th).

If you programming language can't change the number of decimal points, you can display a "?" message to the user.

Example:

Input    Root                     Output

    5 -> 2.23 606797749979     -> 2
   41 -> 6.40312423 743284     -> 8      (Largest gap under 100)
  596 -> 24.4131112314 674     -> 10     (Largest gap under 1000)
59752 -> 244.44222221212112029 -> 16     (Largest gap under 100000)

Do what you want on perfect squares.

This is code-golf so shortest code wins.

For anyone interested, the number 310,617 is the biggest under 1,000,000 and has 18 before you reach a digit >= 5.

CJam, 17 bytes

rie40mQsJ~>'4f>1#

Try it online.


Reflections in Water Take a string as input. This string can be as long as you'd like, however, it may only include letters and spaces––no numbers, punctuation, etc. When a word is passed into your function, an image will be made out of it. This image is the input word written out using only these characters: –, /, \, and |. You do not need to use all of these characters, but you may not use any others. Only words are inputed; no numbers or any other characters.

Here are a couple examples:

Input : "String"

Return :

 –––    –––    –––   –––  |\    |   –––
|        |    |   |   |   | \   |  |
 –––     |    |–––    |   |  \  |  | ––
    |    |    |   \   |   |   \ |  |   |
 –––     |    |    \ –––  |    \|   –––     //uppercase string written out
––––––––––––––––––––––––––––––––––––––––    //bar
                                            //line break
 –––     |    |    / –––  |    /|   –––
    |    |    |   /   |   |   / |  |   |
 –––     |    |–––    |   |  /  |  | ––
|        |    |   |   |   | /   |  |
 –––    –––    –––   –––  |/    |   –––     //uppercase string written upside-down (reflected)

After the all caps string written out, there is a bar and then a line break. After that, there is the same string, just mirrored/upside-down. The bar under the word spelled out should be the length of the written out string. The upside down word––the reflection––goes one line beneath the line break.

Here is another example:

Input : "hi"

Return :

|  |  –––
|  |   |
|––|   |
|  |   |
|  |  –––
–––––––––

|  |  –––
|  |   |
|––|   |
|  |   |
|  |  -––

A bonus challenge/addition:

Add a ripple effect. Have something like a random indent between 0 and 3 spaces before each line in the reflection. Here's an example of what it could look like:

Input : "hi"

Return :

|  |  –––
|  |   |
|––|   |
|  |   |
|  |  –––
–––––––––

 |  |  –––
 |  |   |
  |––|   |
 |  |   |
  |  |  -––

Your code should be in the following form:

function createAwesomeness(string) -> string {
    let s = //your code that creates the 'image'
    return s
}

print createAwesomeness("string")
print createAwesomeness("bananas")

A couple notes:

Every language is valid
Suggestion: Do not copy the font-set as a dictionary or array because that adds a lot to your code's size. Both as a challenge and to lower your code's size, try to use a function of sorts to create the letters
Along with your code, have:

The size in bytes of your function
The number of characters of your function
The two examples

Shortest, working code wins
There is currently no deadline

If any further explanation is needed, please tell me in the comments!

Any response is welcome and greatly appreciated!


Implementing Binary Arithmetic Given two binary numbers (strings containing 0s and 1s), perform operations on them, with one problem: You must keep them in binary. That means no going binary(integer(n1)+integer(n2)) or anything like that.

Input: Two binary numbers, n1 and n2, and a number between 0 and 3, o, defining the operator. The two binary numbers will be the same length.

Output:
If o is 0, return n1+n2 as a binary number.
If o is 1, return n1-n2 as a binary number.
If o is 2, return n1*n2 as a binary number.
If o is 3, return n1/n2 as a binary number, using floor division.
The output will not be the same length as the input. Please truncate all leading zeros.

If you implement Two's Complement, subtract 10% off your character count, up to a limit of 50. Truncate to length(n1)+length(n2) digits.

Test Cases:
n1=01010, n2=10101, o=0: 11111
n1=11110, n2=01010, o=1: 10100
n1=0010, n2=1000, o=2: 10000
n1=1011010, n2=0010001, o=3: 101

Shortest code wins. Good luck!

Python, 429 chars - 10% bonus = 386.1

Numbers are kept in little endian order, which is stretching the rules a bit but makes for easier processing.  Maximum number size is 32 bits.  Addition is standard, subtraction is implemented by x-y = x+~y+1 (throwing away the carry out of the 32 bits), multiplication is done using the Russian Peasant algorithm, and division is done with repeated subtraction.

z,i='01'
P=z*32
def A(x,y):
 r='';c=z
 for a,b in zip(x+P,y+P):k=(a+b+c).count(i);r+='0101'[k];c='0011'[k]
 return r[:32]
S=lambda x,y:A(A(x,''.join(chr(ord(c)^1)for c in y+P)),i)
def M(x,y):
 r=''
 while y:
  if y[0]==i:r=A(r,x)
  x=z+x;y=y[1:]
 return r
def D(x,y):
 x=(x+P)[:32];y=(y+P)[:32];r=''
 while x[::-1]>=y[::-1]:r=A(r,i);x=S(x,y)
 return r
def B(x,y,o):r=[A,S,M,D][o](x,y).rstrip(z)[:len(x)+len(y)];return[r,z][r=='']

B is the function of interest, here is its result on the test cases:

print B('01010','10101',0)
11111
print B('01111','01010',1)
00101
print B('0100','0001',2)
00001
print B('0101101','1000100',3)
101


Shortest code for Seven-Eleven The Seven-Eleven problem is find 4 positive numbers (with two decimal digits, A.BC) such that their sum is equal to their product and is equal to 7.11.

a + b + c + d = a * b * c * d = 7.11
0 < a <= b <= c <= d

Write the shortest program to compute all non-decreasing quadruples. Precomputing the values is not allowed.

Ruby, 105 characters
Unfortunately I didn't get it below the 100 mark. It just brute forces all possible tuples and checks afterwards. Nevertheless it still finishes in finite time.
(1..m=711).map{|a|(a..m).map{|b|(b..m).map{|c|d=m-a-b-c;p [a/u=1e2,b/u,c/u,d/u]if d>=c&&a*b*c*d==m*1e6}}}

The formatted version looks like this:
(1..m=711).map{ |a|
  (a..m).map{ |b|
    (b..m).map{ |c|
      d=m-a-b-c
      p [a/u=1e2,b/u,c/u,d/u] if d>=c && a*b*c*d==m*1e6
    }
  }
}


Addition-Subtraction of Numbers Within String Take a string as an input, and perform addition/subtraction of all the digits in the string and output the sum of those operations as the result.

Rules

The digits in the string are read from left to right
If a digit (n) is odd, perform addition with the next digit (n + n1)
If a digit (n) is even, perform subtraction with the next digit (n - n1)
If you've reached the last digit in the string, perform the operation with the first digit in the string
Output will be the sum of all the resulting values
If there is only one digit in the string, perform the operation with itself (n+n or n-n)
If there are no digits in the string, output is 0

Example

Input: r5e6o9mm!/3708dvc
Process: (5+6) + (6-9) + (9+3) + (3+7) + (7+0) + (0-8) + (8-5)
Output: 32

Notes

Either function or full program is accepted
Maximum input length would depend on your language's limit for a string input
No restrictions on character input, but only half-width digits count towards the output
Fewest bytes wins

Jelly, 17 15 12 bytes

fØDV€ḂT‘ịƲSḤ

Try it online!

Try test cases.

The program keeps only the digits that follow an odd digit then computes twice the sum.

fØDV€ḂT‘ịƲSḤ
f                   Remove anything that isn't...
 ØD                 a digit.
   V€               Cast each digit to an integer
         Ʋ          Monad:
     Ḃ              Parity of each digit.
      T             Indices of truthy elements (odd digits).
       ‘            Increment.
        ị           Index into list of digits.
                    Wraps to beginning and if there are no digits this returns 0.
          S         Sum.
           Ḥ        Double.


Sums of prime factors 2013 has the prime factorization 3*11*61. 2014 has the prime factorization 2*19*53. An interesting property regarding these factorizations is that there exist distinct primes in the factorizations of 2013 and 2014 that sum to the same number: 11+61=19+53=72.

Write a program or function that takes as its input two positive integers greater than 1 and returns a truthy value if there exist a sum of selected prime factors of one number that is equal to a sum of selected prime factors in the second number, and a falsey value otherwise.

Clarifications

More than two prime factors can be used. Not all of the prime factors of the number need to be used in the sum. It is not necessary for the number of primes used from the two numbers to be equal.
Even if a prime is raised to some power greater than 1 in the factorization of a number, it can only be used once in the sum of primes for the number.
1 is not prime.
Both input numbers will be less than 2^32-1.

Test cases

5,6
    5=5
    6=2*3
    5=2+3
==>True

2013,2014
    2013=3*11*61
    2014=2*19*53
    11+61=19+53
==>True

8,15
    8=2^3
    15=3*5
    No possible sum
==>False

21,25
    21=3*7
    25=5^2
    No possible sum (can't do 3+7=5+5 because of exponent)
==>False

This is code golf. Standard rules apply. Shortest code in bytes wins.

Julia, 95 93 bytes

g(x)=reduce(vcat,map(p->map(sum,p),partitions([keys(factor(x))...])))
f(a,b)=g(a)∩g(b)!=[]

The primary function is f and it calls a helper function g.

Ungolfed:

function g(x::Integer)
    # Find the sum of each combination of prime factors of the input
    return reduce(vcat, map(p -> map(sum, p), partitions([keys(factor(x))...])))
end

function f(a::Integer, b::Integer)
    # Determine whether there's a nonzero intersection of the factor
    # sums of a and b
    return !isempty(g(a) ∩ g(b))
end

Saved 2 bytes thanks to Darth Alephalpha


Subtract my odds from my evens Given a non-negative integer, return the absolute difference between the sum of its even digits and the sum of its odd digits.
Default Rules

Standard Loopholes apply.

You can take input and provide output by any standard Input / Output method.

You may take input as a String, as an Integer or as a list of digits.

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

Test Cases

Input ~> Output

0 ~> 0 (|0-0| = 0)
1 ~> 1 (|1-0| = 1)
12 ~> 1 (|2-1| = 1)
333 ~> 9 (|0-(3+3+3)| = 9)
459 ~> 10 (|4-(5+9)| = 10)
2469 ~> 3 (|(2+4+6)-9| = 3)
1234 ~> 2 (|(2+4)-(1+3)| = 2)

Jelly, 6 bytes

-*æ.¹A

Try it online!

How it works

-*æ.¹A  Main link. Argument: A (digit array)

-*      Raise -1 to A's digits, yielding 1 for even digits and -1 for odd ones.
    ¹   Identity; yield A.
  æ.    Take the dot product of the units and the digits.
     A  Apply absolute value.


Compress your code in an image This is a quine variation.
Introduction
We all write short code, because some obscure reasons, but whatever we do, the'll take up at least 144 pixels/byte (with a 12px font). But what would happen, if we would encode our code in images? This is your task today.
Challenge
You task is to read in your own source code (non-proper quines are allowed, e.g. literally reading the source file), and create an image out of it, by setting the red, green and blue components of a pixel based on the ASCII value of the character.
Example:
We have the string "Hello world!"
Hello world!

Let's convert this to ASCII values:
72 101 108 108 111 32 119 111 114 108 100 33

Map the RGB values to it (If the source code's length is not divisible by 3, use 0s as the remaining characters):
 __________________________________________________
| R | G | B || R | G | B || R | G | B || R | G | B |
----------------------------------------------------
|72 |101|108||108|111|32 ||119|111|114||108|100|33 |
----------------------------------------------------

We then create the image with the smallest area out of it. We have 4 sets of RGB values, so the smallest image will be a 2*2 image, going from the top left pixel to the right:

And we get this awfully colored image (resized, so it's at least visible, also proves the fact how small it can get)
Rules/Additional information

There's no input
The output should be as a separate file, or in a separate window.
For multibyte characters, split the character in 2 bytes.
The source code must be at least 1 byte long
The image should be the one from the possible sizes, wich has the closest width/height ratio to 1
The pixel count on the image should exactly be ceil(byte count / 3), no extra pixels should be added

Scoring
This is a code-golf, so the smallest answer in bytes wins.

MATLAB, 81 72 69 bytes
@()image(shiftdim(reshape(evalin('base','char(ans)'),3,1,23)/255,1.))

This creates an anonymous function which can be pasted into the command window and run using ans(). When run this creates a 23-pixel image (a prime) therefore the most square representation is a simple array of pixels.

Explanation
When pasted into the command window, the anonymous function will automatically assign itself to the variable ans. Then from within the anonymous function, we use:
evalin('base', 'char(ans)')

which evaluates char(ans) within the namespace of the command window rather than within the local namespace of the anonymous function. It is therefore able to convert the anonymous function itself into a string representation.
Then we have the following operations which are more straightforward:
%// Reshape the result into a 3 x 1 x 23 matrix where the first dimension is RGB
%// due to column-major ordering of MATLAB
R = reshape(string, 3, 1, 23);

%// Divide the result by 255. This implicitly converts the char to a double
%// and in order for RGB interpreted properly by MATLAB, doubles must be
%// normalized between 0 and 1.
R = R / 255;

%// Shift the dimensions to the left 1 to move the RGB channel values into
%// the third dimension. Note the extra decimal point. This is because it
%// is far shorter to lengthen the code by one byte than to pad the string
%// to give us a length divisible by 3
R = shiftdim(R, 1.);

%// Display the RGB image
image(R);


Is this number an integer power of -2? There are clever ways of determining whether a number is a power of 2.  That's no longer an interesting problem, so let's determine whether a given integer is an integer power of -2.  For example:

-2 => yes: (-2)¹
-1 => no
0 => no
1 => yes: (-2)⁰
2 => no
3 => no
4 => yes: (-2)²

Rules

You may write a program or a function and use any of the standard methods of receiving input and providing output.
Your input is a single integer, and output must be a truthy value if the integer is an integer power of -2, and a falsy value otherwise.  No other output (e.g. warning messages) is permitted.
The usual integer overflow rules apply: your solution must be able to work for arbitrarily large integers in a hypothetical (or perhaps real) version of your language in which all integers are unbounded by default, but if your program fails in practice due to the implementation not supporting integers that large, that doesn't invalidate the solution.
You may use any programming language, but note that these loopholes are forbidden by default.

Winning condition

This is a code-golf contest: the answer which has the fewest bytes (in your chosen encoding) is the winner.

Mathematica, 22 bytes

EvenQ@Log2@Max[#,-2#]&

Try it online! (Using Mathics instead, where this solution also works.)

I tried to find a solution with bitwise operators for a while, and while one definitely exists, I ended up finding something which is probably simpler:

Max[#,-2#] multiplies the input by -2 if it's negative. Multiplying by another factor of -2 doesn't change whether the value is a power of -2 or not. But now all odd powers of -2 have been turned into even powers of -2.
But even powers of -2 are also even powers of 2, so we can use a simple Log2@... and check if the result is an integer (to check whether it's a power of 2). This already saves two bytes over Log[4,...] (another way to look at even powers of -2).
As an added bonus, checking whether a value is an even integer is shorter than just checking whether it's an integer: we can save three more bytes by using EvenQ instead of IntegerQ.


Replace twos with threes Given a positive integer n write some code to take its prime factorization and replace all of its factors of 2 with 3.

For example

12 = 2 * 2 * 3 -> 3 * 3 * 3 = 27

This is code-golf so the goal is to minimize the byte count of your answer.

Test cases

1 -> 1
2 -> 3
3 -> 3
4 -> 9
5 -> 5
6 -> 9
7 -> 7
8 -> 27
9 -> 9
10 -> 15
11 -> 11
12 -> 27
13 -> 13
14 -> 21
15 -> 15
16 -> 81
17 -> 17
18 -> 27
19 -> 19
20 -> 45
21 -> 21
22 -> 33
23 -> 23
24 -> 81
25 -> 25
26 -> 39
27 -> 27
28 -> 63
29 -> 29

Fractran, 3 bytes

3/2

Fractran literally only has one builtin, but it happens to do exactly what this task is asking for. (It's also Turing-complete, by itself.)

The language doesn't really have a standardised syntax or interpreter. This interpreter (in a comment to a blog post –
 it's a very simple language) will accept the syntax shown here. (There are other Fractran interpreters with other syntaxes, e.g. some would write this program as 3 2, or even using 3 and 2 as command line arguments, which would lead to a score of 0+3 bytes. I doubt it's possible to do better than 3 in a pre-existing interpreter, though.)

Explanation

3/2
 /   Replace a factor of
  2  2
3    with 3
     {implicit: repeat until no more replacements are possible}


What's the Language? Recently, the PPCG design leaderboard has been having some trouble parsing answer html headers.

In this challenge you'll be taking your own shot at parsing answer headers.

Example Test Cases

These example inputs (NOT actual test cases), just so you can get the idea of how inputs might be like

Input:
Python 3, 32 bytes

Desired Output: Python 3

Input:
JavaScript, 13 chars / 32 bytes

Desired Output: JavaScript

Input: VeryBadlyFormattedHeader v3 : (32 bytes)

Spec

Your program should be 150 bytes or below

You will be given a line of an answer header's html, you'll need to try to do your best to successfully extract the language. Input may contain unicode characters.

Output case matters.

Tests

Github Gist with test cases

There is one test case per line. The format is:

<lang_name> - <rest_of_the_line_is_the_header>

Scoring

Your score is:

 Number Correct
----------------
  Total Number

(which is a percent)

Tie-breaker is shortest code.

Bash, 100%, 100 bytes

sed sX..s.2./s.XX|grep -Po '(?<=>)[^<]+?(?=(,(?! W)| [-&–5]| ?<| [0-79]\d| ?\((?!E|1\.)))'|head -1

Try it online on Ideone.

Verification

$ wget -q https://gist.githubusercontent.com/vihanb/1d99599b50c82d4a6d7f/raw/cd8225de96e9920db93613198b012749f9763e3c/testcases
$ grep -Po '(?<= - ).*' < testcases > input
$ grep -Po '^.*?(?= - )' < testcases > output
$ while read line; do bash headers.sh <<< "$line"; done < input | diff -s - output
Files - and output are identical


Let's play some boardgame! Introduction

Boardgames are a classic play between kids, but there are some kids that feel bored playing a boardgame step by step. Now they want the result to be shown before they put their hands on the board.

Challenge

Suppose this boardgame: >---#<---X---<X<--#-$

>   means the start of the game
-   means a position without danger
<   means the player should return one step back
X   means the player won't move next round
#   means a portal where the player returns to the start position
$   the first player to get there or after there wins the game

The input consists of a string with the boardgame's aspects described above and two arrays with some values (from 1 to 6) in order that both players (kid A and kid B) had got when playing one cube.

Both arrays will always have the same length >= 1.

The kid A always start the game.

You must output the kid which got the end or closer to the end first.

If neither one got the end and both kids stay at the same position print 0 or any other falsy value.

If one array runs out while the other has remaining dice rolls (due to one player missing several turns on Xs), the remaining dice rolls should be used up.

For this task, you can create a program/function, that reads input from stdin, or take parameters/arguments and output/return/print the winner kid.

Since this is code-golf, shortest answer in bytes wins!

Example Input and Output

You can also use diferrent formats of input, but you should only take the boardgame, the kid-A and the kid-B values.

Example 1:

board:  >---#<---X---<X<--#-$
kid-A:  [3,6,6,5,2,1]
kid-B:  [4,5,3,5,5,5]

output: A

Explaining:

>---#<---X---<X<--#-$     # both kids in position
B--A#<---X---<X<--#-$     # kid-A moved 3 to -
B--A#<---X---<X<--#-$     # kid-B moved 4 to # and returned home
B---#<---A---<X<--#-$     # kid-A moved 6 to X and will wait one round
B---#<---A---<X<--#-$     # kid-B moved 5 to < returned one to # and returned home
>--B#<---A---<X<--#-$     # kid-B moved 3 to -
>--B#<---X---<A<--#-$     # kid-A moved 6 to < returned one to X and will wait again
>---#<--BX---<A<--#-$     # kid-B moved 5 to -
>---#<---X--B<A<--#-$     # kid-B moved 5 to < returned one to -
>---#<---X--B<X<--#A$     # kid-A moved 5 to -
>---#<---X---<X<-B#A$     # kid-B moved 5 to -
>---#<---X---<X<-B#-$A    # kid-A moved 2 and won the game!

Example 2:

board:  >-<<<<<$
kid-A:  [1,2,3]
kid-B:  [5,5,4]

output: 0

Example 3:

board:  >-<-<#<-<-<-$
kid-A:  [5,4,2]
kid-B:  [1,1,1]

output: B

Explaining:

>-<-<#<-<-<-$     # both kids in position
>-<-<#<-<-<-$     # kid-A moved 5 to # returned home
AB<-<#<-<-<-$     # kid-B moved 1 to -
>B<A<#<-<-<-$     # kid-A moved 4 to < returned one to -
>B<A<#<-<-<-$     # kid-B moved 1 to < returned one to -
AB<-<#<-<-<-$     # kid-A moved 2 to # returned home
AB<-<#<-<-<-$     # kid-B moved 1 to < returned one to -

Current position: (A:0, B:1) output: B

Perl, 188 180 + 2 = 182 bytes

Wuhuu, got to use goto.

@q=/.(?!$)/g,next if$w=$e=!@q;for(@F){a:$w+=$_;$_=$q[$w];/</?($_=-1,goto a):/X/?$e++:/#/?$w=0:!$_&&last;$e++}$r+=$"lt$r?-$w:$w;$t+=$"lt$t?-$e:$e-1}{say$w>@q?$t<0?B:A:!$r?0:$r<0?B:A

Requires -a and -E|-M5.010:

$ echo $'>-<-<#<-<-<-<-$\n5 4 2\n1 1 1' | perl -M5.010 boardgame.pl
B

Somewhat ungolfed version:

#!/usr/bin/perl -a

# Read all but last char from the board into an array
@board = /.(?!$)/g,next if $pos = $turns = !@board;
for (@F) {
    a:
    $pos+=$_;
    $_=$board[$pos];
    /</?($_=-1,goto a):
    /X/?$turns++:
    /#/?$pos=0:
    # End of Game (Victory!)
    !$_&&last;

    $turns++
}
# Make sure '$pos_diff' and '$turns_diff' are not zero by checking against [:space:]
# ' ' is less than 0 on the ascii table
$pos_diff += $"lt$pos_diff ? -$pos : $pos;
$turns_diff += $"lt$turns_diff ? -$turns : $turns-1;
}{
    say $pos>@board?
            $turns_diff<0?B
            :A
        :
        !$pos_diff?0:
        $pos_diff<0?B:
        A


Find the maximum flow Given a directed network, with a single source and a single sink, it is possible to find the maximum flow through this network, from source to sink. For example, take the below network, \$G\$:

Here, the source is node 0 and the sink 5. We can see, from the minimum cut-maximum flow  theorem, that the maximum flow through this network is \$70\$ (given by the cut \$\{0\} / \{1, 2, 3, 4, 5\}\$)
Minimum cut-maximum flow theorem
For a network, a cut is a line that divides a network in two, with the sink and source in different halves. For the above network, one such cut, \$C\$, is \$\{0, 1, 3\} / \{2, 4, 5\}\$. Every cut has a value, which depends on which edges in the network is passes through. The above cut, \$C\$, passes through the edges \$1-2, 3-2\$ and \$3-4\$, which have the weights \$40, 45\$ and \$30\$ respectively. The value of a cut is defined, for the set of crossed edges \$S\$, as

The sum of the weights of all the edges in \$S\$ which pass from the source to the sink

Therefore, the value of \$C\$ is \$40 + 45 + 30 = 115\$ but the value of the cut \$\{0, 3\} / \{1, 2, 4, 5\}\$ would be \$20 + 45 + 30 = 95\$ (Note that \$10\$ is not included as it passes from the sink towards the source).
The minimum cut-maximum flow theorem states that

The maximum flow through a network is equal to the minimum value of all cuts in that network

The minimum cut of all the cuts in \$G\$ is \$\{0\} / \{1, 2, 3, 4, 5\}\$ which has a value of \$70\$. Therefore, the maximum flow through \$G\$ is also \$70\$.
Challenge
Write a function of full program that, when given a directed network as input, outputs the maximum flow through that network. You may, of course, use any method or algorithm to compute the maximum flow, not just the minimum cut-maximum flow theorem. This was simply included as one method.
You may take input in any convenient method or format, such as an adjacency matrix, a list of nodes and edges, etc. The input will always have 2 or more nodes, will be a connected graph, and will have exactly 1 source and 1 sink. The weights of the edges will always be natural numbers, as will the maximum flow. The output should reflect this, and can also be in any convenient method or format.
This is code-golf, so the shortest code, in bytes, wins.
Test cases
Both the network and the adjacency matrix are included for each test case.
Network \$G\$ (above):
[[ 0, 20,  0, 50,  0,  0],
 [ 0,  0, 40, 10,  0,  0],
 [ 0,  0,  0,  0, 25, 25],
 [ 0,  0, 45,  0, 30,  0],
 [ 0,  0,  0,  0,  0, 50],
 [ 0,  0,  0,  0,  0,  0]] -> 70 ({0} / {1, 2, 3, 4, 5})

[[ 0, 10, 17,  0,  0,  0,  0],
 [ 0,  0,  0,  2, 13,  0,  0],
 [ 0,  5,  0,  0,  4,  8,  0],
 [ 0,  0,  0,  0,  0,  0, 20],
 [ 0,  0,  0, 18,  0,  0,  0],
 [ 0,  0,  0,  0,  1,  0,  7],
 [ 0,  0,  0,  0,  0,  0,  0]] -> 27 (Multiple cuts e.g. {0, 1, 2} / {3, 4, 5, 6})

[[ 0,  6,  2,  7,  4,  0,  0,  0],
 [ 0,  0,  0,  0,  0, 10,  0,  0],
 [ 0,  8,  0,  0,  0,  0,  9,  4],
 [ 0,  0, 11,  0,  0,  0,  0,  0],
 [ 0,  0,  0,  5,  0,  0,  0,  0],
 [ 0,  0, 13,  0,  0,  0,  0, 16],
 [ 0,  0,  0, 14,  0,  0,  0, 12],
 [ 0,  0,  0,  0,  0,  0,  0,  0]] -> 19 ({0} / {1, 2, 3, 4, 5, 6, 7})

[[ 0, 40, 50,  0,  0,  0,  0,  0,  0],
 [ 0,  0,  0, 30, 10,  0,  0,  0,  0],
 [ 0,  0,  0, 40,  0,  0, 10,  0,  0],
 [ 0,  0,  0,  0, 15, 10,  0,  0,  0],
 [ 0,  0,  0,  0,  0,  0,  0,  0, 20],
 [ 0,  0,  0,  0,  0,  0, 15, 20,  0],
 [ 0,  0,  0,  0,  0,  0,  0, 30,  0],
 [ 0,  0,  0,  0,  0,  0,  0,  0, 50],
 [ 0,  0,  0,  0,  0,  0,  0,  0,  0]] -> 40 ({0, 1, 2, 3, 4} / {5, 6, 7, 8})

[[ 0, 5, 8, 3, 3, 7, 0, 0, 0, 7],
 [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 4],
 [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 9],
 [ 0, 0, 0, 0, 0, 0, 1, 0, 0, 0],
 [ 0, 0, 0, 0, 0, 0, 0, 4, 0, 0],
 [ 0, 0, 0, 0, 0, 0, 0, 0, 6, 0],
 [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
 [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 6],
 [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 5],
 [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]] -> 28 ({0, 1, 3, 5, 8} / {2, 4, 6, 7, 9})

[[0, 5],
 [0, 0]] -> 5

Charcoal, 37 36 34 bytes
Ｉ⌊ＥＥＸ²⁻Ｌθ²↨⁺Ｘ²⊖Ｌθ⊗ι²ΣＥθ∧§ιμΣΦλ¬§ιξ

Try it online! Link is to verbose version of code. Explanation:
   Ｅ…Ｘ²⁻Ｌθ²Ｘ²⊖Ｌθ                    Loop over all cuts...
  Ｅ             ↨⊗ι²                ... converted to base 2
                    ΣＥθ∧§ιμ         Sum rows in source cut
                           ΣΦλ¬§ιξ  Sum columns in sink cut
Ｉ⌊                                  Print the minimum

The range is constructed so that the base 2 values are 100...000 to 111...110 whereby the 1 bits refer to the source cut (thus the left bit, which is actually element 0, is the source itself) and the 0 bits refer to the sink cut.


How many languages can you use simultaneously in ONE functioning program in under 500 bytes Intro
In Objective-C (a superset of C and an object-oriented language), I can create an object called a UIWebView. There is a method for this object called loadHTMLString: in which I can load actual HTML into the UIWebView object itself. I can also inject Javascript into it using the method stringByEvaluatingJavaScriptFromString:.
If I were to write a program that created a UIWebView, loaded in my string (which happens to be HTML "code") and then injected a second string (which is Javascript code) I would be using 3 languages at once, in a functional program. (Not sure that html is really a programming language... so that's debatable haha)
You can also do things like embed Python into C (and other languages): https://docs.python.org/2/extending/embedding.html

This isn't too difficult, with any language you can use other languages inside it if you try hard enough.

Challenge
The challenge here is to see how many languages you can cram into 1 functioning program in under 500 bytes. https://mothereff.in/byte-counter
The program can do literally any task, it just has to work. The languages all have to work together, so you can't have 2 languages running one task, and 3 other languages running a completely different task. So whatever your "task" may be (you decide), there should only be 1 task, and all n languages should work on just that 1 task in your 1 program.

Objective
Your score is the number of languages you used. Whoever uses the most languages at once gets a cookie.
Since this is a popularity contest I will be accepting the answer with the most up-votes.

Q&A
•Ray asked, "Just to clarify, you're looking for a program that uses multiple languages to accomplish different parts of a single task, as opposed to a polyglot that is a valid program in multiple languages?"
Answer, "Yes".
•DanielM. asked, "does Regex count?" Answer, "Yes, I personally WOULD count it. Again, this is a popularity contest, so it really is up to the voters to determine. HTML is not considered a programming language by some, but it has been successfully used in an answer already that has seen quite a few upvotes. (Also, Stack-overflow does define Regex as a programming language if that helps you make your decision to use it or not: https://stackoverflow.com/tags/regex/info)

HTML, CSS, PHP, JavaScript, CoffeeScript, RegEx, sed, bash; 8 languages

Displays colors of the rainbow.

(Only 396 bytes) will try to add more languages

HTML + CSS is turning complete and counts as a valid language on PPCG. I've been told CoffeeScript is different enough as JavaScript to be counted as a separate language. And RegEx has been specifically allowed also.

PHP allows for addition of many languages especially with exec and shell_exec functions.

Golfed to fit inside byte limit (ES6)

Uses:

PHP to generate CSS
PHP, uses exec to run bash
sed to split color items for bash
CSS to specify text colors
JavaScript to generate elements
RegEx to split color items for JS
CoffeScript to print elements
HTML as a wrapper / output

Faster & Ungolfed (All modern browsers)


Be an Epidemiologist! Challenge

You must create a simple model of how disease spreads around a group of people.

Rules and Requirements

The model must be a 1000 by 1000 2D array with each element being a different person.

The user must input three variables using argv: the probability of transmission (how likely someone is going to infect someone else), chance of mutation and how many periods the simulation should run for.

In the first period (t=0), four people should be chosen randomly and infected with the disease.

The way the disease behaves is governed by the following rules:

The disease can only move vertically and horizontally, moving to the person next door.
The infection last for 3 periods in every person. You may not factor in immunodeficiencies.
After a person has been infected three times, they are immune and cannot be infected again.
The disease is subject to mutation making the previously immune people vulnerable to this new mutated disease. The mutated disease has exactly the same traits and follows the same rules as the original disease.
If a mutation occurs, the whole disease does not change, just that particular 'packet' upon transmission.
Once a person has been been infected by one virus, they cannot be infected again until the current infection passes.
If a person is infected, they are infectious from the start of their infection period to its end.
There are no levels of immunity - a person is either immune or not.
To stop memory overload, there is a maximum limit of 800 mutations.

At the end of the specified number of periods, you should output the results.

The results must be a 1000 x 1000 grid showing which people are infected and which people are not. This can be output as a text file, as an image file or graphical output (where #FFFFFF is a healthy person and #40FF00 is an infected person).

Please can you include the language name and a command to run it in your answer.

Winning

The fastest code to run on my computer wins. Its time will be measured with the following piece of Python code:

import time, os
start = time.time()
os.system(command)
end = time.time()
print(end-start)

Note that when running this script, I will use the following defaults:

Probability of transmission = 1
Chance of mutation = 0.01
Number of periods = 1000

I was curious what this would look like so I made this quick and dirty hack in JavaScript: http://jsfiddle.net/andrewmaxwell/r8m54t9c/

// The probability that a healthy cell will be infected by an adjacent infected cell EACH FRAME.
var infectionProbability = 0.2

// The probability that the infection will mutate on transmission EACH FRAME.
var mutationProbability = 0.00001

// The maximum number of times a cell can be infected by the same infection.
var maxInfections = 3

// The number of frames a cell in infected before it becomes healthy again.
var infectionDuration = 3

// The width and heigh of the board
var size = 400

// The number of cells infected at the beginning.
var startingNum = 4

var imageData, // the visual representation of the board
    cells, // array of cells
    infectionCount // counter that is incremented whenever a mutation occurs

// Just some colors. The colors are re-used as the number of mutations increases.
var colors = [[255,0,0],[255,255,0],[0,255,0],[0,255,255],[0,0,255],[255,0,255],[128,0,0],[128,128,0],[0,128,0],[0,128,128],[0,0,128],[128,0,128],[255,128,128],[255,255,128],[128,255,128],[128,255,255],[128,128,255],[255,128,255]
]

// when a cell is infected, it isn't contagious until the next frame
function infect(person, infection){
    person.infect = true
    person.infectionCounts[infection] = (person.infectionCounts[infection] || 0) + 1
    person.currentInfection = infection
}

// when a mutation occurs, it is given a number and the counter is incremented
function mutation(){
    return infectionCount++
}

function reset(){

    cells = []
    infectionCount = 0
    imageData = T.createImageData(size, size)

    // initialize the cells, store them in a grid temporarily and an array for use in each frame
    var grid = []
    for (var i = 0; i < size; i++){
        grid[i] = []
        for (var j = 0; j < size; j++){
            cells.push(grid[i][j] = {
                infectionTime: 0, // how many frames until they are no longer infected, so 0 is healthy
                infectionCounts: [], // this stores how many times the cell has been infected by each mutation
                neighbors: [] // the neighboring cells
            })
        }
    }

    // store the neighbors of each cell, I just want to minimize the work done each frame
    var neighborCoords = [[0,-1],[1,0],[0,1],[-1,0]]
    for (var i = 0; i < size; i++){
        for (var j = 0; j < size; j++){
            for (var n = 0; n < neighborCoords.length; n++){
                var row = i + neighborCoords[n][0]
                var col = j + neighborCoords[n][1]
                if (grid[row] && grid[row][col]){
                    grid[i][j].neighbors.push(grid[row][col])
                }
            }
        }
    }

    // infect the initial cells
    for (var i = 0; i < startingNum; i++){
        infect(cells[Math.floor(cells.length * Math.random())], 0)
    }
}

function loop(){
    requestAnimationFrame(loop)

    // for each cell marked as infected, set its infectionTime
    for (var i = 0; i < cells.length; i++){
        var p = cells[i]
        if (p.infect){
            p.infect = false
            p.infectionTime = infectionDuration
        }
    }

    for (var i = 0; i < cells.length; i++){
        var p = cells[i]

        // for each infected cell, decrement its timer
        if (p.infectionTime){
            p.infectionTime--

            // for each neighbor that isn't infected, if the probability is right and the neighbor isn't immune to that infection, infect it
            for (var n = 0; n < p.neighbors.length; n++){
                var neighbor = p.neighbors[n]
                if (!neighbor.infectionTime && Math.random() < infectionProbability){
                    var infection = Math.random() < mutationProbability ? mutation() : p.currentInfection
                    if (!neighbor.infectionCounts[infection] || neighbor.infectionCounts[infection] < maxInfections){
                        infect(neighbor, infection)
                    }
                }
            }

            // colors! yay!
            var color = colors[p.currentInfection % colors.length]
            imageData.data[4 * i + 0] = color[0]
            imageData.data[4 * i + 1] = color[1]
            imageData.data[4 * i + 2] = color[2]
        } else {
            imageData.data[4 * i + 0] = imageData.data[4 * i + 1] = imageData.data[4 * i + 2] = 0
        }

        imageData.data[4 * i + 3] = 255
    }

    T.putImageData(imageData, 0, 0)
}

// init canvas and go
C.width = C.height = size
T = C.getContext('2d')
reset()
loop()


Bookkeeping for the Sex Bob-ombs (check if a running sum ever gets too low) Believe it or not, the Sex Bob-ombs have become a world famous band and are currently on world tour! As their bookkeeper you must oversee their day to day finances and provide regular reports.
Every few weeks you compile a list of their expenses (in whole USD) in the order they were incurred.
For example, the list
378
-95
2234

means that $378 was deposited to their account, and after that $95 was withdrawn, and after that $2234 was deposited.
You want to make sure that the running sum of these values never goes below some threshold value T. You decide to write a program to do this for you.
Challenge
Write a program or function that takes in a single integer T and a list of integers. If the running sum of the list of integers is ever less than T, then print or return a falsy value, otherwise print or return a truthy value.
You may use any usual input methods (stdin, from file, command line, arguments to function).

At the start of the list the running sum is 0. So a positive T means the result is always falsy.
+ will never be in front of positive integers.
The list may contain 0.
The list may be empty.

Test Cases
T is -5 in all of these.
Falsy:
-6
1
2
3
-20
200
-300
1000
Truthy:
[empty list]
-5
4
-3
-6

Scoring
The submission with the fewest bytes wins. Tiebreaker goes to earliest posted submission.
The regrettable comment that forced me to make this.

Haskell, 22 bytes

f t=all(>=t).scanl(+)0

Usage: f (-5) [4,-3,-6] which outputs True.

Make a list of sub-totals and check if all elements are >= t.

Edit: Bugfix for empty list and positive ts


ROT-13 transform standard input The challenge:  To read an input of arbitrary length and produce the ROT13 of the input.  All characters besides A-Z should be copied to the output verbatim, and case should be preserved if possible.

Any language that can read and write standard streams is fair game.

Bash, 23 bytes

Canonical 23-character answer:

tr A-Za-z N-ZA-Mn-za-m


Converting to Secret Language Write some code in any language that inputs a string such as "Today is a great day" (Note that there is no punctuation) and converts it to the "Secret Language". Here are the rules for the "Secret Language".

a=c, b=d, c=e and so on (y=a and z=b)
separate each word by a space
make sure there is proper capitalization

Example:

Input: "Today is a great day"

Output: "Vqfca ku c itgcv fca"

It is a popularity-contest. Other users should give points by looking for most "to the point" yet "unique" code.

CHALLENGE:
I was looking up uncommon programming languages and I found a language called Piet (esolang). I challenge anyone to write it in this language.

Smalltalk (Smalltalk/X), 29 27 chars
I am lucky - it is already in the String class:
'Today is a great day' rot:2
    -> 'Vqfca ku c itgcv fca'

adding I/O, this makes it:
(Stdin nextLine rot:2)print

in the spirit of doorknob's obfuscated example below, how about:
Parser evaluate:('(Uvfkp pgzvNkpg tqv:2)rtkpvPN' rot:-2)


Implement Malbolge's "crazy" operator One of many unique features of the Malbolge programming language is its highly unintuitive OP operator, referred to only as "op" in the documentation and source code but popularly known as the "crazy" operator. As described by Ben Olmstead, the creator of the language, in its documentation: "don't look for pattern, it's not there."

op is a "tritwise" operator -- it operates on corresponding ternary digits of its two arguments. For each trit (ternary bit), the result of op is given by the following lookup table:

           a
op(a,b)  0 1 2
       +-------
     0 | 1 0 0
   b 1 | 1 0 2
     2 | 2 2 1

For example, to calculate op(12345, 54321), first write out both numbers in ternary and then look up each pair of trits in the table:

   0121221020   (12345_3)
op 2202111220   (54321_3)
--------------
   2202220211   (54616_3)

The last important point is that all values in Malbolge are 10 trits wide, so input values should be padded with zeroes to a width of 10. (For instance, op(0, 0) is 1111111111 in ternary.)

Your task is to take two integers 0 ≤ a, b < 59049 as input, and output the integer value of op(a,b).

Test cases (in the format a b op(a,b)):

0 0 29524
1 2 29525
59048 5 7
36905 2214 0
11355 1131 20650
12345 54321 54616

Here is a reference implementation (copied directly from the Malbolge source code).

C (gcc), 99 98 96 bytes

Saved a byte thanks to ceilingcat; golfing 19683 to L'䳣'.
Saved two bytes; golfing 108609 to L''.

M,a,l,b,o;L(g,e){for(o=b=L'䳣',l=0;o/=2.4;b/=3)M=g/b,g%=b,a=e/b,e%=b,l+=b*(L''>>M+6*a+M&3);g=l;}

Try it online!


Minimum perimeter of an area Just a simple code golf function for fun, intentionally left open with few rules to see what creativity comes up.

Input: An integer representing the area of a rectangle.

Output: Two integers representing the side lengths of the rectangle that have the least perimeter for the area.  (In any order.)

Test cases:

25 => 5, 5
53 => 53, 1
4294967295 => 65537, 65535

Mathematica 34 26

Besides the explicit search there is a nice convergent series:

n = 27

{i=√n//.i_:>n/⌈n/⌊i⌋⌉,n/i}

  {3, 9}

Three previous approaches with 34 characters:

{#,n/#}&@FixedPoint[n/⌈n/⌊#⌋⌉&,√n]

For[i=√n,i>(i=n/⌈n/⌊i⌋⌉),];{i,n/i}

f@i_:=f[f@i=n/⌈n/⌊i⌋⌉]
{i=f@√n,n/i}

ClearAll[f]

Visualization:

p = FixedPointList[n/⌈n/⌊#⌋⌉ &, Sqrt[n]];

Plot[n/x, {x, 0, 11}, GridLines -> {Range@n, Range@n},
 AspectRatio -> Automatic, PlotRange -> {{0, 10.2}, {0, 7.2}},
 Epilog -> {Red, Thickness[0.005],
   Arrow[Transpose[{{n/p, ⌈p⌉}, {n/p, ⌊p⌋}, {⌈n/⌊p⌋⌉, ⌊p⌋}}, {2, 3, 1}]],
  PointSize[0.02], Black, Point[{n/p[[-1]], p[[-1]]}]}]


Number of holes in a polygon The Problem: Count the number of holes in a connected polygon. Connectivity of the polygon is guaranteed by the condition that every triangle in the input triangulation shares at least 1 side with another triangle and that there is only one such connected set of triangles.

Input is a list L of n points in the plane and a list T of 3-tuples with entries from 0...n-1. For each item in T the tuple (t_1,t_2,t_3) represents the three vertices (from the list L) of a triangle in the triangulation. Note that this is a triangulation in the sense of 'polygon triangulation', because of this there will never be two triangles in T that overlap. An additional stipulation is that you will not have to sanitize the input, L and T do not contain any repeats.

Example 1: If L = {{0,0},{1,0},{0,1},{1,2}} and T = {{0,1,2},{1,2,3}} then the polygon specified has a hole count of 0.

Example 2: If L = {{0,0},{1,0},{2,0},{2,1},{2,2},{1,2},{0,2},{0,1},{.5,.5},{1.5,.5},{1.5,1.5},{.5,1.5}} and T = {{5,6,11},{5,10,11},{4,5,10},{3,8,10},{2,3,9},{2,8,9},{1,2,8},{0,1,8},{0,8,11},{0,7,11},{6,7,11},{3,4,10}} then the polygon input should result in an output of 2.

The task is to write the shortest program (or function) that takes L and T as input and returns the number of holes. The 'winner' will be recognized as the entry with the least character count (tentative end date 1st of June).

Sample input formatting (note the 0 indexing):

0,0
1,0
0,1
1,2
0,1,2
1,2,3


Print 1 to 1000 in C++ without semi-colons Following this popular question, present your solution which prints the numbers 1 to 1000 (all of them, not the string "1 to 1000" verbatim or something funny) in C++ without using any semi-colons. Unlike the original question, you may use conditionals and loops.

Solutions not requiring any compiler flags are preferred. Please mention any you use if you go against this. Undefined behaviour is allowed, so please specify the compiler and version you're using. Preference will be given to clever solutions. This is not a shortest code contest.

(I have a solution, which I'll post in 24 hours if a similar solution isn't posted before then.)

The semicolon is not needed if you know the magic word. And no need to go obfuscated.

My solution has the additional fanciness that it doesn't use any comma either ;)

#include <iostream>
#define Please(x) if (x) {}

int Number(int x)
{
    if (x > 1)
        Please(Number(x-1))
    Please(std::cout << " " << x)
}

int main()
{
    Please(Number(1000))
}


Convert to and from the factorial number system The Factorial Number System, also called factoradic, is a mixed radix numeral system. The factorials determine the place value of a number.

In this system, the right most digit can be either 0 or 1, the second rightmost digit can be 0, 1 or 2, and so on. This means that an n digit factoradic number can have a maximum value of (n + 1)!.

For example, to convert the factoradic number 24201 to decimal you would do this:

2 * 5! = 240
4 * 4! = 96
2 * 3! = 12
0 * 2! = 0
1 * 1! = 1
240 + 96 + 12 + 0 + 1 = 349

Hence the factoradic number 24201 is 349 base 10.

To convert a decimal number (with 349 as an example) into a factoradic number, you would do this:

Take the largest factorial less than the number. In this case it is 120, or 5!.

349 / 5! = 2 r 109
109 / 4! = 4 r 13
13 / 3! = 2 r 1
1 / 2! = 0 r 1
1 / 1! = 1 r 0

Hence 349 base 10 is the factoradic number 24201.

Your challenge is to create the shortest program or function that converts an input number to the other base.

The input will be a string representation of a non-negative integer. A factoradic number will be preceded by a ! (eg. !24201), while a decimal number will not be preceded by anything. You may assume that the maximum input will be 10! - 1 - 3628799 in decimal and 987654321 in factoradic. This means that letters will not appear in a factoradic input/output.

The program doesn't need to prepend a ! to a factoradic output, and may output a string or an integer. The input may be in any reasonable format.

Test cases:

Input: 1234
Output: 141120

Input: 746
Output: 101010

Input: !54321
Output: 719

Input: !30311
Output: 381


Evaluate a simple spreadsheet Rules

No cell range references (A2:B3).

Maximum 9 rows and 9 columns.

No circular references or formula errors.

Empty cells evaluate to 0.

Data are numbers only, but may be taken as strings.

Formulas are strings.

Implementation choices
You must state your choices in these matters:

Require formulas to be prefixed with any single character, e.g. = – or not.

The leftmost cell of the second row is A2 or R2C1, as per the two conventions used by Excel et al.

Require any single-character pre- or suffix in cell references, e.g. $ – or not.

One of null, empty string, empty list, etc., (but not 0) to represent empty cells.

Language of your submission (spreadsheet managers are not allowed).

Language for the formulas (may differ from the above).*

Brownie points or cookies for explaining your solution.

Examples
Choices: 7: =; 8: A2; 9: none; 10: ""; 12: Excel Formula Language
In:
[[       2, 3],
 ["=A1+B1",""]]

Out:
[[2,3],
 [5,0]]

In:
[[       2,"=A1+B2"],
 ["=A1+B1",      ""]]

Out:
[[2,2],
 [4,0]]

In:
[[ 3, 4,"=A1*B1"],
 [ 2, 5,"=A2*B2"],
 ["","","=C1+C2"]]

Out:
[[3,4,12],
 [2,5,10],
 [0,0,22]]

In:
[["","=2*B2*B3"     ,""],
 [ 3,"=A1+(A2+C2)/2", 2],
 [ 1,"=C1+(A3+C3)/2", 5]]

Out:
[[0,15,  0],
 [3, 2.5,2],
 [1, 3  ,5]]

* The formula language must be PPCG admissible, but you only have to support cell references plus criteria 3 and 4 there, wiz. addition and primeness determination.

JavaScript, 125 112 105 bytes

To use, add f= at the beginning and invoke like f(argument).

a=>a.map(b=>b.map(p=>+p?p:p?eval(p.replace(/[A-I][1-9]/g,m=>`a[${m[1]-1}][${(m.charCodeAt(0)-65)}]`)):0))

Choices:

Does not require =.
The left most cell of second row is A2.
Does not require any prefix or suffix.
"" (Empty String) to denote empty cell.
JavaScript.
JavaScript.
Cookies.

Explanation:

This solution iterates over all the cells of the worksheet (each element of the sub-arrays of the given array) and if non-empty String is found, replaces its cell references with the corresponding references in terms of the given array and evaluates the expression with eval() (yeah, that evil thing that haunts you in your nightmares). This solution assumes that the constants provided in the input array are of Integer type.

Test Cases

f=a=>a.map(b=>b.map(p=>+p?p:p?eval(p.replace(/[A-I][1-9]/g,m=>`a[${m[1]-1}][${(m.charCodeAt(0)-65)}]`)):0))

console.log(f([[1,2,3],["A1+B1+C1",10,11]]));
console.log(f([[1,2,5,4,6,89,0],[0,1,2,3,"A2+A1",5,6]]));
console.log(f([[1,2,4,5],["A1/B1*C1+A1+Math.pow(5,B1)",2,3,4]]));


Exponent of complex numbers Given two integers, which may be negative, zero, or positive, a and b (taken in any reasonable format, including inputting a plain complex number), convert it to a + bi where i is the imaginary number (square root of negative one). Then, raise it to the power of a third (positive integer) input variable, c as to (a + bi)c. You should then end up with something like d + ei. You must then output, or return, d and e in any reasonable format (including outputting a plain complex number).

Input and output may be taken or outputted in any order.

Examples:

5, 2, 2 -> 21, 20
1, 4, 2 -> -15, 8
-5, 0, 1 -> -5, 0

Mathematica, 17 bytes
ReIm[(#+#2I)^#3]&

Try it online!
-8 bytes from alephalpha
but........
rules have changed......
so
Mathematica, 5 bytes
Power


Fake divisor sum polyglots The task

In this challenge, your task is to write a program in a programming language L that takes a positive integer n, and outputs the sum of the proper divisors of n (sequence A001065 on OEIS).
It should return the correct output for any 1 ≤ n ≤ 10 000.
Here are the first 10 outputs:

0, 1, 1, 3, 1, 6, 1, 7, 4, 8

Furthermore, your program must be a fake polyglot, which means the following.
It is a valid program in another programming language L', and for each input 1 ≤ n ≤ 10 (the test cases above), it returns the sum of proper divisors of n, but there exists some 11 ≤ n ≤ 10 000 for which it doesn't return the correct result.
It may return something incorrect, loop forever, crash etc.
It can give a wrong result for all n ≥ 11, for some of them or just one.

Rules and scoring

You can write a full program or a function, and you can have different means of input and output in the two languages.
The lowest byte count wins.
Standard code-golf rules apply.
In this challenge, different major versions or implementations of a language are considered distinct.

Note that if you use programming languages with non-ASCII encodings (as many do on this site), the same sequence of bytes must be used for both languages.
This means that you must either convert between potentially different code pages or suffer penalties for multi-byte Unicode characters.

Additional test cases

20 -> 22
36 -> 55
180 -> 366
997 -> 1
2875 -> 869
10000 -> 14211

JavaScript (ES6), V8 / SpiderMonkey vs Chakra, 66 63 bytes

n=>[...Array(n)].map((_,d)=>s+=n%d?0:d,[0,n>10].sort(x=>s=x))|s

Demo

let f =

n=>[...Array(n)].map((_,d)=>s+=n%d?0:d,[0,n>10].sort(x=>s=x))|s

console.log(JSON.stringify(
  [...Array(20)].map((_, n) => n + 1).map(f)
))

Output

Output of the above snippet on Chrome and Firefox (all correct):

[0,1,1,3,1,6,1,7,4,8,1,16,1,10,9,15,1,21,1,22]

Output on Edge (off by 1, starting at n = 11):

[0,1,1,3,1,6,1,7,4,8,2,17,2,11,10,16,2,22,2,23]

Why?

No algorithm is imposed by the specification for the .sort() method. It's not even required to be stable. Therefore, each JavaScript engine uses its very own implementation.

However, [0,1].sort(x=>x) gives [0,1] with all engines.

So what's the difference?

What's happening here is that Chakra is passing 1 as the first parameter of the first (and only) iteration to the callback function (asking for a comparison of 1 with 0), while V8 and SpiderMonkey are passing 0 (asking for a comparison of 0 with 1).

You can use the following snippet to check what your browser is doing.

[0, 1].sort((x, y) => console.log("Let's compare " + x + " with " + y + "!"))


Do I need a win streak? You have played \$N\$ matches in some game where each match can only result in one of the two outcomes: win or loss. Currently, you have \$W\$ wins. You want to have a win percentage of \$P\$ or more, playing as few matches as possible. Output the minimum win streak that you need. Assume the current win streak is at \$0\$.
For example: If \$N=10, W=2, P=50\$, then  you can win \$6\$ matches in a row, bringing your win percentage to \$\frac{2+6}{10+6} = \frac{8}{16} = 50\%\$. You cannot have a win percentage of \$50\$ or more earlier than this. So the answer for this case is \$6\$.
Examples
W, N, P ->
2, 10, 50%      -> 6
3, 15, 50%      -> 9
35, 48, 0.75    -> 4
19, 21, 0.91    -> 2
9, 10, 50%      -> 0
0, 1, 1/100     -> 1
43, 281, 24/100 -> 33
0, 6, 52%       -> 7

Rules

\$N\$ and \$W\$ will be integers with \$0 \le W < N\$.
The percentage \$P\$ will be an integer between \$1\$ and \$100\$ inclusive. You can also choose to take a decimal value between \$0\$ and \$1\$ inclusive instead, which will contain no more than \$2\$ decimal places, or take it as a fraction.
You can take the inputs in any convenient format.
Standard loopholes are forbidden.
This is code-golf, so the shortest code in bytes wins.

Python 3, 35 bytes

lambda w,n,p:-min(0,(w-p*n)//(1-p))

Try it online!
-4 bytes thanks to pajonk
Some simple math: if \$X\$ is the number of wins we need, then we have:
\$\frac{W+X}{N+X}\geq P\$
\$W+X\geq PN+PX\$
\$X-PX\geq PN-W\$
\$X(1-P)\geq PN-W\$
Since \$P<1\$, then \$1-P>0\$, so we can divide from both sides without division by zero or flipping the sign.
\$X\geq\frac{PN-W}{1-P}\$


Base-phi converter time! The Golden Ratio Bureau is obsessed with this new thing they call base-phi. You see it and decide to code-golf, as is your natural instinct.

To be specific, base-phi is a number system like base 10, except it uses the number phi, or the golden ratio, as its base. A ones digit would be x*10^y, but in base phi 10 is replaced with phi. Base phi also uses 2 digits, 0 and 1.

Your goal is to accept input that is a base 10 positive natural number, then treat it as such and convert it to base phi.

Due to base phi being able to represent all numbers in more than one way, your program should convert input to its "minimal" representation. This is the representation with the least 1 digits.
Output can have trailing characters but only if the language must output them with no circumvention.

Do not use any built-ins for base conversion. You may use a built-in for phi, but the base conversion should rely on string manipulation and other mathematical operations.

Your program must support inputs up to 2147483647, or lower, depending on your language's limit for integers.

Your program can deal with any undefined behavior as you wish.

Testing cases for accuracy can be done at this link. In case you do not wish to use the link, here are the numbers 1-15 in base phi.

1 = 1
2 = 10.01
3 = 100.01
4 = 101.01
5 = 1000.1001
6 = 1010.0001
7 = 10000.0001
8 = 10001.0001
9 = 10010.0101
10 = 10100.0101
11 = 10101.0101
12 = 100000.101001
13 = 100010.001001
14 = 100100.001001
15 = 100101.001001

The shortest program following these rules wins. Have fun.

Retina, 81 80 bytes

K`0.
"$+"{+`(1(\.)|(1\.(0?1)*0?)1)(00|$)
${3}0${2}11
0\.
1.
+0`0?1(\.?)1
10${1}0

Try it online! Works by repeatedly adding \$ 1 \$. Explanation:

K`0.

Start off with \$ 0. \$.

"$+"{`

Repeat the number of times given by the input.

+`(1(\.)|(1\.(0?1)*0?)1)(00|$)
${3}0${2}11

If the \$ \phi^0 \$ bit is set, use the identity \$ \phi^0 = \phi^{-1} + \phi^{-2} \$ to move bits away until there is enough room.

0\.
1.

Add \$ 1 \$.

+0`0?1(\.?)1
10${1}0

Minimise the number of bits by reversing the above identity.


!I!n!s!e!r!t! !i!n!b!e!t!w!e!e!n! Posted from here.

This challenge is highly "distilled" from this question. Special thanks to @Akababa!

In this task, you should insert an exclamation mark at the start of the string and after every character.

Rules

There will always be a non-empty-string input. The input will not contain tabs either. You can assume that the input only contain non-extended ASCII printable characters and newlines.
The input will not contain trailing newlines as long as your language can't detect a newline.
This is a code-golf contest; the shortest answer should win.

Examples

4 newlines result in 5 newline-delimited exclamation marks. It is very hard to put this as a Markdown text, so this is stated instead.

1 2 3 4 5 6
129591 129012 129127 129582

0

Outputs

!1! !2! !3! !4! !5! !6!
!1!2!9!5!9!1! !1!2!9!0!1!2! !1!2!9!1!2!7! !1!2!9!5!8!2!
!
!0!

asd afjoK ak:e
kPrLd
    fOJOE;
    KFO
KFkepjgop sgpaoj   faj

Outputs

!a!s!d! !a!f!j!o!K! !a!k!:!e!
!k!P!r!L!d!
! ! ! ! !f!O!J!O!E!;!
! ! ! ! !K!F!O!
!K!F!k!e!p!j!g!o!p! !s!g!p!a!o!j! ! ! !f!a!j!

A base test case with only one character:

a

Outputs

!a!

(Auto-completion! Just kidding, there is no such thing.) Contains exclamation marks:

!!
!!
!!
!!
!!

Outputs:

!!!!!
!!!!!
!!!!!
!!!!!
!!!!!

QuadR, 1 byte

Thanks to A__ for halving the byte count!

!

Try it online!

Replaces nothing with !


Approximate definite integrals using Riemann sums Left and right Riemann sums are approximations to definite integrals. Of course, in mathematics we need to be very accurate, so we aim to calculate them with a number of subdivisions that approaches infinity, but that's not needed for the purposes of this challenge. You should instead try to write the shortest program, taking input and providing output through any of the default methods, in any programming language, which does the following:

Task

Given two rational numbers \$a\$ and \$b\$ (the limits of the definite integral), a positive integer \$n\$, a boolean \$k\$ representing left / right and a black-box function \$f\$, calculate the left or right Riemann sum (depending on \$k\$) of \$\int_a^b f(x)\mathrm{d}x\$, using \$n\$ equal subdivisions.

I/O Specs

\$a\$ and \$b\$ can be rational / floating-point numbers or fractions.
\$k\$ can be represented by any two distinct and consistent values, but please keep in mind that you aren't allowed to take complete or partial functions as input.
\$f\$ is a black-box function. Citing the meta answer linked above, the content (i.e. the code) of black-box-functions may not be accessed, you can only call them (passing arguments if applicable) and observe their output. If needed, please include the necessary information about the syntax your language uses such that we can test your submission.

As output, you must provide a rational / floating-point / fraction representing the Riemann sum you are asked for. As discussed in the past, floating-point imprecision can be ignored, as long as your output is accurate to at least three decimal places when rounded to the nearest multiple of 1 / 1000 (e.g. 1.4529999 is fine instead of 1.453).

Math Specs

\$f\$ is guaranteed to be continuous between \$a\$ and \$b\$ (no jumps, no holes, no vertical asymptotes).
There are three possible cases you have to handle: \$a = b\$ (The result should be \$0\$ or its equivalents), \$a < b\$ or \$a > b\$.
If \$b < a\$, the integral changes its sign. Also, the right sense of the integral in this case is towards \$a\$.
Areas under the graph are negative and those above the graph are positive.

Examples / Test Cases

The resolution is not optimal, because I had to shrink them down a bit, but they're still readable.

\$f(x) = 2x + 1,\: a = 5,\: b = 13,\: n = 4\$, k = right:

The result should be \$15 \cdot 2 + 19 \cdot 2 + 23 \cdot 2 + 27 \cdot 2 = 168\$, because the width of each rectangle is \$\frac{|b - a|}{n} = 2\$ and the corresponding heights are \$f(7) = 15,\:f(9) = 19,\:f(11) = 23,\:f(13) = 27\$.
\$f(x)=\sqrt{x},\: a = 1,\: b = 2.5,\: n = 3\$, k = left:

The output should be \$1.8194792169\$.
\$f(x) = -3x + 4 + \frac{x^2}{5},\: a = 12.5,\: b = 2.5,\: n = 10\$, k = right:

The expected output value is \$- (- 4.05 - 5.45 - 6.45 - 7.05 - 7.25 - 7.05 - 6.45 - 5.45 - 4.05 - 2.25) = 55.5\$, because the integral changes signs when flipping the boundaries (\$b<a\$).
\$f(x) = 9 - 4x +  \frac{2x^2}{7},\: a = 0,\: b = 15,\: n = 3\$, k = left:

Calculating our Riemann sum, we get \$13.5714285715\$.
\$f(x) = 6,\: a = 1,\: b = 4,\: n = 2\$,  k = right — Output: \$18\$.
\$f(x) = x^7 + 165x + 1,\: a = 7,\: b = 7,\: n = 4\$, k = left — Output: \$0\$.
\$f(x) = x \cdot \sin(x^{-1}),\: a = 0,\: b = 1,\: n = 50\$, k = right — Output: \$0.385723952885505\$. Note that sine uses radians here, but feel free to use degrees instead.

R, 69 65 63 57 bytes

function(a,b,n,k,f,w=(b-a)/n)sum(sapply(a+w*(1:n-k),f))*w

Try it online!

Takes k=FALSE for right-hand sums, although the TIO link now includes aliases for "left" and "right" for ease of use.

a+w*(1:n-k) generates appropriate left- or right-hand points.

Then sapply applies f to each element of the result, which we then sum up and multiply by the interval width (b-a)/n to yield the result. This last also neatly takes care of any sign issues we might have.


Implement subset of shell script This site had a lot of problems involving implementing various languages in interpreter tag. However, practically all of them were esoteric languages that nobody uses. Time to make an interpreter for a practical language that most of users here probably already know. Yes, it's shell script, in case you have problems reading the title (not that you have). (yes, I intentionally made this challenge, as I'm bored of languages like GolfScript and Befunge winning everything, so I put some challenge where more practical programming language have bigger chances of winning)

However, the shell script is a relatively big language, so I won't ask you to implement it. Instead, I'm going to make a small subset of shell script functionality.

The subset I decided on is the following subset:

Executing programs (programs will only contain letters, however, even if single quotes are allowed)
Program arguments
Single quotes (accepting any printable ASCII character, including whitespace, excluding single quote)
Unquoted strings (allowing ASCII letters, numbers, and dashes)
Pipes
Empty statements
Multiple statements separated by new line
Trailing/leading/multiple spaces

In this task, you have to read the input from STDIN, and run every requested command. You can safely assume POSIX-compatible operating system, so there is no need for portability with Windows, or anything like that. You can safely assume that the programs that aren't piped to other programs won't read from STDIN. You can safely assume that the commands will exist. You can safely assume that nothing else will be used. If some safe assumption is broken, you can do anything. You can safely assume at most 15 arguments, and lines below 512 characters (if you need explicit memory allocation, or something - I'm really going to give small chances of winning for C, even if they are still small). You don't have to clean up file descriptors.

You are allowed to execute programs at any point - even after receiving the full line, or after STDIN ends. Choose any approach you want.

Simple testcase that lets you test your shell (note the trailling whitespace after third command):

echo hello world
printf '%08X\n' 1234567890
'echo'   'Hello,   world!'

echo heeeeeeelllo | sed 's/\(.\)\1\+/\1/g'
  yes|head -3
echo '\\'
echo 'foo bar baz' | sed 's/bar/BAR/' | sed 's/baz/zap/'

The program above should output following result:

hello world
499602D2
Hello,   world!
helo
y
y
y
\\
foo BAR zap

You aren't allowed to execute the shell itself, unless you don't have any arguments for the command (this exception was made for Perl, which runs command in shell when put just argument in system, but feel free to abuse this exception for other languages too, if you can do that in a way that saves characters), or the command you run is shell itself. This is probably the biggest problem in this challenge, as many languages have system functions that execute shell. Instead use language APIs that call programs directly, like subprocess module in Python. This is a good idea for security anyway, and well, you wouldn't want to create an insecure shell, would you want to? This most likely stops PHP, but there are other languages to choose anyway.

If you are going to make your program in shell script, you aren't allowed to use eval, source, or . (as in, a function, not a character). It would make the challenge too easy in my opinion.

Clever rule abuse allowed. There are lots of things I explicitly disallowed, but I'm almost sure that you are still allowed to do things I haven't though of. Sometimes I'm surprised about how people interpret my rules. Also, remember that you can do anything for anything I haven't mentioned. For example, if I try to use variables, you can wipe the hard disk (but please don't).

The shortest code wins, as this is codegolf.

C (340 bytes)

I have no experience at all in golfing, but you have to start somewhere, so here goes:

#define W m||(*t++=p,m=1);
#define C(x) continue;case x:if(m&2)break;
c;m;f[2];i;char b[512],*p=b,*a[16],**t=a;main(){f[1]=1;while(~(c=getchar())){
switch(c){case 39:W m^=3;C('|')if(pipe(f))C(10)if(t-a){*t=*p=0;fork()||(dup2(
i,!dup2(f[1],1)),execvp(*a,a));f[1]-1&&close(f[1]);i=*f;*f=m=0;f[1]=1;p=b;t=a
;}C(32)m&1?*p++=0,m=0:0;C(0)}W*p++=c;}}

I added line breaks so you won't have to scroll, but didn't include them in my count since they are without semantic significance. Those after preprocessor directives are required and were counted.

Ungolfed version

#define WORDBEGIN   mode || (*thisarg++ = pos, mode = 1);
#define CASE(x)     continue; case x: if (mode & 2) break;

// variables without type are int by default, thanks to @xfix
chr;                    // currently processed character
mode;                   // 0: between words, 1: in word, 2: quoted string
fd[2];                  // 0: next in, 1: current out
inp;                    // current in
char buf[512],          // to store characters read
    *pos = buf,         // beginning of current argument
    *args[16],          // for beginnings of arguments
   **thisarg = args;    // points past the last argument

main() {                          // codegolf.stackexchange.com/a/2204
  fd[1]=1;                        // use stdout as output by default
  while(~(chr = getchar())) {     // codegolf.stackexchange.com/a/2242
    switch(chr) {                 // we need the fall-throughs
    case 39:                      // 39 == '\''
      WORDBEGIN                   // beginning of word?
      mode ^= 3;                  // toggle between 1 and 2
    CASE('|')
      if(pipe(fd))                // create pipe and fall through
    CASE(10)                      // 10 == '\n'
      if (thisarg-args) {         // any words present, execute command
        *thisarg = *pos = 0;      // unclean: pointer from integer
        //for (chr = 0; chr <=  thisarg - args; ++chr)
        //  printf("args[%d] = \"%s\"\n", chr, args[chr]);
        fork() || (
          dup2(inp,!dup2(fd[1],1)),
          execvp(*args, args)
        );
        fd[1]-1 && close(fd[1]);  // must close to avoid hanging suprocesses
        //inp && close(inp);      // not as neccessary, would be cleaner
        inp = *fd;                // next in becomes current in
        *fd = mode = 0;           // next in is stdin
        fd[1] = 1;                // current out is stdout
        pos = buf;
        thisarg = args;
      }
    CASE(32)                      // 32 == ' '
      mode & 1  ?                 // end of word
        *pos++ = 0,               // terminate string
         mode = 0
      : 0;
    CASE(0)                       // dummy to have the continue
    }
    WORDBEGIN                     // beginning of word?
    *pos++ = chr;
  }
}

Features

Parallel execution: you can type the next command while the one before is still executing.
Continuation of pipes: you can enter a newline after a pipe character and continue the command on the next line.
Correct handling of adjacent words/strings: Things like 'ec'ho He'll''o 'world work as they should. Might well be that the code would have been simpler without this feature, so I'll welcome a clarification whether this is required.

Known problems

Half the file descriptors are never closed, child processes never reaped. In the long run, this will likely cause some kind of resource exhaustion.
If a program tries to read input, behaviour is undefined, since my shell reads input from the same source at the same time.
Anything might happen if the execvp call fails, e.g. due to a mistyped program name. Then we have two processes playing at being shell simultaneously.
Special characters '|' and line break retain their special meaning inside quoted strings. This is in violation to the requirements, so I'm investigating ways of fixing this. Fixed, at a cost of about 11 bytes.

Other Notes

The thing obviously does not include a single header, so it depends on implicit declarations of all functions used. Depending on calling conventions, this might or might not be a problem.
Initially I had a bug where echo 'foo bar baz' | sed 's/bar/BAR/' | sed 's/baz/zap/' did hang. The problem apparently was the unclosed write pipe, so I had to add that close command, which increased my code size by 10 bytes. Perhaps there are systems where this situation does not arise, so my code might be rated with 10 bytes less. I don't know.
Thanks to the C golfing tips, in particular no return type for main, EOF handling and ternary operator, the last one for pointing out that ?: can have nested , without (…).


Conjugate a Turkish verb Input

verb, a string that matches the regular expression ([a-pr-vyzıöüçğş]*[aeıioöuü][bcçdfgğhj-nprsştvyz]+|([a-pr-vyzıöüçğş]*[aeıioöuü]){2})(mak|mek)
plural, a truthy or falsy value
person, an integer having value either 1, 2, or 3
tense, an integer having value either 1, 2, or 3

Output

The conjugated form of the Turkish verb verb, in personst/nd/rd person, plural if plural is TRUE and singular if it is not, in

If tense is 1, the simple present;
If tense is 2, the continuing present;
If tense is 3, the future.

Rules

Turkish verbs are conjugated in three elements, which are in order:

The stem, formed by removing mak or mek from the end of the infinitive;
The sign of the tense, which is:

For the simple present:

  -r if the stem ends in a vowel;
  -ir according to vowel harmony rules (see below) if the stem contains more than one syllable (i.e. vowel), or is from one of the following irregular verbs: almak, bilmek, bulmak, durmak, gelmek, görmek, kalmak, olmak, ölmek, sanmak, vermek, varmak, vurmak;
  -er according to vowel harmony rules if the stem contains one syllable and is not listed in the irregular verbs above.

For the continuing present, -iyor, where the i changes according to vowel harmony rules. Stems that end in a vowel drop this vowel before adding this suffix, whereupon the suffix harmonizes with the next-to-last vowel in the word (guaranteed to exist by the regular expression).
For the future:

  -ecek according to vowel harmony rules if the stem ends in a consonant;
  -yecek according to vowel harmony rules if the stem ends in a vowel.

The personal suffix to indicate the performer of the action, in all cases according to vowel harmony rules:

    |Singular|Plural|
|---|--------|------|
|1st|    -im |   -iz|
|2nd|   -sin |-siniz|
|3rd| (none) |  -ler|

The final k of the future tense becomes ğ before -im and -iz, so for example (almak, TRUE, 1, 3) would yield alacağız.

Vowel harmony rules

Turkish vowels are divided into two groups: back (a ı o u) and front (e i ö ü) by where in the mouth they are pronounced. The suffixes of a word change vowels according to the vowels of the root.

All suffixes listed above that have i as a vowel instead use:

-ı if the last vowel before the suffix is ı or a (both these vowels are back and unrounded);
-i if the last vowel before the suffix is i or e (both these vowels are front and unrounded; note here Turkish's distinction between dotted and dotless I);
-u if the last vowel before the suffix is u or o (both these vowels are back and rounded); or
-ü if the last vowel before the suffix is ü or ö (both these vowels are front and rounded).

Take careful note of the present continuous suffix -iyor. The i harmonizes, but the o does not change. The personal suffixes will thus harmonize with the o.

All the suffixes listed above that have e as a vowel instead use:

-e if the last vowel before the suffix is a front vowel; or
-a if the last vowel before the suffix is a back vowel.

Irregular verbs

The verbs gitmek, tatmak, ditmek, gütmek, and etmek change the final t to a d before any endings that begin with a vowel (which includes all the endings in this challenge). Any verb that ends in -etmek likewise changes the t to a d, and appends -er for the simple present (though this is not so for the other verbs).

Test cases

gütmek, FALSE, 1, 2 -> güdüyorum
almak, TRUE, 3, 3 -> alacaklar
boğmak, TRUE, 2, 1 -> boğarsınız
ölmek, FALSE, 3, 1 -> ölür
boyamak, TRUE, 1, 2 -> boyuyoruz
affetmek, FALSE, 2, 1 -> affedersin
söylemek, TRUE, 3, 1 -> söylerler
söylemek, FALSE, 3, 2 -> söylüyor
söylemek, FALSE, 1, 3 -> söyleyeceğim

Javascript (ES6), 466 456 451 446 bytes

(v,p,w,t)=>(R=g=>g.exec(s),T=r=>s=s.slice(0,-1)+r,Z=s=>s.replace(/\d/g,c=>l=['ıuiü'[(n='aıoueiöü'.search(l))>>1],'ae'[n>>2]][c]),(s=v.slice(k=l=0,-3)).replace(/[aıoueiöü]/g,c=>(L=l,l=c,k++)),(R(/^(gi|ta|di|gü)t$/)||(R(/et$/)&&(k=1)))&&T`d`,((E=R(/[aıoueiöü]$/))&&t==2?(l=L,T``):s)+Z([(E?'':k<2&!R(/^((k?a|bi|bu|ge|o|ö)l)|dur|gör|san|v[aeu]r$/))+'r','0yor',(E?'y1c1':'1c1')+'ğkk'[--w]][t-1])+Z('0m|0z|s0n|s0n0z||l1r'.split`|`[w+w+p],t-2||(l='o')))

Ungofled and commented

// Parameters:
//   - 'v' = verb
//   - 'p' = plural flag
//   - 'w' = person
//   - 't' = tense
(v, p, w, t) => (
  // R() - Helper function to execute a regular expression on the stem.
  R = g => g.exec(s),

  // T() - Helper function to replace the last character of the stem with 'r'.
  T = r => s = s.slice(0, -1) + r,

  // Z() - Function that applies vowel harmony to the string 's', assuming
  //       '0' = 'i' and '1' = 'e' and using the last encountered vowel 'l'.
  Z = s => s.replace(
    /\d/g,
    c => l = [
      'ıuiü' [(n = 'aıoueiöü'.search(l)) >> 1],
      'ae' [n >> 2]
    ][c]
  ),

  // Computes:
  //   - 's' = stem
  //   - 'k' = number of vowels in stem
  //   - 'l' = last vowel in stem
  //   - 'L' = penultimate vowel in stem
  (s = v.slice(k = l = 0, -3)).replace(/[aıoueiöü]/g, c => (L = l, l = c, k++)),

  // Applies ending 't' => 'd' for irregular verbs and those ending in -et(mek).
  (R(/^(gi|ta|di|gü)t$/) || (R(/et$/) && (k = 1))) && T `d`,

  // Computes 'E' = truthy value if the stem ends in a vowel.
  // If 'E' is truthy and the tense is the continuing present, drops this vowel.
  ((E = R(/[aıoueiöü]$/)) && t == 2 ? (l = L, T ``) : s) +

  // Appends sign of tense with vowel harmony.
  Z([
    // t = 1: simple present -> either '-er', '-ir' or '-r'
    (E ? '' : k < 2 & !R(/^((k?a|bi|bu|ge|o|ö)l)|dur|gör|san|v[aeu]r$/) + 'r',

    // t = 2: continuing present -> always '-iyor'
    '0yor',

    // t = 3: future -> either '-yecek', '-ecek', '-yeceğ' or '-eceğ'
    (E ? 'y1c1' : '1c1') + 'ğkk' [--w]
  ][t - 1]) +

  // Appends personal suffix with vowel harmony,
  // forcing last vowel to 'o' for continuing present.
  Z(
    '0m|0z|s0n|s0n0z||l1r'.split `|` [w + w + p],
    t - 2 || (l = 'o')
  )
)

Test cases

let f =
(v,p,w,t)=>(R=g=>g.exec(s),T=r=>s=s.slice(0,-1)+r,Z=s=>s.replace(/\d/g,c=>l=['ıuiü'[(n='aıoueiöü'.search(l))>>1],'ae'[n>>2]][c]),(s=v.slice(k=l=0,-3)).replace(/[aıoueiöü]/g,c=>(L=l,l=c,k++)),(R(/^(gi|ta|di|gü)t$/)||(R(/et$/)&&(k=1)))&&T`d`,((E=R(/[aıoueiöü]$/))&&t==2?(l=L,T``):s)+Z([(E?'':k<2&!R(/^((k?a|bi|bu|ge|o|ö)l)|dur|gör|san|v[aeu]r$/))+'r','0yor',(E?'y1c1':'1c1')+'ğkk'[--w]][t-1])+Z('0m|0z|s0n|s0n0z||l1r'.split`|`[w+w+p],t-2||(l='o')))

console.log(f("gütmek", false, 1, 2));    // -> güdüyorum
console.log(f("almak", true, 3, 3));      // -> alacaklar
console.log(f("boğmak", true, 2, 1));     // -> boğarsınız
console.log(f("ölmek", false, 3, 1));     // -> ölür
console.log(f("boyamak", true, 1, 2));    // -> boyuyoruz
console.log(f("affetmek", false, 2, 1));  // -> affedersin
console.log(f("söylemek", true, 3, 1));   // -> söylerler
console.log(f("söylemek", false, 3, 2));  // -> söylüyor
console.log(f("söylemek", false, 1, 3));  // -> söyleyeceğim