text:
Be the First 1 (leave only the first Truthy)
Intro
Every year, Dyalog Ltd. holds a student competition. The challenge there is to write good APL code. This is a language agnostic code-golf edition of this year's eighth problem.
I have explicit permission to post this challenge here from the original author of the competition. Feel free to verify by following the provided link and contacting the author.
Problem
Given a Boolean* list, "turn off" all the Truthies after the first Truthy.
No Truthies? No problem! Just return the list unmodified.
Examples
[falsy,truthy,falsy,truthy,falsy,falsy,truthy] → [falsy,truthy,falsy,falsy,falsy,falsy,falsy]

[] → []

[falsy,falsy,falsy,falsy] → [falsy,falsy,falsy,falsy]

* All your truthies must be identical, and all your falsies must be identical. This includes output.

Can we use bit lists or other truthy/falsy list representations that are more natural in our language of choice?

@MartinEnder Yes, of course, I thought that was covered by default rules. No?

Well yeah, if you talk about "truthy" and "falsy" in the challenge instead of "booleans", "true" and "false". ;)

I'm not clear on the booleans. Can we use 0/1 even if our language has True/False?

@MartinEnder Thanks. Fixed.

@xnor See edit.

@Adám Are we choosing which values to expect as Truthy value and Falsey value? Does the output have to use the same ones as the input?

@xnor Ah, good point. I think it would be fair to allow choosing input, but output must match, don't you think so?

@Adám I think that's reasonable, though it needs limits to stop people form embedding code into their choice of values (is that a loophole?). Matching output feels right for the challenge.

@Adám Actually, I'm a bit sad a language like Haskell can't use an arithmetic solution just because 0's and 1's aren't truthy or falsey. But saying "any two distinct values" would let people use True as False and False as True, which is also silly. Not sure how to handle that.

@xnor I hear you, but if Haskell cannot treat numbers as Booleans, or cannot do arithmetic on Booleans, then that is a real limitation in the golfing power of Haskell, and ought to be reflected in the byte count by necessitating conversions or other work-arounds. What do you think of the footnote formulation?

It doesn't matter for this challenge (because the language doesn't have a working interpreter yet), but I'm working on a language which has booleans but not the ability to store them in arrays (not even by printing them one at a time; outputting boolean false would exit the program). How would that work in this challenge? (Normally you'd just use if statements to make them into something else, but the challenge bans that.)

Just to be sure, the input Truthy/falsy values should also be equal to the output T/F? Or can you use 0/1 as input and get TRUE FALSE as output?

@JarkoDubbeldam The first: All your truthies must be identical, and all your falsies must be identical. This includes output.

Are two trailing falsey values ok?

@Christopher What do you mean?

@Adám Input of 0 1 0 output of 0 1 0 0. Two extra false values at the end

@Adám https://tio.run/nexus/brain-flak#XY1RCsAgDEOv0s/kz/2XXkQ8SenZXYs4tyEUSV6SiT7oHvDo4FCjWknhsT7L@@muWzMwFCCNvjsKKNeKRqU0WwSpMslMe1g5imQy78kZ5bOT1afxWVv7czZpcsm5r3cD example

@Christopher I'd say no. That just isn't the right result.

@Adám thought so

If working a language with text input separated by newlines, is an empty line acceptable, or should the line be removed entirely?

@DomHastings An empty line is fine.

Could we take input newline-separated, but have output joined together? Or should both in- and output be newline separated, or both in- and output be joined together?

No Truthies? No problem! No problem = The problem (challenge) does not need to be solved. That pun is really clever!

APL, 2 bytes
<\

Evaluates to the function "scan using less-than".
Try it online!
Explanation
In APL, the operator \ (scan) reduces each nonempty prefix of an array from the right using the provided function.
For example, given the array 0 1 0, it computes 0 (prefix of length 1), 0<1 (prefix of length 2) and 0<(1<0) (prefix of length 2) and puts the results into a new array; the parentheses associate to the right.
Reducing by < from the right results in 1 exactly when the last element of the array is 1 and the rest are 0, so the prefix corresponding to the leftmost 1 is reduced to 1 and the others to 0.

Finally! I have been wondering.

Now I suppose you can answer in J too, no?

@Adám Yes, in J it's 3 bytes: </\ Jelly probably has an analogous 2-byte solution too.

No, I don't think so, because Jelly is left-to-right.

What a strange version of scan APL has. It's neither a left nor a right scan (rather, a mix between them) and doesn't allow the interpreter to reuse previous results in calculating the next. But, as we can see, it does things that can't easily be done with a normal (cumulative) scan operation. (Compare this to the Haskell answer)

@Hjulle Indeed, my answer implements precisely this scan "by hand" - although that wasn't how I thought of it originally. Haskell has both left and right scans, but both are aimed at reusing results, so neither works for this.

There are couple other two byters for this - ⊤\ and |.

Python 2, 35 bytes
while 1:b=input();print b;True&=b<1

Try it online! Input and output are lines of True/False.
Based on Dennis's solution. Redefines the variable True to be False after a True input is encountered. That way, any further inputs of True will evaluate to False and be printed as such. Python 3 no longer allows True and False to be redefined, so this answer uses Python 2.
The redefinition is True&=b<1, i.e. True = True & (b<1). When the input b is True, then (b<1) is False (since True==1), so True becomes False. See Kevin Cruijssen's answer for a shorter way to handle this redefinition.

You can redefine True??? This deserves a +1 just because hax >_>

@HyperNeutrino Yes, but not in Python 3. (Which is fine because the language here is Python 2.)

@BrianMcCutchon Okay thanks. That is just weird though...

@HyperNeutrino It's probably worth mentioning that you can do True, False = False, True.

@BrianMcCutchon Okay, thanks! Also, if I do True, False = False, True, will bool(1) return false (like, real false) and bool(0) return real true?

@HyperNeutrino - nope. Builtins still return the 'real' value, it's just 'True' that you type that changes. (Or modules, in some cases...). So bool(1) return True, but bool(1) == True returns False.

@TLW That's just... Weird... I won't be doing stuff like this anytime soon. :P

@HyperNeutrino - That's probably for the best :-) It's up there with #define 42 43 for how much 'fun' you can have in a codebase with it. Oh, and with ctypes you can actually make, e.g. the internal Python object that represents int(2) actually have an integer value of 1. This breaks all the things.

@BrianMcCutchon Actually, you can. import builtins \n builtins.__dict__["True"] = False. :-)

@wizzwizz4 That doesn't seem to change anything?

@BrianMcCutchon It might be good in a Python 3 port. Plus, it'll make eval(input()) work the same as Python 2's input in this case, no matter the local variables.

Aceto, 19 17 bytes
New version (17 bytes):
This new version takes the characters one at a time and is best executed with the -F option. It works similar, but not identical to the previous solution:
 >,
Op0
p|1u
,ip^

Old answer (19 bytes):
|p1u
iOp<
|!`X
rd!r

This is the first Aceto answer that highlights what it can do relatively well, I would say. The "lists" are input streams, with one input per line, "1" for true, and "0" for false, with an empty string signifying the end of the list.

Aceto programs run on a Hilbert curve, starting on the bottom left, and ending on the bottom right. First, we read a string, duplicate, and negate (!) it, turning empty strings into True, everything else into False. Then there's a conditional horizontal mirror (|): If the top element on the stack is truthy, mirror horizontally. This happens when the string was empty. If we do the mirroring, we land on the X, which kills the interpreter.
Otherwise, we convert the remaining copy on the stack to an integer and do another conditional horizontal mirror: This time, because 1 is truthy and 0 is falsy, we mirror if we see the (first) true value. If we don't mirror (so we saw a 0) we print what's on the stack (since the stack is empty, a zero) and jump to the Origin of the curve, where we started, starting the whole process again.
Otherwise, when we saw a 1, we mirror and land on the u, which reverses the direction we move on the Hilbert curve. 1p prints a 1, and now we go on the same O we would have gone if we had seen a 0, but since we're in "reversed mode", our origin is at the bottom right, so we jump there.
Now we read another string, and negate it. If the string was empty, and therefore the top stack element is truthy, ` will not escape the next command (X), making us quit.
Otherwise (if the string wasn't empty), we do escape the X and ignore it. In that case, we go to the left (<), print 0 (because the stack is empty), and jump back to the Origin.

Congratulations on your first proper challenge solved in Aceto.

Looks at diagram. Right…

@Adám It probably won't help (if you don't know Aceto) on its own, but I thought it might be good to see alongside the text to be able to follow it better.

Java8, 24 19 Bytes
Long::highestOneBit

Hope this is legal; I got the impression the input / output doesn't have to evaluate as true/false in the language. Takes a long as input and gives one as output, with ones being true and zeroes being false in the binary representation. For example, binary 00101 is 5 and would return binary 00100 which is 4.
Five bytes thanks to @puhlen

Nice approach. Java being competitive‽

Wow, JAVA as a competitive answer‽

Not entirely sure if this is valid for codegolf rules, but this could be improved to 19 chars by using a method reference: Long::highestOneBit which produces the identical result with a shorter syntax

@puhlen expressions evaluating to anonymous functions are allowed.

@puhlen Thanks, didn't realize that would work here, but since it's completely equivalent..

This isn't quite valid.  You need to include the import to Long, as this doesn't compile by itself.  That said, java.lang.Long::highestOneBit compiles just fine.

@NathanMerrill The java.lang package is imported by default. From the language spec "A compilation unit automatically has access to all types declared in its package and also automatically imports all of the public types declared in the predefined package java.lang."

@JollyJoker you're right.  I assumed that wasn't the case because my IDE auto-imports it.  My bad :)

@Adám, ZacharyT: +1 for exposing me to the Interrobang.

What's with all the weird question marks‽

Python 2, 33 bytes
while 1:b=input();print b;True^=b

Port of @xnor's Python answer, minus 2 bytes. Normally I would just suggest it as a golf in the comments, but since @xnor has specifically stated we can outgolf any of his answers for a bounty, here it is as a separated answer.
Try it online.
The difference? True&=b<1 has been changed to True^=b.
Why does this work?
First we get some potential False inputs (b=input();). Each of those will be printed as is (print b;). And the True^False will remain True, so 'variable' True remains truthy.
Then we encounter the first True input, which will also be printed. After that, the True^True will evaluate to False, so the 'variable' True is from now on falsey.
After that it doesn't matter what our input is anymore, since True is redefined as falsey. So the print b; will always print False at this point. And in addition, the True^=b can now only be False^False, so 'variable' True will remain falsey.

Wow, TIL True can be reassigned. Nice golf!

@SurculoseSputum Yeah, I also didn't knew before seeing xnor's answer. Then again, I think you can reassign most constants in Python. I think I've also seen someone user and overwrite the id constant in another challenge for example.

@KevinCruijssen Nice find, bounty posted! I like how elegant the ^= update is with it becoming harmless after the first True. What makes your find more impressive is that  a lot of voters on my answer apparently didn't think of this, in addition to me.

@xnor Well, most credit still goes to yourself. I wasn't even aware it was possible to use True/False as a variable and redefine their values before I saw your answer. If it wasn't for your bounty post, I would have just suggested it as a -2 bytes comment. :)

@KevinCruijssen I'm pretty sure the redefining of id was also xnor in another of his answers :)

@RGS You're right, he indeed was. :) Here is his answer I was referring to.

Funny, because I was thinking about this @xnor answer :p turns out this must be a recurrent trick, as id is the shortest predefined and reassignable name in Python

@SurculoseSputum always remember to sneak True = random.random() < 0.98 into your colleague's  code ;)

@jaaq That's evil! XD

Retina, 6 bytes
1>`1
0

Try it online!
Input is a list of 0s (for False) and 1s (for True).
Matches all 1 and replaces each except the first one (1>) with a 0.

I can see it now. You working in an office on some OS. A manager comes over and yells at you for writing an entire OS with regex.

I was wondering who left that ^ dumb comment then realized it was me...

Jelly, 4 bytes
+\=a

Try it online!
Here's a rather different algorithm to most of the other golfing language solutions (although after I posted it, I noticed that the R solution also uses this algorithm), and tying with the current Jelly record holder.
Explanation
+\=a
+\    Cumulative sum of the input list
  =   Compare corresponding elements with the input
   a  Logical AND corresponding elements with the input

As long as all elements to the left of an element are 0, the cumulative sum up to an element will equal the element itself. To the right of the first 1, the two are different (because we're now adding the nonzero total of the elements to the left). Thus, +\= gives us a list containing 1 (i.e. true) up to and including the first truthy element. Finally, logical AND with the original list will give us a 1 for only the first truthy element.

V, 7 bytes
f1òf1r0

Try it online!
My first V submission! \o/
How it works
f1òf1r0
f1       "go to the next occurence of 1
  ò      "repeat the following until end:
   f1    "    go to the next occurence of 1
     r0  "    replace with 0

How does this work?

@BrianMcCutchon Explanation added.

This fails for a 1 in the first position :(

@nmjcman101 fixed.

Since you changed the input format, you can swap r0 with <C-x> to decrement the ones and save a byte.

Vim (not so sure about V) also has ; to repeat last t/f jump, likely saving another byte.

05AB1E, 6 bytes
Code:
ā<s1kQ

Explanation:
ā         # External enumeration, get a and push [1 .. len(a)]
 <        # Decrement each
  s       # Swap to get the input
   1k     # Get the first index of 1
     Q    # Check for equality with the enumeration array

Uses the 05AB1E encoding. Try it online!

1k>sƶ-_ is another, worse though. The lift idea may have potential though.

Alternative 6-byter for the legacy: ηO‚øPΘ, which would be 5 bytes in the new version: ηOøPΘ.

Actually, my 6/5-byter above is actually a 4-byter which works in both the legacy and new version: ηO*Θ

Haskell, 25 bytes
Anonymous function taking and returning a list of Bools.
Use as (foldr(\x l->x:map(x<)l)[])[False,True,False,False].
foldr(\x l->x:map(x<)l)[]

Try it online!
How it works

Folds over a list from the right, prepending new elements and possibly modifying those following.
x is the element to be prepended to the sublist l.
Uses that False compares less than True, so map(x<)l will turn any Trues in l into False if x is True.

JavaScript (ES6), 33 26 bytes
a=>a.map(e=>e&!(i-=e),i=1)

I/O is in arrays of 0s and 1s.

Turing machine simulator, 39 bytes
0 0 0 r 0
0 1 1 r 1
1 0 0 r 1
1 1 0 r 1

Try it online!

Essentially the same thing I'm doing in my answer.

J, 3 bytes
</\

Defines a monadic verb.
This is a trivial port of my APL answer.
Try it online!

Jelly, 4 bytes
A port of my 05AB1E answer.
i1=J

Explanation (argument α):
i1        # Index of 1 (1-indexed) in α
  =       # Check for equality with the array:
   J      # [1 .. len(α)]

Try it online!

brainfuck, 55 bytes
+>,[[->+>[->-<]>+[-<+>]<<<]>>[-<-<<[->>+<<]>>>]<.[-]<,]

Try it online!

Perl 5, 20 bytes
sub{map$_&&!$x++,@_}

Truthy is 1 and falsey is '' (an empty string).
Explanation:
map loops over elements of the list it @_, the arguments passed to the subroutine, setting each element to $_ locally and returning an array of the return values it computes from each element. $_&&!$x++ outputs $_ if $_ is falsey and !$x++ if it is truthy. (Note that && is short-circuiting, so !$x++ is not executed until the first truthy value is reached). $x++ returns 0 (which is falsey) the first time it is run and then increments every time (and so remains truthy). The ! negates $x++, and so it returns truthy the first time it is encountered and falsey thereafter.

R, 24 bytes
cumsum(T<-scan(,F))==T&T

Try it online!
Example:
For input FALSE TRUE TRUE FALSE
cumsum(T<-scan(,F))==T returns TRUE TRUE FALSE FALSE.  The F in the scan ensures logical input.
FALSE TRUE TRUE FALSE and TRUE TRUE FALSE FALSE is FALSE TRUE FALSE FALSE. A single & does an elementwise comparison.

@rturnbull unfortunately the input format has to be the same as the output.

cumsum(scan(,F))==1 works for 19 bytes.

Octave, 23 bytes
@(a)diff([0 cummax(a)])

Try it online!
First difference of cumulative max of the list.

Python, 58 bytes
lambda x:[x[i]and x.index(x[i])==i for i in range(len(x))]

If x[i] is false, the output is false; otherwise, it gives whether or not the element is the first occurence in the array of itself.

PHP, 37 bytes
foreach($_GET as$v)echo$v*!$$v++,' ';

Jelly, 4 bytes
TḊṬ^

Try it online!
How?
This does what was asked in a pretty literal sense:
TḊṬ^ - Main link: list a   e.g. [0,1,0,1,0,0,1]  or  [0,1,0,1,0,1,0]
T    - get the truthy indexes   [  2,  4,    7]      [  2,  4,  6  ]
 Ḋ   - dequeue                  [      4,    7]      [      4,  6  ]
  T  - make a boolean array     [0,0,0,1,0,0,1]      [0,0,0,1,0,1  ]
   ^ - XOR that with a          [0,1,0,0,0,0,0]      [0,1,0,0,0,0,0]

unsure, 222 bytes
hm um err wait oops um but oops yeah umm err heh well wait oops then but heh wait oops no um um yeah err heh um but oops oops um heh well wait oops then um but oops yeah um err heh well wait then um but oops okay well wait

Unsure is a stack based esolang I recently created. This answer takes input as a string of 0x00 and 0x01 bytes.
First, here's the code broken into more readable sections:
hm um err wait oops

um but oops yeah umm err heh well wait oops then

but heh wait oops no um um yeah err heh

um but oops oops um heh well wait oops then

um but oops yeah um err heh well wait then

um but oops okay well wait

The first section is a loop, which first reads input (hm), and adds one (um err). The wait instruction usually ends a while loop, but because there is nothing to start the loop it defaults to the beginning of the program. Because it's adding 1 to each input, and EOF is -1, the loop will end once it reaches EOF with an additional 0 on the stack, which is discarded by oops.
The next line is a loop through the entire stack. For the first iteration, the stack length is unneeded, so it pushed 1 with um. The but starts a loop, and the oops discards the stack length. It then negates the top of the stack (yeah) and adds two (umm err, essentially the inverse of the input). It finally pushes this to the other stack (heh) and pushes the length of the current stack (well). Once the loop ends, the extra 0 is discarded and then switches the active stack.
The next line consists of two parts: but heh wait oops no (a simple loop which pops items to the other stack until one is 0), then um um yeah err heh which pushes 0 to the other stack.
It then pads the other stack to the right length with 1s (um but oops oops um heh well wait oops) and switches to the other stack (then). This is necessary because the output would be backwards otherwise. The other stack does about the same thing, but inverts each item by negating it and adding one (yeah um err).
Finally, the um but oops okay well wait loop just uses okay to output each item in the stack.

Pyth - 9 bytes
.e&b!s<Qk

Try it here
.e&b!s<Qk
.e          # Python's 'enumerate' (i.e., for each index k and each element b at that index)
      <Qk   # The first k elements of the input
     s      # 'Sum' these first k elements (with booleans, this is a logical 'or')
  &b!       # The value of the output at index k is [value of input @ index k]&&[the negation of the 'sum']

It seems to be more efficient to use a variable and just map over it normally: m&!~|Z.

Python 2, 45 36 bytes
r=0
while 1:n=input();print n>r;r+=n

Input and output are one Boolean (True or False) per line.
Try it online!

Python 3, 69 66 64 60 54 53 bytes
lambda i:[k==i.index(j)and j for k,j in enumerate(i)]

Takes an array of falses and trues. This is a list comprehension of falses except if the current iteration's value is true and it is the first true in the input.
This seems a little long (and it's my first lambda), so if you can find a way to golf it, it would be greatly appreciated!

Can you explain?

Oh, oops, misinterpreted the question.

Undeleted and fixed the answer

You can save one byte by making 0 for 0for.

It works for 1if and 1else, right? Thanks!

1if i.index(j)==k and j==1else 0 -> i.index(j)==k and j would work the same if the input is a Boolean vector

Doesn't even have to be a boolean because python is awesome. Thanks!

I think @FelipeNardiBatista meant the whole thing, not just the ==1.

@OldBunny2800 what i meant is that it it a lot shorter

i.index(j)==k and => k==i.index(j)and.

Idris, 98 bytes
The code is a bit longer, but on the plus side you get the compile time guarantee that the output has the same size as the input!
import Data.Vect
f:Vect n Bool->Vect n Bool
f[]=[]
f(x::y)=x::if x then replicate _ False else f y

I'm going to give an extensive explanation to have you understand the basic workings of Idris.
Explanation
import Data.Vect

The type Vect : Nat -> Type -> Type is not imported by default
f : Vect n Bool -> Vect n Bool

Contrary to Haskell, Idris uses a single colon : to specify types and also requires you to specify the type, as the dependent type checker can't possibly infer it in all cases. Since Vect takes a Nat (natural number) and a Type, we provide just that, n being a natural number and Bool being the type. Even though we didn't specify the type of n explicitly, Idris can infer it to be Nat. Since n occurs both in the argument and the resulting type, they need to be the same.
f [] = []

As the base case, the empty list returns the empty list. This is the only possible implementation, anything else such as f[]=[True] would give a compiler error, since the type of [] is Vect 0 Bool but the type of [True] is Vect 1 Bool.
f (x :: y) = x :: if x then

:: is used as the cons operator in Idris, similar to : in Haskell. We put the first element in the resulting list, unchanged.
  replicate _ False else

If the first element is true, we want the rest of the list to be false in any case, so we just replicate the value False. Since Idris knows that the rest of the list has to have the same size as y, it can infer the value of _ (namely length y).
  f y

If the first element is false, we just move on by recursively calling the function on the rest.

C#, 77 bytes
a=>{var b=1<0;for(int i=0;i<a.Length;){a[i]=b?1<0:a[i];b|=a[i++];}return a;};

Compiles to a Func<bool[], bool[]>. Nothing clever really, just a straight forward solution.

Batch, 85 73 bytes
:a
@(if %1.==. exit)&set/ar=(1-f)*%1
@echo %r%&set/af^|=%1&shift&goto a

Takes input as command line arguments. For eample: 1.bat 0 1 0 1 0 0 1
Previous version
@set f=1
:a
@(if %1.==. exit)&set/ar=f*%1
@echo %r%&(if %1==1 set f=)&shift&goto a

sed, 16 19 bytes
15 18 bytes sourcecode + 1 byte for -r flag (or -E flag for BSD sed).
:
s/1(0*)1/1\10/
t

Try it online!
Edit: Thanks Riley for pointing out a mistake.

@Riley Thanks for pointing that out! It looks like TIO has a version of sed that is different from mine (BSD). I can't leave the labels empty. Good to know this.

Yeah, sorry. TIO uses GNU sed. It's a bug turned feature.

Brain-Flak, 146 144 bytes
([]){{}({}<>)(())<>([])}{}<>((())){{}({}<>)<>}{}<>(()){{}((){[()](<{}>)}{})(<>)<>}<>(())<>([]){{}(<{}<>>)<>([])}{}<>{}{}([]){{}({}<>)<>([])}<>{}

Try it online!
# Reverse the stack and add a 1 between each to help with reversing later
([]){{}({}<>)(())<>([])}{}<>

# Add a 1 in case there aren't any truthy values (and another 1 like before)
((()))

# Reverse the stack back to it's original order using the 1s from earlier to know when to stop
{{}({}<>)<>}{}<>

# Push 1 to start the loop
(())

# Until we find the first 1
{

 # Pop the last value
 {}

 # Logical not
 ((){[()](<{}>)}{})

  # Put a 0 on the other stack
  (<>)<>

# end loop
}

# Put a 1 on the other stack
<>(())<>

# Push the stack height
([])

# While there are values on this stack
{

 # Move them to the other stack as a 0
 {}(<{}<>>)<>([])

# End while
}{}

# Pop an extra 0
{}

# Switch stacks
<>

# Copy everything back (to reverse it back to it's original)
([])
{
 {}({}<>)<>([])
}<>{}

c (with gcc builtins), 40
A slightly different approach:
f(n){return!n?0:1<<31-__builtin_clz(n);}

This may be ruled invalid - in which case I will happily mark this as non-competing.
Input and output "arrays" are 32-bit unsigned integers - this limits the input list size to be exactly 32 - this may be a disqualifier.  If the input is less than 32 bits long, then it may be padded with zero bits at the end.
Try it online.

x86 assembly instructions, 12 bytes
31 c0 0f bd cf 74 04 ff c0 d3 e0 c3

Or in gcc assembly:
    .globl  f
f:
    xor     %eax, %eax
    bsrl    %edi, %ecx
    je  .L2
    inc     %eax
    sall    %cl, %eax
.L2:
    ret

This is a translation of my c answer and has the same I/O specs.
Try it online.

Javascript, 25 bytes
x=>x.map(c=>c&&x&&!(x=0))

x holds the original array.
Once the first truthy has been found, x is overwritten with a false value.
This makes c && x return false for all values except the first truthy.

Brain-Flak, 230 bytes
([]){{}({}[()]<>)<>([])}{}<>([]){{}({}<>)<>([])}{}<>({<({}<>)<>>()}<(())>){({}[()]<<>({}<>)>)}{}(([])<{{}(({})())({<{}>{}((<()>))}<{}{}>)({}<>)<>([])}<>>){({}[()]<({}<>)<>>)}{}<>([]){{}({}<>)<>([])}{}<>{}{}([]){{}({}<>)<>([])}{}<>

I will explain soon but my mom cooked me some fried potatoes
([]){{}({}[()]<>)<>([])}{}<>([]){{}({}<>)<>([])}{}<> Subtracts one from every item

({<({}<>)<>>()}<(())>){({}[()]<<>({}<>)>)}{} Loops down stack until current item is zero and adds one

(([])<{{} (({})())({<{}>{}((<()>))}<{}{}>) ({}<>)<>([])}<>>){({}[()]<({}<>)<>>)}{}<> On every item of stack if it is 0 do nothing and if it is -1 add one

([]){{}({}<>)<>([])}{}<> Flip stack

{}{} Remove the two zeros at top of stack

([]){{}({}<>)<>([])}{}<> Flip stack back

Try it online!
Special thanks
Special thanks to Wheat Wizard and Riley for helping me a ton with code!

Perl 5, 12 bytes
10 bytes code + 2 for -pl.
$_&&=!$-++

Try it online!

Jelly, 3 bytes
ŒQa

Try it online!
ŒQ was added to the language about two months after the previous Jelly solution.
ŒQ     Nub sieve: for each element, is it the first occurrence of that value?
  a    Take the logical AND of that and the original list.

user62131's solution can also be 3 bytes with a newer builtin:
Jelly, 3 bytes
Ä=a

Try it online!

tinylisp, 63 bytes
(d F(q((L B)(i L(c(i B(h L)0)(F(t L)(i(h L)0 B)))(
(q((L)(F L 1

The solution is the anonymous function in the second line; the first line is a helper function. Try it online!
Ungolfed/explanation
(load library)                 ; Library contains ungolfed aliases for builtins

(def F                         ; Define F
  (lambda (L B)                ; as a function that takes a list L and an int B (where B
                               ; is a flag indicating if we're in the beginning section):
    (if L                      ;  If L is nonempty:
      (cons                    ;   Prepend
        (if B (head L) 0)      ;   head of L if B is truthy, else 0
        (F                     ;   to a recursive call
          (tail L)             ;   with tail of L as the new list
          (if (head L) 0 B)))  ;   and 0 as the new flag if head of L is truthy, else B
      nil)))                   ;  Else, return empty list

(lambda (L)                    ; Anonymous function that takes a list
  (F L B))                     ; and passes it to F with a second argument of 1

Cubix, 14 bytes
W;@.1I?>O;w..W

Try it online
Cubix doesn't have proper lists or booleans, so we take the input as a sequence of space-separated 1s and 0s terminated with a -1.
Unfolded
    W ;
    @ .
1 I ? > O ; w .
. W . . . . . .
    . .
    . .

Explanation
The instruction pointer starts at the top of the left face of the cube, moving to the right.
Initially, we push a 1 onto the stack.  We then take one input at a time, with I and branch with ?.
If the input is 0, we see O;, which outputs 0 and pops it from the stack.
If the input is 1, we see ;O;, which pops the 1 from the stack, outputs the top of the stack (which will be 1 the first time around), then pops it from the stack.
If the input is -1, we see @, which ends the program.

Ruby, 32 bytes
->a{i=1;a.map{|x|x&&[i,i=p][0]}}

Uses 1 for truthy and nil for falsy.
Explanation
->a{           # take an array a
    i=1;       # use i to keep track of if we've gotten a truthy value yet
    a.map{|x|  # for each element x in a:

        x&&[     # if x is truthy:
              i,     # remember the old i,
              i=p    # then set i to false
           ][0]      # and replace x with the old i
    }
}

vim, 19 keystrokes
2/1<ENTER>i<ENTER><ESC>:s/1/0/g<ENTER>kJx

2/1<ENTER>i<ENTER><ESC> puts everything after the first 1 to the second line and moves the cursor to that line.  :s/1/0/g<ENTER> replaces the 1s with 0s.  kJx then merges the lines.

Perl 6, 19 bytes
{@_ «&&»[\^^] @_}

This is an anonymous function that takes its arguments in @_.  ^^ is the exclusive-or operator, and [\^^] does a scan using that operator, returning a copy of the input list where the first truthy value is replicated until the second truthy value, whereupon it and all remaining values become Nil (which is falsy).  To falsify the replicated copies of the first truthy value, if any, the list is combined with the original using &&, the boolean and operator.

F#, 79 76 72 bytes
let rec f o=function|[],_->o|x::y,1->f(o@[0])(y,1)|x::y,_->f(o@[x])(y,x)
Try it online!
Usage
let input = [0;0;0;0;1;1;0;0;1]
printfn "%A" f [] (input, 0)

Explanation
This is a very straightforward implementation.
f is a function with two arguments, first being the result list and the second a tuple of input and a value indicating if a truthy value has been found.
Note: only 1 is considered truthy, every other number is falsy. Which sounds weird now that I think about it. This however, can easily be changed so that any value <> 0 is truthy. But I think it should be ok the way it is, as expected input is only 0 or 1
// int list -> int list * int -> int list
let rec f output = function
| [], _ -> output                      // return result
| x::xs, 1 -> f (output@[0]) (xs,1)    // if truthy was encountered before, append 0 to result, process rest of input
| x::xs, _ -> f (output@[x]) (xs,x)    // if not, append 0 or 1 to result, process rest of input

Scala, 44 bytes
s=>{var b=1>2;s.map{x=>if(b)!b else{b=x;x}}}

PowerShell, 29 bytes
$args|%{$_-and!$b;$b=$b-or$_}

Try it online!

OCaml, 85 60 bytes
let rec f?(b=true)=function h::t->(h&&b)::(f~b:(h<b)t)|_->[]

Ungolfed
let rec f ?(b=true) = function
    | head :: tail -> (head && b) :: (f ~b:(head<b) tail)
    | _            -> []

Explanation
f is defined as a recursive function taking an optional (?) boolean b and an unnamed list (function) and return according to the cases:

if the first element of the list is false, returns it unchanged,
if the first element if the list is true, sets it to b and flip b to false (id est, only let unchanged the first true since b is true by default and then set to false),
if the list is empty (end of recursive call), returns the empty list.

Usage
Try it online (you'll need to copy/paste the function definition) !
# f [];;
- : bool list = []
# f [false];;
- : bool list = [false]
# f [true];;
- : bool list = [true]
# f [false;true;true;false;true;true;false;true;false;false];;
- : bool list =
[false; true; false; false; false; false; false; false; false; false]

History
25 (yes, twenty-five) bytes golfed off by Ørjan Johansen, suggesting to merge the first two cases (see explanation).

You can merge the first two cases: let rec f?(b=true)=function c::t->(c&&b)::(f~b:(c<b)t)|_->[].

@ØrjanJohansen Thanks, that's 25 bytes golfed!

PHP, 34 bytes
foreach($_GET as$g)echo$f?0:$f=$g;

Try it online!

CJam, 10
{_1#\,,f=}

Try it online!
Explanation:
This is a function that takes an array of 0 and 1 from the stack, and pushes the resulting array on the stack.
_      duplicate the array
1#     find the index of the first 1 (it is -1 if not found)
\      swap with the other copy of the array
,      get the array length, let's call it n
,      make an array [0 1 … n-1]
f=     compare each element with the index we got earlier

[Python 2], 83 68 bytes
I try classic approach.
def t(l,b=1>0):
 r=[]
 for x in l:r+=[x and b];b=(1-x)*b>0
 return r

I use and boolean operator between each value of list and a value that is true until first truely value in list and false after.
es.
list val. --> F F T F T F F
b         --> T T T F F F F
and op.   --> F F T F F F F

Tanks @AdHocGarfHunter

Welcome to the site.  Three improvements I see right away are 1) You can put r=[] in the function arguments just like b=True 2) False is shorter as 1<0 and True as 1>0 3) Your whole if then bit is just not x and b which can be rewritten as (1-x)*b>0.

@AdHocGarfHunter Tanks. There is a problem to side effect of function parameter, if you call more time t function, r accumulate values and b assume False value.

@n1k9 you're right, I think the consensus here is that a function must be reusable. So r=[] must goes in the body. b is immutable, so it can stay in the arguments.

Ruby -nl, 22 bytes
Input is STDIN.
a|=p
p !a&&a|=eval($_)

Try it online!
Explanation
                  # For each line of STDIN:
a|=p              # Set a to falsy if it wasn't defined before
                  #  (needed or else the next line crashes)
p !a&&a|=eval($_) # Output false if a is truthy, otherwise OR it with the value in STDIN
                  #  and output that instead

05AB1E, 5 bytes
ε¾›D½

Try it online!
explanation:
ε for each value in the (implicit) input
¾ push the counter variable
› check if it's bigger than the current value (0 0 - 0, 0 1 - 1, 1 0 - 0, 1 1 - 0)
D duplicate
½ increment the counter variable if it's true (which means that if the current value is 1 and the counter is 0, increment it)

Nice approach. I just had this 5-bytes alternative, which I added as a comment under the existing 05AB1E answer: ηOøPΘ. :)

@KevinCruijssen Isn't that trivially the same as ηO*Θ for 4 bytes? My 5-byter was RƶRZQ (or ƶWQ by bending the I/O rules a bit), interesting how different our three approaches are.

@Grimmy Ah, I'm an idiot. You're indeed completely right that ηO*Θ works for 4 bytes. And another nice alternative! EDIT: And I like that 3-byter, since only 1 is truthy in 05AB1E. xD I actually had something similar with ƶWQ in mind at first, but it obviously failed since 0 is lower. Hadn't thought about using a different falsey value, which technically is valid in 05AB1E, although indeed kinda bending the I/O rules. xD

K (oK), 13 bytes
Solution:
{@[x;1_&x;~]}

Try it online!
Explanation:
{@[x;1_&x;~]} / the solution
{           } / lambda taking implicit argument x
 @[x;    ; ]  / apply func to target at indices @[target;indices;func]
          ~   / not, the function being applied
       &x     / indices where x is true
     1_       / drop the first occurrence

Python 3, 52 46 44 38 bytes
Input is a list of bools, requires Python 3.8 (for the walrus operator :=).
lambda x,b=0:[a>b and(b:=a)for a in x]

To be called as (lambda x,b=0:[a>b and(b:=a)for a in x])(bools_list)
Previous attempts:
Input is a list of 1s and 0s
lambda x,b=0:[(b:=1)if a>b else 0for a in x]

def f(x):a=[0]*len(x);a[x.index(1)]=1;return a

The above doesn't work with an all-falsey list, list.index throws ValueError if the value isn't present.
Edit: and neither do most (all?) other Python 3 entries, for the same reason.
Input x is an iterable of bools, returns iterable of bools.
map(lambda a,b=[0]:not(b[-1]or b.append(a)or 1-a),x)

Fig, \$6\log_{256}(96)\approx\$ 4.939 bytes
=1*eSk

Try it online!
cumsum builtin when

cumsums == Y@S

@Seggan that's no shorter than eSk

PHP, 61 Bytes
$n=[];foreach($_GET as$v)$n[]=$n&&max($n)?0:$v;print_r($n);

Try it online!

Japt, 7 bytes
®?!T°:Z

Try it online!

ReRegex, 18 bytes
1(0*)1/1$10/#input

Fairly simple solution, ReRegex takes all pairings of 1(0*)1, which is two 1s with any amount of 0s in between, and just leaves the first 1, replacing the second with a 0. As ReRegex keeps running the regex until no more change happens, which satisfies the challenge.
Try it online!

This solution removes ones from the input, but I believe the challenge asks to turn them into zeros. This can be fixed by adding a final 0 to the substitution pattern

77 Bytes, Javascript

var s=0;[0,0,0,1,0,0].forEach(function(c,i,a){if(c||s)s=c=1;console.log(c)});

I/O are zeros and ones.

F#, 88 bytes
let c2 u=
 let n=ref(1<0)
 [for i in u do if !n||not i then yield 1<0 else n:=i;yield i]

Use as follows:
let mutated = c2 [true; true; false; false; true]

or
printfn "%A" (c2 [true; false; true; false; true])

AWK, 31 bytes
BEGIN{ORS=RS=" "}$1{$1=t-->-1}1

Try it online!
Assumes input is space-separated 1 and 0. Most of the code is just splitting the records on  for input and output.  The variables could be assigned via command-line options, but it only saves a couple bytes and TIO doesn't count them. :(
BTW
BEGIN{ORS=RS=" "}$1&&t++{$1=0}1

also works, but I find it a bit harder to read and has the same byte-count, anyway.

Chip, 10 bytes
,.
`z.
a\A

Try it online!
How?
The elements a\A will copy the lowest bit of input (A) to the lowest bit of output (a) so long as the switch is inactive (\).
When A is powered, due to a truthy input, it activates the delay element (z) via a wire (.). This delay element will wait one cycle -- that is, until the next input byte -- at which point it will send the signal onward. This activates the switch, cutting off the input from the output, and via some more wires (` , .) activates itself for the next cycle.
If you change the normally-closed switch \ for a normally-open switch /, you'd get a circuit that filters out only the first truthy value.

Retina, 16 bytes
+T`1`0`(?<=1)0*1

Try it online! My first Retina submission ever.

0*1 can be replaced with .*

C++, 77 75 bytes
Yay pointers and memset!
void f(bool*a,int b){bool*c=&a[b];while(a<c)if(*a++)break;memset(a,0,c-a);}

Function takes in a pointer to a bool array, and the length of that array as parameters.  It loops through the array until it finds the first true, increments one more cell, and memsets the remainder of the memory from that pointer until the end.  0 length arrays work too since the loop is skipped entirely and the memset gets 0 bytes as the length, however passing in null instead of an empty array will break things.
Ungolfed + tests
#include <iostream>
#include <cstdlib>
#include <cassert>

//void f(bool*a,int b){bool*c=&a[b];while(a<c)if(*a++)break;memset(a,0,c-a);}

void f(bool* a, int b)
{
    bool* c = &a[b];
    while (a < c)
        if (*a++)
            break;
    memset(a, 0, c - a);
}

void print(bool* a, int b)
{
    for (int i = 0; i < b; i++)
    {
        std::cout << a[i] << '\t';
    }
    std::cout << std::endl;
}

int main()
{
    size_t s = sizeof(bool);
    assert(s == 1);
    bool* t1 = new bool[5] { false, false, false, false, false };
    bool* t2 = new bool[0];
    bool* t3 = new bool[6] { false, false, true, false, true, true };
    bool* t4 = new bool[10] { true, true, true, true, true, true, true, true, true, true };
    f(t1, 5);
    f(t2, 0);
    f(t3, 6);
    f(t4, 10);
    print(t1, 5);
    print(t2, 0);
    print(t3, 6);
    print(t4, 10);
    delete[] t1;
    delete[] t2;
    delete[] t3;
    delete[] t4;
}

Befunge-98, 19 bytes
&:1`#@_1*:.70g\-70p

Try it online!
Input: stream of numbers, 0 (false), 1 (true), or 2 (EOF).
Output: stream of numbers, 0/1.
Explanation
The program works by reading the next number in a loop, multiplying it by a constant, and printing the result to stdout. The operation described in the problem statement is performed by modifying that constant:
&:1`#@_1*:.70g\-70p
       ^          v
       [ P[7]-= x ]

Processing.js  (Khanacademy version), 67 bytes
var a=[];for(var i=0;i<a.length;i++){if(i!==0){a[i]=0;}}print(a);

A is the input (khanacademy version of processing has no real input method)
The output is printed to console. Truth = 1, false = 0;
Try it online!

Whitespace, 66 bytes
[S S S N
_Push_0][N
S S N
_Create_Label_LOOP][S N
S _Dupe_0][S N
S _Dupe_0][S N
S _Dupe_0][T    N
T   T   _Read_STDIN_as_integer][T   T   T   _Retrieve_integer][T    S S T   _Subtract][N
T   T   S N
_If_negative_Jump_to_Label_FIRST_TRUTHY][S S S N
_Push_0][T  N
S T _Print_as_integer][N
S N
N
_Jump_to_Label_LOOP][N
S S S N
_Create_Label_FIRST_TRUTHY][S S S T N
_Push_1][S N
S _Dupe_1][T    N
S T _Print_as_integer][N
S N
N
_Jump_to_Label_LOOP]

Letters S (space), T (tab), and N (new-line) added as highlighting only.
[..._some_action] added as explanation only.
Try it online (with raw spaces, tabs and new-lines only).
The input is newline separated, and the output is all joined together. If this is not allowed, it's 80 bytes (both newline separated) or 82 bytes (both joined together) instead.
Uses 1 for truthy and 0 for falsey.
Explanation in pseudo-code:
Integer flag = 0
Start LOOP:
  Integer input = STDIN as integer
  If(flag - input < 0):
     Jump to Label FIRST_TRUTHY
  Print 0 as integer to STDOUT
  Go to next iteration of LOOP

FIRST_TRUTHY:
  flag = 1
  Print 1 as integer to STDOUT
  Go to next iteration of LOOP

Kotlin, 31 bytes
{List(size){it==indexOf(true)}}

{                             }  // lambda; input is `this`
 List(    )                      // build new list
      size                       // same size as input
           {                 }   // based on lambda
            it==                 // index of this element equal to
                indexOf(true)    // index of first true in input

To actually solve this challenge you only need to know two things about the input:

its length
where the first true is.

The shotgun approach of just generating a new list worked out best here.
Try it online!

Io, 38 bytes
method(x,x map(i,v,i==x indexOf(1<2)))

Try it online!
Explanation
method(x, // Take an operand x
    x map(i,v, // Map every item with index/value
        i==    // Is the index equal to
        x indexOf(1<2) // the index of true in x?
    )
)

sed, 8 bytes
0,/./!c

Try it online!
Note the trailing linefeed.
Inputs are linefeed separated. Any single character is truthy (I used 1) and an empty line is falsey.
Input should not have a trailing linefeed, as that will be interpreted as an extra falsey value. Note that TIO adds a final linefeed, and thus a falsey value, at the end. This is a limitation of TIO, the program works just fine without.
Commented:
0,/./ #Run the following commands from the first line to the first line containing a character
#If we are *not* in the previous range, replace the line with an empty line
!c

To make it easier to read the output, you can make 0 falsey and replace the program with
0,/1/!c0

at the cost of one byte. Try it online!

Vyxal, 3 bytes
¦=*

Try it Online!
Explained
¦=*
¦   # cumulative sum
 =  # equal
  * # multiply bits

ÞU* would also work

BQN, 3 bytes
×⟜∊

Anonymous tacit function; takes and returns a list of 0's and 1's. Try it at BQN online!
Explanation
  ∊  Mark firsts: a list the same length as the argument, containing 1 at the first
     occurrence of each element of the argument and 0 for subsequent occurrences
×⟜  Multiply by the argument, itemwise

Nice. An alternative would be ⊢×∊ right? And makes me wonder why there's no APL answer here: ⊢×≠. Hopefully, we'll be able to write your solution as ≠⍛× soon.

Yes; ∊⊸× also works, and × can be replaced with ∧ or ⌊ in any of them.

Go, 129 bytes
func f(i[]int)(o[]int){k:=0
for _,e:=range i{if e>0&&k<1{k=1
o=append(o,1)}else if k>0{o=append(o,0)}else{o=append(o,e)}}
return}

Attempt This Online!

x86-64 machine code, 9 bytes
56 59 31 C0 F3 AE F3 AA C3

Try it online!
Following the standard calling convention for Unix-like systems (from the System V AMD64 ABI), this takes in RDI the address of an array of 8-bit integers and its length in RSI, and modifies it in place, taking 0 as a falsy value and any nonzero value as a truthy value.
In assembly:
f:  push rsi; pop rcx   # Put the length into RCX.
    xor eax, eax        # Set EAX to 0. In particular, its low byte AL is 0.
    repe scasb  # Read bytes from the array and compare them with AL,
                #  advancing the pointer and counting down from the length in RCX,
                #  stopping when the comparison result is not equal or RCX is 0.
    rep stosb   # Repeatedly write AL into the array, advancing the pointer,
                #  and counting down RCX, stopping when RCX is 0.
                # This writes 0 into all the remaining places.
    ret         # Return.

TI-Basic, 7 bytes
Ans and 1=cumSum(Ans

Takes input as Ans (last input value)

Thunno 2, 3 bytes
ṡ=&

Attempt This Online!
Explanation
ṡ=&  # Implicit input      ->  [0,1,0,1,0,0,1]
ṡ    # Cumulative sums     ->  [0,1,1,2,2,2,3]
 =   # Check for equality  ->  [1,1,0,0,0,0,0]
  &  # Logical AND         ->  [0,1,0,0,0,0,0]
     # Implicit output

PowerShell, 25 bytes
$args|%{$_-and!$f;$f+=$_}

Previous "non legal" version
{$_*!$f;if($_){$f=1}}

Try it online!
The one more version with the same length of 25 bytes
$args|%{!!$f-lt$_;$f+=$_}

Try it online!

Is this a legal answer? I am honestly not sure. You cannot run this on its own as a function or program. It is a process scriptblock for the foreach-object cmdlet. I would have expected you to use $args

@Matt I would say no, it's not legal.

@briantist Well that is good then. I don't feel the need to go back to my old answers now.

@Matt here's the relevant clarification for PowerShell specifically.

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


text:
Filling space with pursuit polygons
Make a program which can fill a 2D space with "pursuit polygons".
The following picture will help you understand better what I mean.

You can also look up "pursuit curves" or mice problem.
You can use any convex n-polygon you like
here are some examples
Triangle:

Square:

Pentagon

notice that for every polygon you can also use the "anti-clockwise" version of the polygon, which produces interesting results

Can you find a way to divide and fill a given space with pursuit polygons?
The result would look better if this could work with ANY convex polygon and not only the regular polygons that I used...
EDIT
I am new here, so I'll try some specifications:
RULES
You must fill an A4 page ( 2480 Pixels X 3508 Pixels)
You can use only triangles,4-gons and pentagons.(try some of them to have anti-clockwise rotation)
Fewest bytes wins.
Use at least 10 polygons and at most 20
All the polygons must be convex
The borders must be the sides of the polygons.So the polygons must fit perfectly in the given rectangular space.
The algorithm must create RANDOM patterns but you should try to keep the polygons all about the same size and make the polygons as regular as possible.
Sorry for the edits

Hi Jenny, welcome to PPCG. Your question needs an objective winning criterion. One possibility is popularity contest (most votes wins) but that would almost certainly get closed as an art contest. The other possibility is code golf (fewest bytes wins) but you need to make the output far more specific for that. Note that you can post challenges in the sandbox before they go live:   https://codegolf.meta.stackexchange.com/q/2140/15599 . Upvoting and temporary closevoting while you fix the spec to avoid invalid answers

(Just a suggestion - I think a tesselation of random triangles would be a good way to go for codegolf.) Be sure to specify minimum sizes and numbers of polygons whatever you do.

This is a really interesting idea for a challenge, but as mentioned it needs an unambiguous specification before it will be ready. One thing that isn't clear to me is whether the 2D space to be filled is specified as an input, or is a fixed aspect of the challenge.

There appear to be more interesting ideas here than can fit into a single challenge - it might be better as a series of different challenges on a theme. In addition to the mentioned sandbox, I recommend dropping into The Nineteenth Byte chatroom to discuss the different ways of turning the ideas into objective programming challenges.

The spec is looking much better already. What should we do at the edge of the canvas? Your examples have whitespace around them, because they are not rectangular. There are 3 possibilities: 1.Allow a border area of specified width 2. extend the design beyond the canvas, so the canvas becomes a window 3.make the design perfecty rectangular. Also - I think you want some randomness? You'll get fixed designs unless you ask for random, because random costs bytes. Specifying random can be a bit of a minefield sometimes though...

Thank you very much for your help. I'll make one more edit

@trichoplax related https://codegolf.stackexchange.com/q/77492/15599 but the links cited there are even more related.

As Level said, randomness is a minefield. I'm not sure how to objectively decide whether an answer follows the requirement "the algorithm must create RANDOM patterns but you should try to keep the polygons all about the same size and make the polygons as regular as possible".

source: Stack Exchange

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

sort: votes


text:
Create a black window with as little memory as possible
Today I installed MonoGame and ran the test application, which creates a basic colored window. I was surprised to see that the process was using 32.2 MiB of memory, and I thought it could be improved.

Your challenge is to write a program that creates a 640 by 480 window displaying only black pixels. Whatever program uses the least physical memory to do so wins. You may use any operating system released after the year 2000.

I suppose we cannot shut down the computer?

[tag:restricted-memory] is not the right tag for this. I proposed a challenge type for memory golf a while back, but the community hasn't yet come up with a good, fair way to measure memory. For the time being, I'm going to replace the tag with [tag:code-challenge].

If memory cannot be reliably measured, this could make a nice code-golf challenge

This is why this site sucks. I ask a clear question, nobody complains about it or asks for clarification, yet it is put on hold.

@EMBLEM: The problem is the scoring criterion. How to you measure memory? When do you measure memory? Peak usage? Usage after a while of doing nothing and stabilising? I've got six different memory measurements alone on a process on Windows. Which one is the one to report here?

@Joey Great, I'm glad you told me that! Now I can go back and improve the question. If only the five close voters had done the same thing.

C, 96KiB
Never seen restricted-memory but i guess code length doesn't matter here. RAM usage was taken from gnome-system-monitor (i hope it's accurate).
#include <stdlib.h>
#include <stdio.h>

#include <xcb/xcb.h>

int main ()
{
  xcb_connection_t    *c;
  xcb_screen_t        *screen;
  xcb_drawable_t       win;
  xcb_generic_event_t *e;
  uint32_t             values[2];

  char string[] = " ";

  c = xcb_connect (NULL, NULL);
  screen = xcb_setup_roots_iterator (xcb_get_setup (c)).data;
  win = screen->root;

  win = xcb_generate_id(c);
  values[0] = screen->black_pixel;
  values[1] = XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_KEY_PRESS;
  xcb_create_window (c,XCB_COPY_FROM_PARENT,win,screen->root,
  0, 0,640,480,10,XCB_WINDOW_CLASS_INPUT_OUTPUT,screen->root_visual,XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK, values);

  xcb_map_window (c, win);
  xcb_flush (c);

  while ((e = xcb_wait_for_event (c))) {
    switch (e->response_type & ~0x80) {
    case XCB_EXPOSE:
      xcb_flush (c);
      break;
    }
    free (e);
  }
  return 0;
}

This code works on pretty much every linux with a running xserver. To compile add -lxcb for the xcb libs.

This is why Linux > Windows, the Windows equivalent using WinAPI + GDI uses 1.4MB

According to valgrind, the memory usage always peaks at 12,849,152 bytes when compiled using GCC 5.4.0 (with only your -lxcb; -Os doesn't do anything) on my system during the xcb_connect call (and then returns to around 100kiB while the window is being displayed.)

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


text:
Implement the Fibonacci-quine
A Quine is a program which outputs its source when run.
In this challenge, You should make a Fibonacci-quine, a variant of the quine.

What is a Fibonacci-quine?
A Fibonacci-quine is a program, which outputs a modification of the source by the following rule:
The initial source should be ...2.... In other words, the source should contain 2. (Why 2? If it was 1, Nobody would know if it was the first 1 or the second, Even the program itself)
When run, You should output the source, but only the specific number (In this stage, 2) changed to the next number of the fibonacci sequence. For example, ...3.... Same goes for the output, and the output of the output, etc. You may support integers for up to 2^32-1. For integers over that limit, the next output is on your choice.

OP's note
I would really like to see a creative solution for this. I couldn't think of a single solution for this, since Both of the two important aspects of the challenge, fibonacci and quine, is not easy. I'll be waiting then!

Related.

The quine part doesn't add much to this challenge. This is just "next value in Fibonacci sequence" plus a universal quine constructors, as the answers show.

I agree. I would like to see a creative solution for this as well. But if you want a creative solution so bad, then why not make it a code-challenge instead of code-golf. The winning criteria could be the highest number of votes after some time interval or something.

@FixedPoint What about a 'Second criteria'? Someone makes a creative solution, I give them bounty.

@FixedPoint That's a [tag:popularity-contest]

Mathematica, 61 bytes
ToString[#0 /. v:2 :> RuleCondition[Round[GoldenRatio v]]] &

Note that there is a trailing space. This is a function quine, i.e. the above code evaluates to an unnamed function which, if called returns the code itself as a string (with 2 changed to the next Fibonacci number).
This was suprisingly tricky to get to work. The basic idea is to take the function itself (with #0) and replace a number in that function with the next one using /. v:2 :> nextFib[v]. However, nextFib wouldn't get evaluated at this stage so we wouldn't really end up with the new number in the source code. After searching around for a while to figure out how to force immediate evaluation, I found this great post on Mathematica.SE. The "standard" technique uses a With block which forces evaluation, but the second answer by WReach contains a shorter alternative using the undocumented built-in RuleCondition which also forces evaluation.
The way we compute the next Fibonacci number is by making use of the fact that the ratio of consecutive numbers is roughly the golden ratio 1.618... and this is accurate up to rounding. So we don't need to keep track of the last two numbers and can simply do Round[GoldenRatio v]. This will never lose precision since Mathematica's GoldenRation is a symbolic value and therefore Round can always compute an accurate result.
In summary:
... #0 ... &

An unnamed function, where #0 refers to the function object itself.
... /. v:2 :> ...

Find a 2 in the expression tree of the function (this 2 of course only matches itself), call it v and replace it with...
... RuleCondition[Round[GoldenRatio v]]

... the next Fibonacci number.
ToString[...]

And convert the resulting expression tree to its string representation.

It's nice to know you have to work hard at these sometimes :)

Isn't there a symbol for the golden ratio?

@cairdcoinheringaahing no.

CJam, 26 bytes
2{0X{_@+_W$>!}go;\;"_~"}_~

Try it online!
Probably not quite optimal. We simply iterate the Fibonacci sequence until the value is greater than the last one and use the result as the new value at the beginning of the program.

Thi..This early?

Python 3, 95 bytes
a=b=1
while a<2:a,b=b,a+b
s='a=b=1\nwhile a<%i:a,b=b,a+b\ns=%r;print(s%%(b,s))';print(s%(b,s))

Try it online!
Obviously a fork of Martin Ender's CJam answer.

CJam, 20 bytes
2{\5mq)*)Y/io"_~"}_~

Try it online!

Wow, 20 bytes: I'm speechless...

Actually, 19 bytes
2⌠è@fuF$+";ƒ"@+⌡;ƒ

Try it online!
Obviously a fork of Martin Ender's CJam answer.

Python 3, 81 79 bytes
s='s=%r;print(s%%(s,round(%s*(1+5**.5)/2)))';print(s%(s,round(2*(1+5**.5)/2)))

Try it online!
Uses the golden ratio to calculate the next number

Jelly, 14 bytes
“×Øp+.ḞṭØv”Ṙv2

Try it online! or verify all required iterations.
How it works
“×Øp+.ḞṭØv”Ṙv2  Main link. No arguments.

“×Øp+.ḞṭØv”     Set the left argument and return value to the string "×Øp+.ḞṭØv".
           Ṙ    Print a string representation of the return value and yield the
                unaltered return value.
            v2  Evaluate the return value as a Jelly program with left argument 2.
 ×Øp                Multiply the left argument by the golden ratio.
    +.              Add 0.5 to the resulting product.
      Ḟ             Floor; round the resulting sum down to the nearest integer.
        Øv          Yield the string "Øv".
       ṭ            Tack; append the result to the left to the result to the right.

Swift, 251 bytes
A bit verbose for me, but I can't figure out how to get it shorter:
import Foundation;var n="\"";var u="\\";var s="import Foundation;var n=%@%@%@%@;var u=%@%@%@%@;var s=%@%@%@;print(String(format:s,n,u,n,n,n,u,u,n,n,s,n,(round(%f*(1+sqrt(5))/2))))";print(String(format:s,n,u,n,n,n,u,u,n,n,s,n,(round(2*(1+sqrt(5))/2))))

Ungolfed:
import Foundation
var n="\""
var u="\\"
var s="import Foundation;var n=%@%@%@%@;var u=%@%@%@%@;var s=%@%@%@;print(String(format:s,n,u,n,n,n,u,u,n,n,s,n,(round(%f*(1+sqrt(5))/2))))"
print(String(format:s,n,u,n,n,n,u,u,n,n,s,n,(round(2*(1+sqrt(5))/2))))

My trouble is trying to get the quotes around the new version of s.

Javascript (ES6), 151 60 bytes
New version, credits to @Leaky Nun
x=i=>console.log('x='+x+';x('+(i*(5**.5+1)/2+.5|0)+')');x(2)

Old version :
x=i=>{var s=Math.sqrt(5),a=1;f=n=>{return Math.ceil((((1+s)/2)**n-((1-s)/2)**n)/s)};while(f(++a)<=i);console.log('x='+String(x)+';x('+f(a)+')');};x(2)

Based on this.

Welcome to PPCG! We hope that you will have a great time here.

@LeakyNun Hopefully fixed now !

Golfed version: x=i=>console.log('x='+x+';x('+(i*(5**.5+1)/2+.5|0)+')');x(2)

@LeakyNun wow, that's short ! But isn't it too approximate ? it outputs 50159 for i = 31000 although the right answer should be 46368

I don't understand. 31000 isn't a Fibonacci number.

@LeakyNun Yep, i think I misunderstood the question. I thought you needed to output the next Fibonnaci number greater than the input, whether the input is one or not.

So you can use my suggestion now \o/

Cheddar, 136 bytes
let b=1;for(let a=1;a<2;a=b-a){b+=a};let s='let b=1;for(let a=1;a<%i;a=b-a){b+=a};let s=%s;print s%b%@"39+s+@"39';print s%b%@"39+s+@"39

Try it online!

dc, 35 bytes
2[r9k5v1+2/*.5+0k1/n91PP93P[dx]P]dx

A version with iteration (56 bytes):
2[rsP1dsN[lN+lNrsNdlP[s.q]s.=.lFx]dsFxlNn91PP93P[dx]P]dx

Swift, 235 bytes
This is an improved version of Caleb's answer.
import Foundation;var n="\"",u="\\",s="import Foundation;var n=%@%@%@%@,u=%@%@%@%@,s=%@%@%@;print(String(format:s,n,u,n,n,n,u,u,n,n,s,n,(round(%f*(1+sqrt(5))/2))))";print(String(format:s,n,u,n,n,n,u,u,n,n,s,n,(round(2*(1+sqrt(5))/2))))

Java (OpenJDK 8), 239 bytes
interface a{static void main(String[]p){int a=1,b=1;for(;a<2;a=b-a)b+=a;String s="interface a{static void main(String[]p){int a=1,b=1;for(;a<%d;a=b-a)b+=a;String s=%c%s%c;System.out.printf(s,b,34,s,34);}}";System.out.printf(s,b,34,s,34);}}

Try it online!

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


text:
Is magic possible?
A magic square is an n-by-n square grid, filled with distinct positive integers in the range 1,2,...n^2, such that each cell contains a different integer and the sum of the integers in each row, column and diagonal is equal.
Your task is to take an n-by-n matrix consisting of positive numbers, and a placeholder character for empty cells (I'll use 0, but you can use any non-numeric character or datatype you like), and determine if it's possible to make a magic square by filling in the missing numbers
The matrix will be at least 2-by-2, and at most 10-by-10. The smallest possible non-trivial magic square is 3-by-3. The numbers in the input matrix might be higher than n^2, and it's possible that all cells are filled.
Test cases:
2   2
2   0
False

8   0   6
0   5   0
0   9   2
True

16    2    3   13
 5   11   10    8
 9    7    6   12
 4   14   15    1
True

10   0   1
 0   5   9
 3   7   5
False

99    40    74     8    15    51     0    67     0     1
 0    41    55    14     0    57    64     0    98     0
81    47    56    20    22    63    70    54     0    88
 0    28     0    21     0    69    71    60    85    19
 0    34     0     2     9    75    52    61     0    25
24    65    49     0    90    26    33    42    17    76
 0     0    30    89    91     0    39    48     0    82
 6    72    31    95     0    38    45    29     0    13
12    53     0    96    78     0     0     0    10    94
18    59    43    77     0     0    27    36     0   100
True

Hmm. I think I've seen a solution somewhere..

Suggested test case to make sure that the diagonals are tested correctly: [ [ 1, 5, 9 ], [ 6, 7, 2 ], [ 8, 3, 4 ] ] (falsy)

Can we number the placeholders (i.e. [[8, X1, 6], [X2, 5, X3], [X4, 9, 2]])?

@Scott sure, feel free...

JavaScript (ES6), 270 268 bytes
Takes the matrix as a 2D array. Returns 0 or 1.
a=>(g=(x,y=0,w=a.length,p,R=a[y])=>[0,1,2,3].some(d=>a.some((r,y)=>(p=s)^(s=r.reduce((p,v,x)=>(o|=1<<(v=[v,(b=a[x])[y],b[x++],b[w-x]][d]),p+v),0))&&p),s=o=0)||o/2+1!=1<<w*w?R&&[...Array(w*w)].map((_,n)=>(p=R[x])==++n|!p&&(R[x]=n,g(z=(x+1)%w,y+!z),R[x]=p)):r=1)(r=0)&&r

Test cases
This is definitely too slow for the last test case. :-(

let f =

a=>(g=(x,y=0,w=a.length,p,R=a[y])=>[0,1,2,3].some(d=>a.some((r,y)=>(p=s)^(s=r.reduce((p,v,x)=>(o|=1<<(v=[v,(b=a[x])[y],b[x++],b[w-x]][d]),p+v),0))&&p),s=o=0)||o/2+1!=1<<w*w?R&&[...Array(w*w)].map((_,n)=>(p=R[x])==++n|!p&&(R[x]=n,g(z=(x+1)%w,y+!z),R[x]=p)):r=1)(r=0)&&r

console.log(f([
  [ 2,  2 ],
  [ 2,  0 ]
]));

console.log(f([
  [ 8,  0,  6 ],
  [ 0,  5,  0 ],
  [ 0,  9,  2 ]
]));

console.log(f([
  [ 16,   2,   3,  13 ],
  [  5,  11,  10,   8 ],
  [  9,   7,   6,  12 ],
  [  4,  14,  15,   1 ]
]));

console.log(f([
  [ 10,  0,  1 ],
  [  0,  5,  9 ],
  [  3,  7,  5 ]
]));

05AB1E, 45 38 bytes
gn¹à@¹˜āsKœ0ªεÎ˜r.;¹gôD©ø®Å\®Å/)O˜Ë}à*

Also uses \$0\$ as placeholder. The more \$0\$s in the input, the slower the program is. Size of the matrix doesn't matter that much (a 10x10 matrix with three \$0\$s runs quite a bit faster than a 3x3 matrix with seven \$0\$s).
Could have been 4 bytes less, but there is currently a bug in the builtin .; with 2D lists. : and .: work as expected, but .; doesn't do anything on 2D lists right now.. hence the work-around of ˜ and ¹gô to flatten the matrix; use .; on the list; and transform it back into a matrix again.
Try it online or verify some more test cases. (NOTE: Last test case of the challenge description is not included, because it has way too many 0s..)
Explanation:
g          # Get the length of the (implicit) input-matrix (amount of rows)
           #  i.e. [[8,0,6],[0,5,0],[0,0,2]] → 3
 n         # Square it
           #  → 9
  ¹        # Push the input-matrix again
   à       # Pop and push its flattened maximum
           #  → 8
    @      # Check if the squared matrix-dimension is >= this maximum
           #  → 9 => 8 → 1 (truthy)
¹          # Push the input-matrix again
 ˜         # Flatten it
           #  → [8,0,6,0,5,0,0,0,2]
  ā        # Push a list in the range [1,length] (without popping)
           #  → [1,2,3,4,5,6,7,8,9]
   s       # Swap so the flattened input is at the top of the stack again
    K      # Remove all these numbers from the ranged list
           #  → [1,3,4,7,9]
œ          # Get all possible permutations of the remaining numbers
           # (this part is the main bottleneck of the program;
           #  the more 0s and too high numbers, the more permutations)
           #   i.e. [1,3,4,7,9] → [[1,3,4,7,9],[1,3,4,9,7],...,[9,7,4,1,3],[9,7,4,3,1]]
 0ª        # Add an item 0 to the list (workaround for inputs without any 0s)
           #  i.e. [[1,3,4,7,9],[1,3,4,9,7],...,[9,7,4,1,3],[9,7,4,3,1]]
           #   → [[1,3,4,7,9],[1,3,4,9,7],...,[9,7,4,1,3],[9,7,4,3,1],"0"]
ε          # Map each permutation to:
 Î         #  Push 0 and the input-matrix
  ˜        #  Flatten the matrix again
   r       #  Reverse the items on the stack, so the order is [flat_input, 0, curr_perm]
    .;     #  Replace all 0s with the numbers in the permutation one by one
           #   i.e. [8,0,6,0,5,0,0,0,2] and [1,3,4,7,9]
           #    → [8,1,6,3,5,4,7,9,2]
      ¹g   #  Push the input-dimension again
        ô  #  And split the flattened list into parts of that size,
           #  basically transforming it back into a matrix
           #   i.e. [8,1,6,3,5,4,7,9,2] and 3 → [[8,1,6],[3,5,4],[7,9,2]]
 D         #  Duplicate the current matrix with all 0s filled in
  ©        #  Store it in variable `®` (without popping)
   ø       #  Zip/transpose; swapping rows/columns of the top matrix
           #   → [[8,3,7],[1,5,9],[6,4,2]]
 ®Å\       #  Get the top-left to bottom-right main diagonal of `®`
           #   i.e. [[8,1,6],[3,5,4],[7,9,2]] → [8,5,2]
 ®Å/       #  Get the top-right to bottom-left main diagonal of `®`
           #   i.e. [[8,1,6],[3,5,4],[7,9,2]] → [6,5,7]
    )      #  Wrap everything on the stack into a list
           #   → [[[8,1,6],[3,5,4],[7,9,2]],
           #      [[8,3,7],[1,5,9],[6,4,2]],
           #      [8,5,2],
           #      [6,5,7]]
     O     #  Sum each inner list
           #   → [[15,12,18],[18,15,12],15,18]
      ˜    #  Flatten it
           #   → [15,12,18,18,15,12,15,18]
       Ë   #  Check if all values are the same
           #   → 0 (falsey)
}à         # After the map: Check if any are truthy by taking the maximum
           #  → 1 (truthy)
*          # And multiply it to the check we did at the start to verify both are truthy
           #  → 1 (truthy)
           # (after which the result is output implicitly)

The part D©ø®Å\®Å/)O˜Ë is also used in my 05AB1E answer for the Verify Magic Square challenge, so see that answer for a more in-depth explanation about that part of the code.


text:
Make an interpreter for yes!
Yes is a stack-based language that has a few space-separated instructions:
yes: Push 1 to the stack
no: Push 0 to the stack
what: Push the input to the stack (input is taken at the start of program execution and is the same for the whole execution)
sure: Increment the last item in the stack
nah: Decrement the last item in the stack
really: If the last stack item is a number, replace it with its Unicode character. If it is a letter, replace it with its Unicode char code.
oh: convert the stack to strings and concatenate it, and push that to the stack.
nope: remove the first stack item
yep: remove the last stack item

The stack's last element is always outputted at program end. All non-alphanumeric and non-space characters are ignored. All code is lowercase. Example programs:
yes sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure really
yes sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure really
yes sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure really
yes sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure really
yes sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure really
yes sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure really
yes sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure really
yes sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure really
yes sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure really
yes sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure really
yes sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure really
yes sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure really
yes sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure really
oh

prints Hello, World!.
what

prints the input (cat program.)
no nah

prints -1.
no really

prints the NUL character (U+0000)
what
yes sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure really
oh

prints the input and an underscore.
yes no nope

prints 0
yes no yep

prints 1.
You must write an interpreter in as few bytes as possible. Here's a JS implementation (not well golfed!):

function yes(code, input){
 var stack = [];
 var functions = {
  "yes": "stack.push(1)",
  "no": "stack.push(0)",
  "what": "stack.push(input)",
  "sure": "stack[stack.length - 1] ++",
  "nah": "stack[stack.length - 1] --",
  "really": "stack[stack.length - 1] = (typeof lastItem === 'number' ? String.fromCharCode(lastItem) : lastItem.charCodeAt())",
  "oh": "stack.push(stack.reduce((x, y)=>''+x+y))",
  "nope": "stack.shift()",
  "yep": "stack.pop()"
 };
 code.replace(/[^a-z ]/g, "").split(" ").map(x=>(lastItem = stack[stack.length - 1],eval(functions[x])));
 return stack[stack.length - 1];
}
textarea{
  display: block;
}
Code: <textarea id = "code"></textarea>
Input: <textarea id = "input"></textarea>
<button onclick = "output.value = yes(code.value, input.value)">Run</button>
<textarea id = "output"></textarea>

See also my JS answer below.
You may assume that all integers involved will be less than or equal to 126, that really will never be run with a multi-char string on top of the stack, and that the stack will never be longer than 100 elements.
Edge cases

yes yes oh prints 11.
Intput may be a string or number.
The code can contain any chars. Ones not matching [a-z ] should be ignored.

Please make sure that your testcases include all of the commands.

@LeakyNun done.

What type of integers should be used? Is there overflow? What does really do if there is a multi-character string on top of the stack?

@MartinEnder see edits.

What does really do if -1 is on the top of the stack?

Can input be taken as an array of strings containing the keywords?

What should yes yes oh output?

@LeakyNun undefined behavior (both)

@Luke no, you can't.

@programmer5000 Shouldn't yes yes oh print 11?

@programmer5000 Can you include the relevant definitions to your question so that we are clear that what I asked is undefined behaviour?

Can you take code input as a space separated list?

Is it okay if we assume that the input only contains can character in [a-zA-Z ]?

What if you  pop from an empty stack? Can we error?

Push the input Can input be numbers? Arrays? Chars? Strings? If so, can input strings be multi-line? Increment the last item in the stack What does this do when the last item is not a number?

@KritixiLithos it would probably need to be [a-zA-Z\d ], but that's just a guess.

Can we also assume that the stack will not be empty at the end?

@Titus no, you can't.

Considering your yes yes oh result, I assume that convert to strings means converting a number to its string representation, not to its Unicode.

@Titus yes, you are right.

05AB1E, 77 67 63 61 bytes
Að«Ã#vyÇO§}ðý•9ǝ×н}ÀÀÙ™Íð•650в"X ¾ I > < DdiçëÇ} J r\r \"#:.V

Assumes the program is on the top of the stack.
Try it online!

Can you really assume that all input is valid? For example that you can't get the program yes no sey yep

@Emigna There are no test cases about this, no specifications, and the OP hasn't clarified this even after somebody has left a comment.

I noticed a lack of test-cases. Didn't see anything in the comments about this so I wondered as his reference program ignores invalid commands while yours might execute them as valid commands if the sum of the character codes matches a valid command.

JavaScript (ES6), 218 215 204 203 bytes
Takes the program string s and the input i in currying syntax (s)(i).
s=>i=>s.replace(/\w+/g,S=>(c=eval("[P()];P()+1;[s.shift()];1;0;s=[s.join``];P()-1;i;P()[0]?k.charCodeAt():String.fromCharCode(k)".split`;`[parseInt(S,35)%156%9])).map||s.push(c),s=[],P=_=>k=s.pop())&&P()

How?
We use the perfect hash function parseInt(S, 35) % 156 % 9 to convert the instruction S into an index in 0…8 and use this index to select the JS code to be executed:
instruction | base 35 -> dec. | % 156 | % 9 | JS code
------------+-----------------+-------+-----+---------------------------------------------
"yes"       |           42168 |    48 |   3 | 1
"no"        |             829 |    49 |   4 | 0
"what"      |         1393204 |   124 |   7 | i
"sure"      |         1238209 |    37 |   1 | P()+1
"nah"       |           28542 |   150 |   6 | P()-1
"really"    |      1439554619 |    35 |   8 | P()[0]?k.charCodeAt():String.fromCharCode(k)
"oh"        |             857 |    77 |   5 | s=[s.join``]
"nope"      |         1016414 |    74 |   2 | [s.shift()]
"yep"       |           42165 |    45 |   0 | [P()]

The P function pops the last item off the stack s and loads it into k.
We prevent the result of some instructions from being pushed back onto the stack by testing if the .map() method is defined, that is, if the result is an array. The code for oh is returning an array by design and we force nope and yep to return arrays as well. Hence the syntax:
(c = eval("[code0];code1;...".split`;`[index])).map || s.push(c)

Test cases

let f =

s=>i=>s.replace(/\w+/g,S=>(c=eval("[P()];P()+1;[s.shift()];1;0;s=[s.join``];P()-1;i;P()[0]?k.charCodeAt():String.fromCharCode(k)".split`;`[parseInt(S,35)%156%9])).map||s.push(c),s=[],P=_=>k=s.pop())&&P()

console.log(f(`yes sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure really
yes sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure really
yes sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure really
yes sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure really
yes sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure really
yes sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure really
yes sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure really
yes sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure really
yes sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure really
yes sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure really
yes sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure really
yes sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure really
yes sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure really
oh`)())

console.log(f(`what`)(1234))

console.log(JSON.stringify(f(`no really`)()))

console.log(f(`what
yes sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure sure really
oh`)('code golf'))

console.log(f(`yes no nope`)())

console.log(f(`yes no yep`)())

Röda, 256 bytes
f c,n{s=[];(c/`\W|_`)()|{|m|s+=#m-2 if[m=~"yes|no"];s[-1]+=#m*2-7 if[m=~"sure|nah"];s+=n if[m="what"];s=s[#m%3:#s-#m%2]if[m=~"nope|yep"];{s+=""s()|s[-1].=_}if[m="oh"];{t=s[-1]y=t..""a=t+0;a=a..""{s[-1]=ord(s)}if[#a>#y]else{s[-1]=chr(t)}}if[#m=6]}_;[s[-1]]}

Try it online!
Explanation
#variable returns the length of variable (if it is a string or an array).
f c,n{                         /*declare a function f with arguments c and n*/
s=[];                          /*initialise the stack*/
(c/`\W|_`)                     /*split the code on anything not [a-zA-Z0-9]*/
          ()|                  /*and push each of its values to the stream*/
{|m|...}_                      /*for each element m in the stream, do:*/
s+=#m-2 if[m=~"yes|no"];       /* add 1 or 0 to the stack if m is "yes" or "no"*/
s[-1]+=#m*2-7if[m=~"sure|nah"];/* increment or decrement the top element if m is "sure" or "nah"*/
s+=n if[m="what"];             /* push input if m is "what"*/
s=s[#m%3:#s-#m%2]              /* remove the first or last element of the stack
  if[m=~"nope|yep"];           /* if m is "nope" or "yep" */
{                 }if[m="oh"]; /* if m is "oh" do:*/
 s+=""                         /*  add an element to the stack*/
      s()|s[-1].=_             /*  for each element in s, concatenate that amount to the last element of the stack*/
{                   }if[#m=6]  /* if m is "really" (it's length is 6) do:*/
 t=s[-1]y=t..""                /*  get the last element of the stack*/
 a=t+0;a=a..""                 /*  add 0 to it, if a is a number, this does nothing, otherwise this makes a longer by 1 character*/
 {s[-1]=ord(s)}if[#a>#y]       /*  if a is longer than t (the last element is a char/string) replace it with its code point*/
 else{s[-1]=chr(t)}            /*  otherwise, replace the last element with the char it represents*/
 [s[-1]]                       /*finally output the top of the stack*/

Pyth, 69 bytes
Vczd=Y.v@c"+YsY X_1Y1 +Yw  +Y0 X_1Y_1    PY   +Y1 tY +PYCeY"d%CN23;eY

Try it online!

Doesn't seem to work on the "Hello, World" program.

@Okx It does work; I changed the program in my link; the original program is too long.

Or a bunch of other programs, for that matter. 013456789yes 012345678no oh prints 0, expected output is 10.

Also doesn't work for the edge case yes yes oh (specified in the question), expected output is 11.

@Okx Look at the comments. The OP specifically specified this as undefined behaviour.

Well, comments don't specify the question. In the question it states that yes yes oh should output 11.

JS (ES6), 361 340 bytes
c=>i=>(s=[],r="s[s.length-1]",c.replace(/[^a-z ]/g,"").split` `.map(x=>(eval({"yes":"s.push(1)","no":"s.push(0)","what":"s.push(i)","sure":"~++","nah":"~--","really":"~=((typeof ~)[0]<'o'?String.fromCharCode(~):lastItem.charCodeAt())","oh":"s.push(s.reduce((x,y)=>''+x+y))","nope":"s.shift()","yep":"s.pop()"}[x].replace(/~/g,r)))),eval(r))

Takes code and input through currying.

var yes =
c=>i=>(s=[],r="s[s.length-1]",c.replace(/[^a-z ]/g,"").split` `.map(x=>(eval({"yes":"s.push(1)","no":"s.push(0)","what":"s.push(i)","sure":"~++","nah":"~--","really":"~=((typeof ~)[0]<'o'?String.fromCharCode(~):lastItem.charCodeAt())","oh":"s.push(s.reduce((x,y)=>''+x+y))","nope":"s.shift()","yep":"s.pop()"}[x].replace(/~/g,r)))),eval(r))
textarea{
  display: block;
}
Code: <textarea id = "code"></textarea>
Input: <textarea id = "input"></textarea>
<button onclick = "output.value = yes(code.value)(input.value)">Run</button>
<textarea id = "output"></textarea>

JavaScript (ES6), 220 216 bytes
c=>i=>c.replace(/\w+/g,x=>a=a.concat(eval("Q,[]  (b=Q)[0]?b.charCodeAt():String.fromCharCode(b) 1    [a.join``,a=[]][0] Q+1 a.shift(),[]  i  Q-1".split`Q`.join`a.pop()`.split` `[parseInt(x,36)%19]||0)),a=[])&&a.pop()

A function that takes input with currying syntax, like f(code)(input).

Python 2, 258 bytes
s=[]
m=-1
i,p=input()
for c in p.split(' '):
 k=c<"o"
 if c in"yesnowhat":s+=[i if"w"==c[0]else-k+1]
 if c in"surenah":s[m]+=[1,m][k]
 if"p"in c:s.pop(k-1)
 if"oh"==c:s+=[''.join(map(str,s))]
 if"y"==c[m]:s[m]="'"in`s[m]`and ord(s[m])or chr(s[m])
print(s[m])

Try it online!

-3 bytes thanks to @Wondercricket

You can save 4 bytes by storing -1 as a variable

Perl 6,  233  225 bytes
{my @s;{yes=>{@s.push(1)},no=>{@s.push(0)},what=>{@s.push: once slurp},sure=>{++@s.tail},nah=>{--@s.tail},really=>{($/:=@s.tail)~~Int??$/.=chr!!$/.=ord},oh=>{@s.=join},nope=>{@s.shift},yep=>{@s.pop},}{.words}.map:{.()};@s.tail.print}

Try it
Hello World
cat
-1
nul
cat_
0
1
{my @s;{es=>{@s.push(1)},no=>{@s.push(0)},at=>{@s.push: once slurp},re=>{++@s.tail},ah=>{--@s.tail},ly=>->{($_:=@s.tail)~~Int??.=chr!!.=ord},oh=>{@s.=join},pe=>{@s.shift},ep=>{@s.pop},}{.comb(/..»/)}.map:{.()};@s.tail.print}

Works the same except it only grabs the last two characters from each command, and uses $_ instead of $/ for really.
Try it (Hello World)
Expanded:
{
  my @s; # stack

  {  # Associative array
    yes    => {@s.push(1)},
    no     => {@s.push(0)},
    what   => {@s.push: once slurp}, # read everything from $*IN
    sure   => {++@s.tail},
    nah    => {--@s.tail},
    really => {
          ( $/ := @s.tail ) # bind $/ to the last value in the stack
          ~~ Int            # if that is an Int
      ??  $/.=chr           # replace it with that character
      !!  $/.=ord           # otherwise replace it with its ordinal
    },
    oh     => {@s.=join},
    nope   => {@s.shift},
    yep    => {@s.pop},
  }\
  { .words }                # index by the words in the program
  .map: {.()};              # call each of the lambdas in order

  @s.tail.print             # print the last value on the stack
}

PHP, 315 305 bytes
second draft, not tested yet
foreach($argv as$k=>$v)if($k>1)eval((strstr($c=preg_replace('#[^a-z ]#','',$v),p)?'':'$s[]=').[yes=>1,no=>0,what=>'$argv[1]',sure=>'array_pop($s)+1',nah:'array_pop($s)-1',really=>'is_int($x=array_pop($s))?chr($x):ord($x)',oh=>'join($s)',nope=>'array_shift($s)',yep=>'array_pop($s)'][$c].';');echo end($s);

Run with php -nr '<php-code>' <input> <yes-code>.
breakdown
foreach($argv as$k=>$v)if($k>1)         # loop through commands
    eval(                                   # 3. interprete
        (strstr(                            # 2. if no 'p' in command, prepend '$s[]='
                                            # 1. ignore all non-code characters
            $c=preg_replace('#[^a-z ]#','',$v),p)?'':'$s[]=').
        [yes=>1,                                # yes: append 1
        no=>0,                                  # no: append 0
        what=>'$argv[1]',                       # what: append input
        sure=>'array_pop($s)+1',                # sure: remove end, increment, append
        nah:'array_pop($s)-1',                  # nah: remove end, decrement, append
                                                # really: convert between ascii and ordinal
        really=>'is_int($x=array_pop($s))?chr($x):ord($x)',
        oh=>'join($s)',                         # oh: concatenate elements, append
        nope=>'array_shift($s)',                # nope: remove first element
        yep=>'array_pop($s)']                   # yep: remove last element
        [$c]
    .';');
echo end($s);                           # print last element (if exists)

PowerShell, 286 bytes
$s=@()
$k-split"\s"|%{
switch($_){
"yes"{$s+=1}
"no"{$s+=0}
"what"{$s+=(read-host)}
"sure"{$s[-1]+=1}
"nah"{$s[-1]-=1}
"really"{if($s[-1]-is[int]){[char]($s[-1])}else{[int][char]($s[-1])}}
"oh"{$s+=($s-join'')}
"nope"{$s=($s[1..($s.Length-1)])}
"yep"{$s=($s[0..($s.Length-2)])}}}
$s[-1]

Try it online!
The input is defined as $k in header of TIO.
An empty array $s initialized.
Splits the input on whitespace using a regex.
Then for each switch it does
yes: Push 1 to the stack (read stack as array and push as append, += operator used, which adds an item at the end of arrays (here))
no: Push 0 to the stack
what: Push the input to the stack
sure: Increment the last item in the stack (indexing and += used)
nah: Decrement the last item in the stack
really: If the last stack item is a number, replace it with its Unicode character. If it is a letter, replace it with its Unicode char code. (used [char] and [int][char] type casting)
oh: convert the stack to strings and concatenate it, and push that to the stack. (Just join the array with '')
nope: remove the first stack item (Using indexing)
yep: remove the last stack item (Using indexing)

At last output last item in array.