text:
Square root of ASCII art
You are working as an intern for a mathematician who really hates TeX, LaTeX, etc. So much so that he has decided to abandon all typesetting whatsoever and make you do all the formatting in ASCII. You got tired of this after a while and decided to start automating parts of it, starting with square roots.
Here's how a square root is made:
###  this is the input
###
###

_____  put a row of underscores stretching one character off either side on top
 ###
 ###
 ###

   _____  put a diagonal of slashes in front going the height of the input
  / ###
 /  ###
/   ###

      _____ put a diagonal of backslashes in front of that, going up half of the input's height rounded up
     / ###
 \  /  ###
  \/   ###

And that's it!
Rules
You are to make a program or function that takes in a string, list of strings  (i.e. lines), or array of characters, and outputs the input transformed according to the description above (not necessarily by the exact same order or process)
You may assume that the input is rectangular if preferred. Trailing whitespace is neither required nor disallowed.
This is code-golf, so the shortest answer in bytes wins.
Examples:
Input:
40
Output:
  ____
\/ 40

Input:
  ____
\/ 40
Output:
   ________
  /   ____
\/  \/ 40

Input:
/|
 |
 |
_|_
Output:
      _____
     / /|
    /   |
\  /    |
 \/    _|_

Input:
#  #
#  #
#####
   #
   #
Output:
        _______
       / #  #
      /  #  #
\    /   #####
 \  /       #
  \/        #

V is gonna do well in this one

a mathematician who really hates TeX, LaTeX etc I almost quit reading right there

You are working I almost quit reading right there

Python 2, 196 bytes
x=Q=input()
l=len(x)
k=(l+1)/2
q=l+k
x=[[' ']*(q+1)+list(y)for y in x]
for i in range(k):x[i+l/2][i]='\\'
for j in range(l):x[j][q-j-1]='/'
print'\n'.join([' '*q+'_'*(2+len(Q[0]))]+map(''.join,x))

Try it online!
-2 bytes thanks to Step Hen
-13 bytes thanks to Jonathan Allan

@StepHen Hm. It works but / would work too. Thanks.

Same for i+l//2

The underscores need to stretch one character extra on either side.

You can take input as a list of strings (Python 2's input() evaluates the raw input). Also '_'*len(Q[0])+'__' is '_'*(2+len(Q[0])).

SOGL V0.12, 27 bytes
1w⁄2+╔*00žl»╚;lH╚@Κ№↕h┼№↕;┼

Try it Here! (→ added for ease-of-use; the program expects the input on stack)

Python 3, 138 147 Bytes
def f(l):h=len(l);w=len(l[0]);c=int(h/2);print('\n'.join([(h*2-c)*' '+w*'_']+[(i*' '+'\\'+(h-i-1)*2*' '+'/'+i*' ')[c:]+s for(i,s)in enumerate(l)]))

Variable 'l' is a list of strings, each string a line. Readable Version:
def f(l):
  height = len(l)
  width = len(l[0])
  half_height_floor = int(height / 2)

  print((height * 2 - half_height_floor) * ' ' + width * '_')

  for (index, line) in enumerate(l):
    #build a V based on the location of the line
    #surrounding V whitespace
    outer_space = index * ' '

    #inner V whitespace
    inner_space = (height - index - 1) * 2 * ' ' #inner v space

    #complete V
    v = outer_space + '\\' + inner_space + '/' + outer_space

    #left half_height_floor chars removed
    v_chopped = v[half_height_floor:]

    print(v_chopped + line)

Forms a square root symbol with a complete V then shaves off the left accordingly.
Try it Online!

Hi, Welcome to PPCG. Nice first answer, but this is a snippet, since it is assuming the variable l as input. You must also include the part where l is input, either as a function parameter or input() function, etc. (P.S. your answer also seems to be lacking a few white-space-padding.)

@officialaimm, thank you for the welcome! To practice for future problems I have updated and included TIO link

Charcoal, 32 bytes
ＷＳ⊞υιＰ⪫υ¶↖Ｐ×_⁺²⌈ＥυＬι↙↙Ｌυ↑↖÷⁺¹Ｌυ²

Try it online! Link is to verbose version of code. 29-byte version that assumes rectangular input:
ＷＳ⊞υιＰ⪫υ¶↖Ｐ×_⁺²Ｌθ↙↙Ｌυ↑↖÷⁺¹Ｌυ²

@LuisMendo Charcoal is getting old...

@EriktheOutgolfer D: old how

@ASCII-only Well SOGL is newer and better, so...no offense to Charcoal though it still wins a lot.

@EriktheOutgolfer but how is it better :(

IMO it's kinda like saying Haskell is newer and better so Haskell > C# although it still wins a lot

@ASCII-only Well you can't just design the perfect language for everything :p basically that's a problem with many languages, and there's also evolution, and of course being able to recognize when somebody means something literally or not ;)

i know but old :||||||||||||||||||||||||||||| do you know how offensive that is to charcoal it's one of the younger ones (less old than cjam etc, including v and jelly) :P

Python 2,  131  130 bytes
x=input()
n=len(x)
s=" "
for v in[s*2*n+"_"*(2+len(x[0]))]+[s*i+"\\"+s*2*(n+~i)+"/"+s*-~i+r for i,r in enumerate(x)]:print v[n/2:]

A full program taking a list of lines as input with the rectangular-only allowance (actually that the first line is one of the longest).
Try it online!

Java 8, 244 bytes
A very long solution, but probably close to the shortest for Java. This lambda takes lines of input as a String[] and returns a String. All lines must have the same length.
Based on the example outputs, I assumed that there's no need to append a space to each line in the input, so the program doesn't.
Thanks to Jonathan Allan for reminding me about the ~ operator.
l->{int h=l.length,w=l[0].length(),a=h/2,i=w+3,x=h+a+h%2;String s="",t=s;for(;--i>0;)t+="_";for(;i++<x;)s+=" ";t=s+t;for(i=0;i<h;)t+="\n"+s.substring(0,i<a?x+~i:i-a)+(i<a?"":"\\"+s.substring(0,(h+~i)*2))+"/"+s.substring(0,i+1)+l[i++];return t;}

Try It Online
Ungolfed
l -> {
    int
        h = l.length,
        w = l[0].length(),
        a = h / 2,
        i = w + 3,
        x = h + a + h % 2
    ;
    String
        s = "",
        t = s
    ;
    for (; --i > 0; )
        t += "_";
    for (; i++ < x; )
        s += " ";
    t = s + t;
    for (i = 0; i < h; )
        t +=
            "\n"
            + s.substring(0, i < a ? x + ~i : i - a)
            + (i < a ? "" : "\\" + s.substring(0, (h + ~i) * 2))
            + "/"
            + s.substring(0, i + 1)
            + l[i++]
        ;
    return t;
}

Acknowledgments

-2 bytes thanks to Kevin Cruijssen

Nice answer +1. You can golf 2 bytes by creating a variable for h+a+h%2 which you use two times in your code: l->{int h=l.length,w=l[0].length(),a=h/2,i=w+3,x=h+a+h%2;String s="",t=s;for(;--i>0;)t+="_";for(;i++<x;)s+=" ";t=s+t;for(i=0;i<h;)t+="\n"+s.substring(0,i<a?x+~i:i-a)+(i<a?"":"\\"+s.substring(0,(h+~i)*2))+"/"+s.substring(0,i+1)+l[i++];return t;}. (I also used the header & footer in the TIO link, so you can isolate your actual golfed code from the test code.)

Vyxal a, 67 bytes
L3*½⌈ð*₴⁰hL⇧\_*,ƛ¥⁰L½⌊-:0≥[:ð*\\+₴⁰L½⌈ε‹|_⁰L½⌈]&›ð*₴⁰L¥εð*\/¥ð*++₴,

Try it Online!
Don't ask how it works. It's a giant mess.

Vyxal, 40 32 bytes
ẏṘ\\$꘍øm↵:IǏfL:£Nvȯ$Z¥?hL⇧\_*꘍p⁋

Try it Online! or verify all test cases.
-8 bytes from porting 05AB1E

Perl 5, 177 185 160 bytes
$s=$f=int((@t=<>)*1.5+.5);print" "x$f;print"_"x length$t[0];print"_
";$b=-int(@t/2);for(0..$#t){--$s;print$_==$s?"/":$_==$b?"\\":" " for 0..$f;print$t[$_];++$b}

Try it online!
Changelog:

needed more bytes to fix a bug (it assumed a square input first)
fixed another bug and used some tips from comments (thanks Dada!)

Shortened to 132 bytes. I let you have a look at what I did. The big lines: <> instead of <STDIN>, print" "x$f instead of for(1..$f){print" "}, using xxx for yyy instead of for(yyy){xxx}, using $_ in the for loop instead of explicit variables (for$i(..){..})...

Long time since I used perl, thanks! But I tried with x$f and couldn't get it to work :o trying again now...

Uh and I just found a bug in both versions ... give me some time to fix this ;)

JavaScript (ES6), 140 bytes
Takes input as an array of strings / returns an array of strings.
a=>[a[0].replace(/./g,'_'),...a].map((r,y)=>[...a,...a].map((_,x)=>x-y+1|y-.5<l/2?l*2-x-y?' ':'/':'\\',c=y?' ':'_').join``+c+r+c,l=a.length)

Test cases

let f =

a=>[a[0].replace(/./g,'_'),...a].map((r,y)=>[...a,...a].map((_,x)=>x-y+1|y-.5<l/2?l*2-x-y?' ':'/':'\\',c=y?' ':'_').join``+c+r+c,l=a.length)

console.log(
  f([
    '40'
  ]).join`\n`
)

console.log(
  f([
    '  ____',
    '\\/ 40 '
  ]).join`\n`
)

console.log(
  f([
    '/| ',
    ' | ',
    ' | ',
    '_|_'
  ]).join`\n`
)

console.log(
  f([
    '#  # ',
    '#  # ',
    '#####',
    '   # ',
    '   # '
  ]).join`\n`
)

Japt, 46 bytes

l *2
£Vç hY'\ h~Y'/ +S+XÃuVç +'_p2+Ug l¹msV/4

Leading newline is part of the program. Input and output is an array of strings representing lines.
Try it online! using the -R flag to join the resulting array with newlines.

@ETHproductions Sadly that won't work since U is an array and not a string.

Ah, darn it....

C (clang), 169 151 bytes
-18 thanks to @ceilingcat
#define P printf("%*c"
i;k;f(**l,c){P,i=c+c-c/2,32);for(k=strlen(*l)+3;--k;)P,1,95);for(;P,1,10),k<c;P"%s",k,32,*l++))P,i-k-P,k++<c/2?0:k-c/2,92),47);}

Try it online!

Dyalog APL, 95 bytes
{((' '/⍨y+x),'_'/⍨2+⊃⌽⍴⍵)⍪⍉(x-y)↓⍉(⊖(x(-x)↑⌽y y⍴'\',' '\⍨y←⌈x÷2),x x⍴'/',' '\⍨x←⊃⍴⍵),' ',⍵,' '}

Try it online!

C++, 291 bytes
The function assumes that all the strings in the vector passed as parameter have the same length
#include<vector>
#include<string>
#define S std::string
#define T size()
void f(std::vector<S>&c){c.insert(c.begin(),S(c[0].T+1,'_'));int i,j=0;for(i=1;i<c.T;++i){c[i]='/'+S(i,' ')+c[i];if(i>=c.T/2)c[i]='\\'+S((c.T-i-1)*2,' ')+c[i];}for(auto&a:c)j=j>a.T?j:a.T;for(auto&a:c)a=S(j-a.T,' ')+a;}

C, 485 bytes
This program takes up to 999 characters from standard input and reads them into an array. It prints them 1 at a time to standard output with the changes your challenge indicated. It assumes the input is rectangular.
#include<stdio.h>
#define p(a)putc(a,stdout);
#define P j+j/2+1
a[999],i,j,k,l,m,n,q;char c;pad(a){m=P;if(a&&!k){m-=1;}for(n=0;n!=m;n++){q=32;if((!a||k)&&n==c){c--;q=47;}else if((P-c+1)>j/2+1&&(P)/2-n==c-2){q=92;}p(q);}}int main(){k=i=j=0;x:if(read(0,&c,1)){if('\n'==(a[i++]=c)){if(!j){l=i;}j++;}goto x;}i--;if('\n'==a[i-1]){i--;}else{j++;}c=P-2;for(;k!=i;k++){if(!k||a[k]==10){if(a[k]==10){p(10);}pad(1);if(!k){l++;while(l-->0){p(95);}p(10);pad(0);}if(a[k]==10){continue;}}p(a[k]);}}

Perl 5, 159 bytes
@a=map{$m=(y///c)>$m?y///c:$m;$_}<>;$_=$"x($l=@a/2-.5).'\\/'.$"x@a;for$i(1..@a){$a[-$i]=$_.$a[-$i];s| \\|\\ |;s|/ | /|;$i>$l&&y/\\/ /}chop;say$_.'_'x++$m,$/,@a

Try it online!

Canvas, 26 bytes
Ｌ├_×；∔ｒ↔ｌ╷＼ ；∔＋ｌ½：／； ＊；∔＋↔

Try it here!

05AB1E, 35 bytes
ā<R'\úíº.c.BD2äĆ˜g©δ.£søIнgÌ'_×®úš»

Input as a rectangular list of strings-lines (rectangular isn't completely necessary, as long the first line is the longest).
Try it online or verify all test cases or see the step-by-step output.
Explanation:
ā             # Push a list in the range [1, (implicit) input-length]
 <            # Decrease each by 1 to the range [0, length)
  R           # Reverse it to the range (length, 0]
   '\        '# Push string "\"
     ú        # Pad "\" with the integer amount of leading spaces
      í       # Reverse each, so the spaces are trailing
       º      # Mirror each line
        .c    # Centralize (implicitly joins by newlines)
          .B  # Box it (split on newlines, and add trailing spaces)
D             # Duplicate it
 2ä           # Split it into two equal-sized parts (where the first is longer
              # for odd-length lists)
   Ć          # Enclose: append its own head
    ˜         # Flatten
     g        # Pop and push the length
      ©       # Store it in variable `®` (without popping)
       δ      # Map over each string:
        .£    #  Only leave the last `®` amount of characters
s             # Swap so the input-list is at the top
 ø            # Create pairs of the two lists
  Iн          # Push the first line of the input-list
    g         # Pop and push its length
     Ì        # Increase it by 2
      '_×    '# Pop and push a string of that many "_"
         ®ú   # Pad `®` amount of leading spaces
           š  # Prepend it to the list
            » # Join each inner list by spaces, and then the strings by newlines
              # (after which the result is output implicitly)

2äĆ˜g could alternatively be gD;î+ for the same byte-count (length; duplicate; halve; ceil; sum together): try it online.


text:
How do you guys get to know these strange programming languages
I majored in computer science in the area of communication technologies and I fluently speak Python, Java, C, Bash, Matlab, Octave and some others. But you guys know things I have never ever heard about like "Fish" or "R" or "Whitespace" or some kind of crazy things. Sometimes these languages are not even build by ASCII letters but by some crazy signs.
My question is: How do you get by all these things? I mean: At what point of your programming career did you say to yourself that you want to do some task in "Fish" or whatever? I mean what is the point or what was the purpose or... I am simply extremely confused by the fact that programming langues besides the big common ones (C, C++, C#, Java, Python, Lisp, JavaScript...) even exist but why in the world did you learn them so well that you can solve difficult problems with 8 Bytes of code??
PS: If someone finds a better tag, please add it mine is bad but I can't think of a better one

An esoteric programming language, or esolang, is a computer programming language designed to experiment with weird ideas, to be hard to program in, or as a joke, rather than for practical use. That said, I'm pretty sure this is both off-topic and too broad and opinion based.

I'm voting to close this question as off-topic because while we do programming competitions and allow tips questions for how to golf certain code or in certain languages, asking for how we get to know these languages is firstly largely opinion-based and secondly is off-topic here. Once you have 20 reputation, you might be able to find answers to your question in our general chatroom. Thanks!

Wait what R is a normal programming language

Also why? Because we can. Also because we don't have enough memory to have a program more than 8 bytes long :P

I'm not getting the downvotes right here. Clearly my question is not a programming challenge but it targets the field and the people who participate in it?

I think this could be a good question to discuss in chat. Can a 1 rep user get access?

It's off-topic, and we don't like off-topic posts. Like I said, chat is suitable for this because it has no validity criteria for valid answers, it's not about PPCG itself so Meta.PPCG.SE wouldn't allow this either.

@xnor You can ask a moderator to superping the user in or grant access. Since you're a room owner, I think you can add explicit read+write access for this user.

Of course it has criteria for a valid answer which would be a number of valid reasons why to participate in "fun programming languages" or am I wrong. Maybe I just have to swallow these downvotes and hopefully someone is willing to share despite some users labeling this as off topic

@ASCII-only Fish is also a rather normal programming language.

@JoschKraus A criteria is for a contest. Not for a random question.

@JoschKraus Would you be interested in a site chat invitation to ask there?

Of course! I would really like to talk with programmers with these kind of special interests!

@JoschKraus Do you have a chat profile? I can't seem to find it.

@WheatWizard Oh yeah that fish haha I keep on getting it confused with ><>

@xnor i do not think that you can do it.

@JoschKraus just make a blank account on 19 other SE. In a few minutes you can join. (known bug)

@JoschKraus Are you able to join our chat room? (link was wrong before)

@HyperNeutrino I think this would fit into meta ... but he can´t post there, can he?

@Titus he can. 1 rep users can join meta

IMO this question would definitely be on-topic on meta.PPCG.SE.  This question is very relevant to this site and I would be in support of carefully broadening our scope to allow questions such as this on main.PPCG.SE.  Given our current scope I understand the close-votes, but not the downvotes - this is reasonably written, useful question.  +1 from me.

source: Stack Exchange

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

sort: votes


text:
Take the square root of a string
Motivation
In this challenge your task was to multiply two strings, this naturally introduces a way to take the square root of a string.
How does it work?
Given a string (for example pub) the first thing you need to do, is to determine the ASCII code for each character:
"pub" -> [112, 117, 98]

Next you map these codes to the range [0..94] by subtracting 32 of each value:
[112, 117, 98] -> [80, 85, 66]

Now you need to find for each value its root modulo 95 (eg. 40*40 % 95 = 80, you could also pick 55):
[80, 85, 66] -> [40, 35, 16]

And finally you'll map it back to the range [32..126] and convert it back to a string:
[40, 35, 16] -> [72, 67, 48] -> "HC0"

Indeed "HC0" ⊗ "HC0" = "pub" as you can verify with a solution from the other challenge here.

The ones familiar with modular arithmetic probably noticed that the square root modulo 95 does not always exist, for example there's no root for 2. In such a case the square root of a string is not defined and your program/function may crash, loop indefinetly etc.
For your convenience, here's the list of chars that have a square root (the first one is a space):
 !$%&)+03489:>CDGLMQVW]`bjlpqu

Rules

You will write a program/function that takes a string (or list of chars) as an argument and returns any square root if it exists
You may assume that the input always has a square root
The input may consist of an empty string
The input will be in the printable range ([32..126])
The output is either printed to the console or you return a string if the square root exists
In case the square root doesn't exist, the behavior of your program/function is left undefined
If you choose to print the root to the console trailing newlines or whitespaces are fine

Test cases
Note that these are not necessarily the only solutions:
''              -> ''
'pub'           -> 'HC0'
'pull!'         -> 'HC33!'
'M>>M'          -> '>MM>'
'49'            -> '4%'
'64'            -> undefined
'Hello, World!' -> undefined

Forcing an error state on these characters without a square root seems unnecessary, I'd recommend just undefined behavior.

@ATaco I updated the challenge.

What to do if the given string is the square of multiple strings?

@tsh Return any, I'll update the challenge.

@Downvoter Why the downvote?

Is it deliberate that you map to the range 0-95 and then take modulo 95 instead of 96?

@curiousdannii Actually it should be the range 0-94 (that's the printable range), that's a typo - sorry about that.

Can the output be a list of chars?

@Oliver Yes, it can.

sh + coreutils, 58 bytes
tr '$%&)+0389:>CDGLMQVW]`bjpqu' 1u.#:BFO%+M/L2Aa,795d0@H=C

Try it online!
The modular square root is typically not unique; we have 2 or 4 choices for each character except .  We don’t need to translate , !, 4, l since each is already a square root of itself.  For the remaining characters, we choose images that don’t need to be escaped for the shell or tr.

Python 3, 57 56 bytes
lambda s:s.translate({k*k%95+32:k+32for k in range(95)})

translate uses a mapping from "Unicode ordinals to Unicode ordinals". Thus, we don't need chr/ord conversions. Note: it doesn't crash when the char has no root.
Saved 1 byte thanks to @jonathan-allan
The value of the mapping is the greatest root in range 0..94 of the key. To have the least root (as in the examples), use:
lambda s:s.translate({k*k%95+32:k+32for k in range(95,0,-1)})

(61 bytes)
>>> [s.translate({k*k%95+32:k+32for k in range(95,0,-1)}) for s in ['','pub','pull!','M>>M','49','64','Hello, World!']]
['', 'HC0', 'HC33!', '>MM>', '4%', '64', 'He33o,\x7f9or3d!']

Welcome! Nice first post. You can remove the space between 32 and for.

...also, here is a link to an online interpreter test suite.

Japt, 16 15 bytes
c@H+LÇ²%95+HÃbX

Try it online!
Saved a byte by looking at the 05AB1E answer (using L = 100 instead of 95). Now Japt is the shortest, a quite rare occurance :-D
Explanation
 c@ H+LÇ   ²  %95+HÃ bX
UcX{H+LoZ{Zp2 %95+H} bX}   Ungolfed
                           Implicit: U = input string, H = 32, L = 100
UcX{                   }   Map each charcode X in the input to the following:
      Lo                     Create the array [0, 1, ..., 98, 99]
        Z{         }         and map each item Z to
          Zp2                  Z ** 2
              %95              mod 95
                 +H            plus 32.
                     bX      Find the first index of X in this array. This gives the
                             smallest square root (mod 95) of (X - 32).
    H+                       Add 32 to map this back into the printable range.
                           Implicit: output result of last expression

Python 2, 80 bytes
lambda s:''.join([chr(i+32)for i in range(95)if i*i%95==ord(c)-32][0]for c in s)

Try it online!
Throws IndexError if no root exists.

JavaScript, 82 bytes
Collaborated with @ETHproductions
s=>s.map(x=>(g=z=>z*z%95==x.charCodeAt(0)-32?String.fromCharCode(z+32):g(z+1))(0))

Input and output are in the form of a char array.
Test snippet

var f=s=>s.map(x=>(g=z=>z*z%95==x.charCodeAt(0)-32?String.fromCharCode(z+32):g(z+1))(0))

console.log(f([...""]));
console.log(f([..."pub"]));
console.log(f([..."pull!"]));
console.log(f([..."M>>M"]));
console.log(f([..."49"]));

05AB1E, 17 bytes
vтLn95%žQykk33+ç?

The algorithm is very similar to the Jelly and Japt answer (Had something else before but that only got me to 19 bytes)
Explanation
vтLn95%žQykk33+ç?
v                 # For each character of the input...
 тL                # Push [1..100]
   n               # Square every element of the list
    95%            # And take it modulo 95
       žQyk        # Push the index of the current character in the printable ascii range
           k       # Push the index of that in the list created earlier
            33+    # Add 33 to the result
               ç   # And convert it back to a character
                ?  # Print the character

Try it online!

Mathematica 82 Bytes
FromCharacterCode[Solve[x^2==#,Modulus->95][[1,1,2]]+32&/@(ToCharacterCode@#-32)]&

Using Solve's ability to do modular arithmetic.

Jelly, 18 17 16 bytes
95Ḷ²%95+32żØṖFyO

Try it online! (comes with test-suite footer)
Saved 2 bytes by doing a complete rewrite. Also the first time I've found use for }.
Explanation
The code first calculates all square characters, and then maps them to their respective square roots.
95Ḷ²%95+32żØṖFyO    Main link. Argument: S (string)
95                    Take 95.
  Ḷ                   Get the array [0, 1, ..., 94].
   ²                  Square each to get [0, 1, ..., 8836].
    %95               Get each square modulo 95 to get [0, 1, ..., 1].
       +32            Add 32 to get [32, 33, ..., 33].
           ØṖ         Get the list of printables [" ", "!", ..., "~"].
          ż           Interleave with printables to get [[32, " "], ..., [33, "~"]].
             F        Flatten the mapping to [32, " ", ..., 33, "~"].
               O      Get the code point of each character in input.
              y       Map the code points to the correct output characters using the map.

95Ḷ²%95+32iÐ€O+31Ọ is basically what my Japt answer does, though your solution is two bytes shorter...

Mathematica, 94 bytes
(R[x_]:=Min@Select[Range@45,Mod[#^2,95]==x&];FromCharacterCode[R/@(ToCharacterCode@#-32)+32])&

Try it online!

Ruby, 65 bytes
->s{s.chars.map{|c|((0..94).find{_1**2%95+32==c.ord}+32).chr}*""}

Attempt This Online!

Perl 6, 53 bytes
{[~] .comb.map({32+first *²%95==.ord-32,^95})».chr}

Try it online!

Mathematica, 60 bytes
FromCharacterCode[PowerMod[ToCharacterCode@#-32,1/2,95]+32]&

Anonymous function. Takes a string as input and returns a string as output. Errors on invalid input.

Factor, 59 55 bytes
[ [ 32 - 95 iota [ sq 95 mod = ] with find 32 + ] map ]

Try it online!

Go, 120 bytes
func f(s[]rune)[]rune{
for i:=range s{for k:=0;k<95;k++{r:=rune(k*k%95+32)
if r==s[i]{s[i]=rune(k+32)
break}}}
return s}

Attempt This Online!

JavaScript, 56 bytes
s=>Buffer(s).map(x=>(g=y=>y*y%95+32-x?g(++y):y+32)``)+``

Try it online!

Pip, 33 bytes
FiA*a YyAE((SQ,h)%95+32@?i)+32 Cy

Try It Online!

Pip, 37 bytes
FiA*a-32 YyAE((SQ_%95=i)FI,h)@0+32 Cy

Try It Online!

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

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


text:
Map of India - minimum number of bytes
Your challenge is to make a program(less number of bytes than what the below program takes) that should print the map of India with any special character of choice.
TIO Link
#include <stdio.h>
int main()
{
    int a = 10, b = 0, c = 10;
    char* str = "TFy!QJu ROo TNn(ROo)SLq SLq ULo+UHs UJq "
                "TNn*RPn/QPbEWS_JSWQAIJO^NBELPeHBFHT}TnALVlBL"
                "OFAkHFOuFETpHCStHAUFAgcEAelclcn^r^r\\tZvYxXyT|S~Pn SPm "
                "SOn TNn ULo0ULo#ULo-WHq!WFs XDt!";
    while (a != 0)
    {
    a = str[b++];
        while (a-- > 64)
        {
            if (++c == 90)
            {
                c = 10;
                putchar('\n');
            }
            else
            {
                if (b % 2 == 0)
                    putchar('!');
                else
                    putchar(' ');
            }
        }
    }
    return 0;
}

The program outputs:
                !!!!!!
                !!!!!!!!!!
                 !!!!!!!!!!!!!!!
                   !!!!!!!!!!!!!!
                 !!!!!!!!!!!!!!!
                  !!!!!!!!!!!!
                  !!!!!!!!!!!!
                    !!!!!!!!!!!!
                    !!!!!!!!
                    !!!!!!!!!!
                   !!!!!!!!!!!!!!
                 !!!!!!!!!!!!!!!!
                !!!!!!!!!!!!!!!!                                  !!!!!
              !!!!!!!!!!!!!!!!!!!                               !!!!!!!!!!
             !!!!!!!!!!!!!!!!!!!!!!!                 !         !!!!!!!!!!
        !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!              !!     !!!!!!!!!!!!
       !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!        !!      !!!!!!!!
        !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
         !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!
          !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!  !!!!!!!!!!!!
   !!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!        !!!!!!
  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!      !!!!!
      !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!        !!!
    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!        !
      !!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
       !!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
              !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
             !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
              !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
              !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
              !!!!!!!!!!!!!!!!!!!!!!!!!!!!
              !!!!!!!!!!!!!!!!!!!!!!!!!!
              !!!!!!!!!!!!!!!!!!!!!!!!!
               !!!!!!!!!!!!!!!!!!!!!!!!
                !!!!!!!!!!!!!!!!!!!!
                !!!!!!!!!!!!!!!!!!!
                 !!!!!!!!!!!!!!!!
                  !!!!!!!!!!!!!!!!
                  !!!!!!!!!!!!!!!
                   !!!!!!!!!!!!!!
                    !!!!!!!!!!!!
                    !!!!!!!!!!!!
                    !!!!!!!!!!!!
                      !!!!!!!!
                      !!!!!!
                       !!!!

Like @BruceForte said, I had added the requisite tio link

I think printing a 2d region of one character isn't that interesting, and we've already had the batman symbol challenge which has more usable structure.

Are we free to use any two characters, or is the ocean restricted to the space character? Also I noticed you have specified "special character", what exactly does that mean (I currently use 0, but do not know if that counts as "special")?

@xnor <3 domo origato, Mr. Xnorboto.

Jelly, (110? 113?) 112 bytes
Notes: The 2 bytes, a⁶ (near the end) may be dropped if 1 is acceptable for the ocean. If special character means digits are not acceptable and the ocean must be a space the byte count will be 113 (replace Ḃa⁶s75Y with ị⁾ !s75Y) which will use !.
“*ẊñDȯT¹^qɓ\j£œ%ñ2u{ṅʠỴ©ṾÇịṭxẏ¤Ḅʋ⁽~|}ṾṃƑ¡vṀGs®[Ȯkhɗṃ?ƇṿTṫ6HỌ¡ẏṣnD1ı¹ḍ1Ḣ4$ẸObẓ¢ƙṾⱮḃċỵ|)wY)ḌÇḤ~æṣt²5’ḃ70ĖŒṙḂa⁶s75Y

A full program printing the map. Uses 0 for the land.
Try it online!
How?
The first 99 bytes:
“*ẊñDȯT¹^qɓ\j£œ%ñ2u{ṅʠỴ©ṾÇịṭxẏ¤Ḅʋ⁽~|}ṾṃƑ¡vṀGs®[Ȯkhɗṃ?ƇṿTṫ6HỌ¡ẏṣnD1ı¹ḍ1Ḣ4$ẸObẓ¢ƙṾⱮḃċỵ|)wY)ḌÇḤ~æṣt²5’

is a base 250 literal (a very large number). The rest of the code manipulates this number:
“ ... ’ḃ70ĖŒṙḂa⁶s75Y - Main link: no arguments
“ ... ’              - the large number above
       ḃ70           - convert to bijective base 70 [16,6,69,10,66,...]
          Ė          - enumerate                    [[1,16],[2,6],[3,69],[4,10],[5,66],...]
           Œṙ        - run length decode            [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,3,3,...(69 total)...,3,4,4,4,4,4,4,4,4,4,4,5,5,...(66 total)...,5,...]
             Ḃ       - modulo 2                     [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,1,1,...(69 total)...,1,0,0,0,0,0,0,0,0,0,0,1,1,...(66 total)...,1,...]
               ⁶     - literal space character
              a      - logical and (vectorises)     [' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',0,0,0,0,0,0,' ',' ',...(69 total)...,' ',0,0,0,0,0,0,0,0,0,0,' ',' ',...(66 total)...,' ',...]
                s75  - split into chunks of length 75 (representing the rows of "text")
                   Y - join with newline characters (making a single list of ' ', 0, and '\n')
                     - implicit print (a list containing any characters is smashed, so
                     -             the 0s print as `0` and none of the `[,]` are shown)

Charcoal, 135 134 133 132 126 bytes
Ｆ¹²⁶Ｆ…"§”kL↷DXry"Ｒ⁴¹¤'➙ω⎈v¬⌊π2κÿρ“q↷0h˜⁶!⌊P[±9ＮＨ｜N≡H´“i¬›ＦＥ‹t⁵→Z£314➙yqt⟲“⌊⌊‖↷ÞＩuＡ?↷｜⁻c″!!<;‹ＹＳ00y/;↥Ｌ’Ｄ∧§⎈k≕X”ι⎇﹪Ｌ⊞Ｏυω⁷⁵§ *ι⸿

Try it online!
Port of my C# answer. Link to the verbose version.

6 bytes saved thanks to Neil!

AtIndex(" *", i) saves 4 bytes, I think.

@Neil nice! Thanks!

I think you can save more bytes by using a Range instead of subtracting the ordinals. (for (Range("A", "Z")) would loop 25 times for example, so it would be shorter than for (Minus(Ordinal("Z"), 65)).

I tried porting this approach to the Batman question. It came in at 54 bytes Ｆ³⁶Ｆ…A§”v.£j⎚-n²λWHＸ↓wＡ8L$»δηπ41H″”ι⎇﹪Ｌ⊞Ｏυω²⁶§ *ι⸿‖Ｏ← but sadly I then noticed I could apply the AtIndex trick to save 2 further bytes on my own solution...

Bubblegum, 132 bytes
00000000: b595 b719 4421 18c3 7aa6 30fb 0f79 a93b  ....D!..z.0..y.;
00000010: 4412 dfc3 25f6 2f32 a451 fda9 f49a 61c1  D...%./2.Q....a.
00000020: 4300 9163 84b7 7d60 6c3e 383b 2618 c852  C..c..}`l>8;&..R
00000030: e080 0290 9856 ed8b f503 1221 503b 106e  .....V.....!P;.n
00000040: 1231 6335 9c70 3027 0245 6242 88a6 0410  .1c5.p0'.EbB....
00000050: b097 c2dd ae27 c2c1 0346 8ca3 a05e 32fe  .....'...F...^2.
00000060: c710 b993 a288 97cc 55f8 2eee 877d 5407  ........U....}T.
00000070: 91cb 6e2e 3ee4 1f5e 1f91 3f00 7423 002d  ..n.>..^..?.t#.-
00000080: 6c98 70df                                l.p.

Try it online!

C# (.NET Core), 240 232 231 227 bytes
_=>{var r="";for(int i=0,j,k=0;i<126;i++)for(j=0;j++<@"2(g,d1`0]1_.a.c.a*e,b0]2\2D'45A,093#+,,@0$'.-G*$(*1_1P#.3N$.,(#M*(,W('1R*%0V*#2(#I@'#GIEIEK@O@O>Q<S;U:V6Y5[2^2]1_0`.a.a.c*e(h&"[i]-34;)r+=++k%75<1?'\n':" *"[i%2];return r;}

Try it online!
Same approach as for my C# answer for the Batman challenge.

4 bytes saved thanks to Neil! His Charcoal tip could also be applied here! :)

Oh, well, if you're accepting C# tips, then r+=++k%75<1?'\n':" *"[i%2] can be r+=++k%75?" *"[i%2]:'\n'.

@Neil no, it can't. In C# the int type is not automatically cast to bool.

Oh, it's as stupid as Java then?

@Neil yes, it is. :-)

Python 2, 227 223 218 216 bytes

Thanks @Mr. Xcoder for 2 bytes: j%2>0 can be just j%2

for k in range(46):print''.join(ord(i)*' !'[j%2]for j,i in enumerate('''E
B>;=?A?C
@;:"

%=.,
+
504'%'#'#)--/13479<;=>??ACF0'''))[75*k:][:75]

Try it online!

How I obtained the string!

Inspired from this answer

Explanation
The idea is to store the information as the count of total characters in a cluster. For eg:ssssss!!!!ssss is encoded as [6,4,4](and since we have to just alternate thru two characters, this becomes easy. ;) ) This info can be compiled as a string by ascii characters for each count (see the string literal). Now we simply obtain the count and draw ! or a space alternately.

-2 bytes

JavaScript (ES7), 239 bytes
Encodes the shape and the line breaks separately.

let f =

_=>'h7hbigkfigjdjdldl9lbkfihhhz6fkwbeoi2ab9vf36d812937991qa1b2db193d472189731i7671d9451h927721486212f10e10fvfvftfrfqgphlhkihjhjgkfldldldn9n7o5'.replace(/1?./g,n=>' X'[i&1].repeat(parseInt(n,36)-1)+((++i|716000693/2**(i/2))&1?'':`
`),i=-26)

o.innerHTML = f()

Retina, 289 bytes

16:16;,7#/9#,7#/8-18<<"!%20;,9#,7#&,6#@34&/4#"!31;,3#;&!17!9;!%8'"14&5-7=!8&6"!%8'=%9=;&1-10=;2-3"1="!8:2''@!6@%6''8&%>'@8%6"1=&%7@!1=%1>;/3';/>:1>:1>&,>,>%15'¶16#",6#"%17#&,8#&,8#/9#!%20<<-22"!%22:23@45
@
&&
>
4'
=
'#
<
-20
;
"&
:
"¶
/
&%1
-
#¶
,
!%1
'
##
&
!!
%
!¶
#
""
"
!!!!!!
\d+
$*

Try it online!

JavaScript (ES6), 254 253 251 bytes
_=>`f5
f9
ge
id
ge
hb
hb
jb
j7
j9
id
gf
ffx4
diu9
cmg089
7td14b
6z07157
7zo
8z90b
9z71b
250z675
1zg54
5zb72
3zf70
550z2
640z0
dy
cy
dt
dt
dr
dp
do
en
fj
fi
gf
hf
he
id
jb
jb
jb
l7
l5
m3`.replace(/./g,m=>" !"[i%2].repeat(parseInt(m,36)+1,i+=m<"z"),i=0)

Test it

o.innerText=(
_=>`f5
f9
ge
id
ge
hb
hb
jb
j7
j9
id
gf
ffx4
diu9
cmg089
7td14b
6z07157
7zo
8z90b
9z71b
250z675
1zg54
5zb72
3zf70
550z2
640z0
dy
cy
dt
dt
dr
dp
do
en
fj
fi
gf
hf
he
id
jb
jb
jb
l7
l5
m3`.replace(/./g,m=>" !"[i%2].repeat(parseInt(m,36)+1,i+=m<"z"),i=0)
)()

C (gcc), 255 244 239 bytes
b,c;main(a){for(;a="TFy!QJu ROo TNn(ROo)SLq SLq ULo+UHs UJq TNn*RPn/QPbEWS_JSWQAIJO^NBELPeHBFHT}TnALVlBLOFAkHFOuFETpHCStHAUFAgcEAelclcn^r^r\\tZvYxXyT|S~Pn SPm SOn TNn ULo0ULo#ULo-WHq!WFs XDt!"[b++];)for(;a-->64;putchar(++c%80?33-b%2:10));}

Slightly bugfixed and golfed version of OP's reference implementation.
Try it online!
Minimally less golfed:
b,c;
main(a){
  for(;a="TFy!QJu ROo TNn(ROo)SLq SLq ULo+UHs UJq TNn*RPn/QPbEWS_JSWQAIJO^NBELPeHBFHT}TnALVlBLOFAkHFOuFETpHCStHAUFAgcEAelclcn^r^r\\tZvYxXyT|S~Pn SPm SOn TNn ULo0ULo#ULo-WHq!WFs XDt!"[b++];)
    for(;a-->64;)
      putchar(++c%80?33-b%2:10);
}

C (gcc), 205 bytes
My solution quickly converged on something extremely close to ceilingcat's golfed version of OP's implementation, but output does differ slightly when it comes to leading spaces on each line, since I worked from the text found in OP's post, which does not exactly match the output of the reference implementation, most likely due to OP missing the leading spaces required for code text, but there are answers using that text as reference, so it's somewhat ambiguous.
i,j;main(c){for(;c="B8w<tAp@mAo>q>s>q:u<r@mBlBT7DEQ<@IC3;<
=W:48:AoA`3>C^4><83]:8<g87Ab:5@f:3B83YP73WYUYU[P_P_NaLcKeJfFiEkBnBmAo@p>q>q>s:u8x6b"[i++];)for(;c---50;j++)printf("\n%c"+(!j||j%75),33-i%2);}

Try it online!

Vyxal j, 442 bytes
»⌐ṫżṫṗƛ&%≠ɽ_~ẇ*⁼3L ≈;n~U7⋏₇ḭǔ°₁>Aµ1I(□]:ȯ≤KWƒʁY•₇⟩-RCa⟨&8ẋżṫẏL_ġN⇧ṗḞΠṄẇ%¨ḃ₆Q<Zǒ,]„∨TC⁋⟩`ɾOn^≬İ¾¨Ṫlṅ^£†i-ẏ₂↓∷×ṘǍ¶G?∑x∪ż∪İɖ¹p*₴Ḣ≈J₀↳₁‡x⌈↳D4xJḢmḃẇDpeH&⋏¹!≥₇∑;↑≬m†¥⁋†₇,Ż∪ß^ċ¡}GBİ£:U~ʁ⌈∴Ṡ^ṗ⁺Ȯo↓Ṅ%Ẏṗ§∴ḭ₈Ṁ‛∑ø≈dOƒ¥¤ɖ4Ẏ{⅛I∞_uė∇ṫḭB?U≤ǔ9F⟑q₴ẆŀṠz∞₁XṖ¨‛₇VB₁τḟAsżǒxP∵9)&∵β"Ż∆ ↲,₴øxJT.t꘍/₴ǎpe↔ḟqȯ(^≥Vḭ⁰Ȯɽτ∆ṙ°÷lW≠⇧Cb≠²∩]±ḭy∧D℅øJǔ₅⅛EGḭ≥ẋZ≥×8nΠḋ⟩)Ṗv‹'⇧@jq≥ḟ⁽]¾fǎ⅛Ȯ⌊bDa^ṀP;}ṫ⁼τ1„√ɽh⇩GW€⁼[6¼U~j_IṘ†gJ↔Ȧ$°§_„)Ż"₅‡xußġ₃ǔ↔×ɖɖ[æ¥s‹⁰≈c†t‹ṪṙḊ꘍bεβ¶∩∩{ǒḢġ†₅⟨L⌐∨H»`! `τ75ẇ

Try it Online!
Plain old binary, AKA I'm losing to everyone.


text:
Invisible Writing
In the physical world, invisible ink usually becomes invisible when it dries, and is then is readable if it is exposed to heat or chemicals of some kind. The invisible ink in this challenge will be readable when exposed to highlighting.
Create a full program or function that takes in text from the console (using a prompt) and outputs it the console so it cannot be seen unless highlighted (selected, as you would with a mouse).

Notes:

Assume that the console is a solid color (black, white, green, etc.).

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

Isn't this requirement heavily platform-dependent?

@FelixPalmen in what way?

different consoles in different operating systems have different ways how to control them, so if a solution doesn't use a language with integrated terminal/console control functions, it would need to also specify what OS and terminal/console it is targeting.

@FelixPalmen hmm, makes sense. Is there a problem with that?

Or you could specify it like e.g. "the output should use standard ANSI terminal control sequences"

IDK if this is a problem ... maybe when it comes to comparing the solutions ....

Is there a maximum length for the input ?

Couldn't we just assume our console uses a black background with black foreground, but the highlight color is white?

@HatsuPointerKun No, there is not.

@miles I decided against that because then you could just output black text.

What counts as highlighting? Selecting the text? Changing the colour after printing? Changing the background colour?

@TheLethalCoder Selecting the text. I will update the challenge.

HTML, 28 bytes: <input style="color:white"/>

@BetaDecay, simple white is not enough, because for example Firefox's text input has a gray gradient background: https://i.stack.imgur.com/c7Dz6.png Better this: <input style=color:#fff0>

Bah, Batch specifically guards against outputting invisible text...

@manatwork; it only needs to work in one browser in order to be valid.

@CalebKleveter I can copy the content in the console in a text file to reveal the output. Does this counts as highlighting ? Because highlighting in the windows console will change both foreground and background colors ( so black foreground and black background will become white foreground and white background ), and i can't prevent it

@manatwork Well how about this: <input style="color:white;background:white"/>?

@Shaggy, possible. Not sure what the question owner's comment on a solution wants to mean. I interpreted as the 1 working environment is not enough here.

@BetaDecay, if you set both colors yourself, then maybe <input style=color:red;background:red>.

JavaScript (ES6), 44 42 bytes
Tested in Chrome & Firefox.
s=>console.log("%c"+s,"color:transparent")

Try it
Open your browser's console.

(
s=>console.log("%c"+s,"color:transparent")
)("Invisible Text!")

Japt, 21 20 bytes
Will post this separately when/if the challenge is reopened
Ol"%c"+U`¬l:ÉspÂÁt

Test it

I can't see the text if I highlight it: https://i.stack.imgur.com/RAVhS.png

Try a different browser, @CalebKleveter. Also, no need to paste it into your console, you can just run the Snippet above.

This works fine in the javascript-console of Chromium. But @CalebKleveter -- see what I meant with heavily platform-dependent ;)

Magneson, 102 bytes

(source: googleapis.com)
(Note that the above is an enlarged version of the program, and the action source can be found here
This is my first submission in a long while, so while I think Magneson does classify as a language according to this, if it's not suitable let me know and I can take it down.
Onto the "code" itself; Magneson operates by parsing an image and evaluating commands from the colours of the pixels it reads. So stepping through the image for this challenge, we have:

R: 0, G: 0, B: 1 is a simple println statement; it prints a string out to the console

R: 255, G: 255, B: 0 is a string operative to concatenate the following values, until we receive a stop concatenate op.

R: 2, G: 0, B: 27 is a raw character. In strings, when the red component is 2 and the green component is 0, we simply use the blue component as a raw character to add to the string. In this case, we add the escape character for ANSI control strings.

R: 2, G: 0, B: 91 is another raw character ([)

R: 2, G: 0, B: 51 is another raw character (3)

R: 2, G: 0, B: 48 is another raw character (0)

R: 2, G: 0, B: 59 is another raw character (;)

R: 2, G: 0, B: 52 is another raw character (4)

R: 2, G: 0, B: 48 is another raw character (0)

R: 2, G: 0, B: 109 is another raw character (m)

R: 3, G: 0, B: 0 is a string operative for input from STDIN. In this case, it just appends it to the concatenated string.

R: 255, G: 255, B: 1 is the end concatenation op.
All in all, this program builds a string of ESC[30;40m, followed by one line of input from the command line. This'll set both the foreground and background colours to black.

This doesn't work when the background colour is not black

Just saw that requirement (Error on my part). Updated to account for that

Not really sure how to test this but when you select the text can you see it?

It does on my system at least, since it's just using ANSI control codes

same general problem as with my solution, you just can't control (with ANSI escape sequences) what a terminal actually does when displaying a selection. I'll try a few terminals soon and can hopefully add a list of some supported ones to my solution (windows 10 console is not among them)

C (gcc), 77 91 bytes
c;main(){printf("\x1b]11;2\a\x1b[42;32m");while((c=getchar())>0)putchar(c);puts("\x1b[m");}

Try it online! (will only show the raw output including the escape sequences)
Extra bytes were necessary to be independent from the original background color, see discussion in the comments.
This version uses ANSI escape codes to set the background and foreground colors to green as well as an Xterm escape code to change the background of the whole window to green. This way, if your selection color doesn't happen to be (dark) green (very unlikely), it will work on terminals supporting ANSI escape sequences and compatible with Xterm.
It works for example in rxvt as seen in these screenshots:

I'm pretty sure this doesn't work for the reasons you have stated.

As stated, whether it works or not depends on how the terminal handles selection display. It doesn't work on a windows console, unfortunately.

Yes but you've also hard coded the colour, what happens when the background is white?

It doesn't bother me that it doesn't work on a windows console. What I did notice was that you said it only works on a black background. A solution should work on any solid colored terminal.

@CalebKleveter in this case, it must either be allowed to change the background color as well or there's no solution for terminals that can only be controlled by ANSI sequences.

I never put in the challenge that you can't change the terminal color. I never thought of that, so you can use it to your advantage.

@CalebKleveter fixed with a solution doing exactly that, but in green. Still requires some specific support from the terminal, works e.g. (as stated) with rxvt.

82 bytes main(c){for(printf("\e]11;2\a\e[42;32m");~(c=getchar());)putchar(c);puts("\e[m");}


text:
Restricted Integer Partitions
\$P_k(n)\$ means the number of partitions of \$n\$ into exactly \$k\$ positive parts. Given \$n\$ and \$k\$, calculate \$P_k(n)\$.

Tip: \$P_k(n) = P_k(n−k) + P_{k−1}(n−1)\$, with initial values \$P_0(0) = 1\$ and \$P_k(n) = 0\$ if \$n \leq 0\$ or \$k \leq 0\$. [Wiki]

Examples
n    k    Ans
1    1    1
2    2    1
4    2    2
6    2    3
10   3    8

Rules

General code-golf rules apply.

Can someone link to the OEIS for this (I assume there is one with the number of partition sequences we've been running into on the CnR OEIS post)

Related

A008284

Is restricting the second input, k, to non-negative integers is acceptable? Also should the solution work for negative n? Zero n? (my guesses are yes, yes, and yes)

If k is fixed the generating function for this is x^k/((1-x)*(1-x^2)*...*(1-x^k)).

@JonathanAllan I don't see how k can be negative, given it's the length of a partition.

This needs more detail. Can 0 be a partition element? Can a partition contain duplicates? Do we count only increasing partitions?

@EriktheOutgolfer there are, by the very definition provided in the OP, 0 partitions for k<=0. (and my guess to the answer to my question was "yes" too)

@Zgarb it could help to add such information to the post, yes. But to address these questions "an integer partition is a way of writing n as a sum of positive integers. Two sums that differ only in the order of their summands are considered the same partition.", so: no zeros inside; duplicates are acceptable; disregard order for counting. (Note that P(0,0) is 1 however - one way to have the empty set).

In the tip, if P0(0)=1, shouldn't the condition in the other case be <0 instead of ≤ 0?

@JAD No, ≤ is correct, it's just that "if both are not zero" is missing.

Python 2, 61 55 51 50 bytes
-10 bytes thanks to Erik the Outgolfer. -1 byte thanks to Mr. Xcoder.
I will say, I did copy the hint from OP and translate it to Python. :P
P=lambda n,k:n*k>0and P(n-k,k)+P(n-1,k-1)or+(n==k)

Try it online!

This breaks on the last test case of 10, 3. Too much recursion

@jkelm Fixed. -

(n>0and k>0) -> n>0<k

Heh, nice abuse of Python's comparison operators. I wish there was a way to have the 0 at the end though, so I could get rid of that space...

Also you can do +(n==k) instead of [0,1][n==k].

You don't need the space in or +.

"I will say, I did copy the hint from OP and translate it to Python" - I don't feel so bad that my solution ended up being so similar to yours, now!

50 bytes, replace n>0<k and with n*k>0and

(also @EriktheOutgolfer) What is the + in +(n==k) for exactly? This seems to work for 48.

To cast n==k to an integer. Technically, True instead of 1 and False instead of 0 is allowed but it shaves off 3 bytes and is just... meh.

@JonathanAllan + converts True/False to 0/1

Does it ever need to be cast though, wont the addition in the pre-tail call always exist, hence casting any boolean results to integers?

@JonathanAllan Not always.

@EriktheOutgolfer right - if numbers less than 1 are required to be handled I suppose.

@totallyhuman nothing is "just ...meh" when it comes to shaving off bytes ;p

Swift, 76 73 bytes
func P(_ n:Int,_ k:Int)->Int{return n*k>0 ?P(n-k,k)+P(n-1,k-1):n==k ?1:0}

Try it online!

Explanation
How does the code structurally work?
First of all, we define our function P, with two integer parameters n and k, and give it a return type of Int, with this piece of code: func P(_ n:Int,_ k:Int)->Int{...}. The cool trick here is that we tell the compiler to ignore the names of the parameters, with _ followed by a space, which saves us two bytes when we call the function. return is obviously used to return the result of our nested ternary described below.
Another trick I used was n*k>0, which saves us a couple of bytes over n>0&&k>0. If the condition is true (both the integers are still higher than 0), then we recursively call our function with n decremented by k as our new n and k stays the same, and we add the result of P() with n and k decremented by 1. If the condition is not true, we return either 1 or 0 depending on whether n is equal to k.
How does the recursive algorithm work?
We know that the first element of the sequence is p0(0), and so we check that both integers are positive (n*k>0). If they are not higher than 0, we check if they are equal (n==l ?1:0), here being two cases:

There is exactly 1 possible partition, and thus we return 1, if the integers are equal.

There are no partitions if one of them is already 0 and the other is not.

However, if both are positive, we recursively call P twice, adding the results of P(n-k,k) and P(n-1,k-1). And we loop again until n has reached 0.

* Note: The spaces cannot be removed.

Pyth, 9 7 6 bytes
-1 byte thanks to Erik the Outgolfer!
/lM./E

Try it online!
Inputs to the program are reversed (i.e. k, n).

Jelly, 6 bytes
œċS€ċ⁸

Try it online!

Ah ha, of course!

Mathematica, 33 bytes
Length@IntegerPartitions[#,{#2}]&

here is n x k table
 \k->
 n1  0  0   0   0   0   0   0   0   0
 |1  1  0   0   0   0   0   0   0   0
 v1  1  1   0   0   0   0   0   0   0
  1  2  1   1   0   0   0   0   0   0
  1  2  2   1   1   0   0   0   0   0
  1  3  3   2   1   1   0   0   0   0
  1  3  4   3   2   1   1   0   0   0
  1  4  5   5   3   2   1   1   0   0
  1  4  7   6   5   3   2   1   1   0
  1  5  8   9   7   5   3   2   1   1

Of course. I knew there was a builtin.

A Mathematica Simplified port would save a 13 bytes here I believe (Length->Len`1 and IntegerPartitions -> Int`7

@JonathanAllan I'm actually making a super-short version of this. Hopefully I can finish it by the end of the month

MATL, 14 bytes
y:Z^!S!Xu!Xs=s

Try it online!
Explanation
Consider inputs 6, 2.
y     % Implicitly take the two inputs. Duplicate from below
      % STACK: 6, 2, 6
:     % Range
      % STACK: 6, 2, [1 2 3 4 5 6]
Z^    % Cartesian power
      % STACK: 6, [1 1; 1 2; ... 1 5; 1 6; 2 1; 2 2; ...; 6 6]
!S!   % Sort each row
      % STACK: 6, [1 1; 1 2; ... 1 5; 1 6; 1 2; 2 2; ...; 6 6]
Xu    % Unique rows
      % STACK: 6, [1 1; 1 2; ... 1 5; 1 6; 2 2; ...; 6 6]
!Xs   % Sum of each row, as a row vector
      % STACK: 6, [2 3 ... 6 7 4 ... 12]
=     % Equals, element-wise
      % STACK: [0 0 ... 1  0 0 ... 0]
s     % Sum. Implicitly display
      % STACK: 3

Honestly I'm surprised MATL doesn't have an "integer partition" builtin or something.

@Sanchises It should be working now. Thanks for telling me!

No problem. I was just playing with it to understand your method (which is generally easier for small cases) when I ran into the error.

JavaScript (ES6), 42 40 39 bytes
I think this works.
f=(x,y)=>x*y>0?f(x-y,y)+f(--x,--y):x==y

Try it

k.value=(
f=(x,y)=>x*y>0?f(x-y,y)+f(--x,--y):x==y
)(i.value=10,j.value=3)
onchange=_=>k.value=f(+i.value,+j.value)
*{font-family:sans-serif}input{margin:0 5px 0 0;width:100px;}#j,#k{width:50px;}
n: <input id=i type=number>k: <input id=j type=number>Pk(n): <input id=k readonly>

Haskell, 41 bytes
0#0=1
n#k|n*k>0=(n-k)#k+(n-1)#(k-1)
_#_=0

Try it online!

Pari/GP, 35 bytes
Pari/GP has a built-in for iterating over integer partitions.
n->k->i=0;forpart(x=n,i++,,[k,k]);i

Try it online!

C (gcc), 41 40 bytes
f(n,k){n=n*k>0?f(n-k,k)+f(--n,--k):n&k;}

Try it online!

Haskell, 41 bytes
n&0=0^n
n&k=sum$map(&(k-1))[n-1,n-k-1..0]

Try it online!
An alternate recurrence.

05AB1E, 5 bytes
ÅœIùg

Try it online or verify all test cases.
Explanation:
Åœ     # Get all lists of positive integers that sum to the first (implicit)
       # input-integer `n`
   ù   # Only keep the lists with a length equal to
  I    # the second input-integer `k`
    g  # Pop and push the length to get the amount of remaining lists
       # (which is output implicitly as result)

Jelly, 13 bytes
I have a feeling know this basic approach won't be the golfiest!
RŒṖL€€Ṣ€QṀ€=S

Try it online!

Yeah it isn't (see my Jelly answer at the far bottom).

Oh no Code bowling

@EriktheOutgolfer If it works why is it deleted?

@Jonathan refresh

@JonathanAllan It was deleted before a test case was fixed.

05AB1E, 9 bytes
L²ã€{ÙO¹¢

Try it online!

CJam, 18 bytes
{_,:)@m*:$_&::+e=}

Try it online!
Expects inputs in reverse, i.e. k n instead of n k.

Scala, 98 bytes
Well this is some easy unreworked use of OP's tip.
k and n are the parameters of my recursive function f.
def f(n:Int,k:Int):Int={(k,n)match{case(0,0)=>1
case _ if k<1|n<1=>0
case _=>f(n-k,k)+f(n-1,k-1)}}

Try it online!

This is invalid as it's a snippet, not a proper function.

R (+ pryr), 49 bytes
f=pryr::f(`if`(k<1|n<1,!n+k,f(n-k,k)+f(n-1,k-1)))

Which evaluates to the recursive function
function (k, n)
if (k < 1 | n < 1) !n + k else f(n - k, k) + f(n - 1, k - 1)

(k < 1 | n < 1) checks if any of the initial states are met. !n + k evaluates to TRUE (1) if both n and k are 0, and FALSE (0) otherwise. f(n - k, k) + f(n - 1, k - 1) handles the recursion.

Regex  (Perl/PCRE+(?^=)RME), 32 28 bytes
^((?^=(\2?x))(\1|^x)x*)+,\2$

Try it on replit.com (RegexMathEngine)
Takes its input in unary, as the lengths of two strings of xs delimited by a ,, specifying \$(n,k)\$. Returns its output as the number of ways the regex can match. (The rabbit emoji indicates this output method. It can yield outputs bigger than the input, and is really good at multiplying.)
This simply enumerates all the partitions. In order to count unordered partitions, it enforces that partitions occur in strictly nondecreasing order. This is accomplished by starting with an arbitrary-sized partition on the first iteration, then increasing it by an arbitrary nonnegative integer on each subsequent iteration. Each iteration increments the counter, which is then compared with \$k\$ at the end.
On each iteration, the size of the partition (arbitrarily chosen) is captured in \1, which is accessed via a nested backreference. The counter is stored in \2. Lookinto is used to ensure there is room to read and increment \2 on each iteration.
^                   # tail = N
(                   # \1 = the following, looping:
    (?^=            # Lookinto; tail = N
        (           # \2 = sum of the following:
            \2?     # previous value of \2 if set, else 0
            x       # 1
        )
    )
    # \1 = the sum of the below items
    (
        \1          # On subsequent iterations, \1
    |
        ^x          # On the first iteration, 1
    )
    x*              # any nonnegative integer
    # \1 = some of the above items
)+                  # Iterate the above as many times as possible, min 1
,                   # Assert tail == 0; tail = K
\2$                 # Assert tail == \2

This uses nested backreferences (supported by Java / Perl / PCRE / .NET), a branch reset group (Perl / PCRE / Pythonregex), and a lookinto, a feature just added to RegexMathEngine. The parameterless form of it, (?^=pattern), is equivalent to one of the common uses of variable-length lookbehind, (?<=(?=pattern)^.*) – it allows matching against the entire string, even after the top-level cursor has advanced past the start. It also has a parametrized form, e.g. (?^5=pattern) will match pattern against the current contents of \5.
Regex  (RME / Perl / PCRE2 v10.35+), 36 34 bytes
^((?|(?=.*,(\2x))\1x*|^(x)+))+,\2$

Try it on replit.com (RegexMathEngine)
Try it online! - Perl v5.28.2 / Attempt This Online! - Perl v5.36+
Attempt This Online! - PCRE2 v10.40+
Attempt This Online! - PCRE2 v10.40+ - test cases only
Without lookinto, there's still always room within \$k\$, accesible via lookahead, to count iterations.
Starting with a positive arbitrary-sized partition on the first iteration is done by ^(x)+, which also initializes the counter to \$1\$. On subsequent iterations, \1x* advances by the sum of \1 and any arbitrary nonnegative integer, which also gets captured in \1. At the end, , asserts that the cumulative sum is equal to \$n\$.
To enforce \$k\$ as the number of partitions, it starts by setting \2 \$=1\$ on the first iteration with ^(x)+. On subsequent iterations, (?^=(\2x)) increments \2 by \$1\$. Lookahead is used to avoid not having room for \2\$+1\$ when nearing the end of \$n\$. The Branch Reset Group (?|...|...) allows \2 to be captured/recaptured in these two places.
^                   # tail = N
(                   # \1 = the following, looping:
    (?|             # Branch Reset Group
        # This alternative can only match on iterations after the first, because
        # it unconditionally matches \1 and \2.
        (?=         # Lookahead
            .*,     # tail = K
            (\2x)   # \2 += 1
        )
        \1x*        # \1 += {any nonnegative integer}; tail -= \1
    |
        ^           # Anchor to start, to only match on the first iteration.
        (x)+        # \2 = 1; \1 = {any nonnegative integer}; tail -= \1
    )
)+                  # Iterate the above as many times as possible, min 1
,                   # Assert tail == 0; tail = K
\2$                 # Assert tail == \2

Regex  (RME / Perl / PCRE2), 50 bytes
^((?=(?(3)(\3)))((?|(?=.*,(\4x))\2x*|^(x)+)))+,\4$

Try it on replit.com (RegexMathEngine)
Try it online! - Perl v5.28.2 / Attempt This Online! - Perl v5.36+
Try it online! - PCRE2 v10.33 / Attempt This Online! - PCRE2 v10.40+
Attempt This Online! - PCRE2 v10.40+ - test cases only
PCRE1, and PCRE2 up to v10.34, automatically makes any capture group atomic if it contains a nested backreference. To work around this, the capture is copied back and forth between \2 and \3 using only forward-declared backreferences.
This would also make the regex compatible with Pythonregex and Ruby, but they have no way of doing  output without source code modifications.
It still doesn't work under PCRE1, probably due to its bug where in certain conditions, captures are not reverted to their earlier values when backtracking: Try it online!
^                      # tail = N
(                      # \1 = the following, looping:
    (?=
        (?(3)(\3))     # If \3 is set, \2 = \3, else leave \2 unset
    )
    (                  # \3 = the following, to avoid a nested backreference
        (?|            # Branch Reset Group
            # This alternative can only match on iterations after the first,
            # because it unconditionally matches \1 and \2.
            (?=
                .*,    # tail = K
                (\4x)  # \4 += 1
            )
            \2x*       # \3 = \2 + {any nonnegative integer}; tail -= \3
        |
            ^          # Anchor to start, to only match on the first iteration.
            (x)+       # \4 = 1; \3 = {any nonnegative integer}; tail -= \3
        )
    )
)+                     # Iterate the above as many times as possible, min 1
,                      # Assert tail == 0; tail = K
\4$                    # Assert tail == \4

Vyxal, 5 bytes
ṄvL=∑

Try it Online!
Jelly, 5 bytes
ŒṗẈ=S

Try it online!
Dang it, ninja'd by Kevin because I took the time to get the shortest jelly answer too :p
Exact same approach as the 05ab1e answer, derived independently - both answers get the integer partitions of the first input and then count the number of partitions where the length equals the second input.

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


text:
ASCII Hangman in Progress
(inspired by a question over on Code Review)
Suppose two people are playing Hangman, but you've only overheard the game and want to draw the current status.
Given two words as input, where the words each match [A-Z]+ or [a-z]+ (your choice), output the current state of the hangman game as ASCII art, following the below rules.

The first word is the word to be guessed, and the second word is the already-guessed letters. These can be taken as input in any order.
The word to be guessed is guaranteed non-empty, but the already-guessed letters may be empty (i.e., as if it's the start of the game).
The game will always be a valid hangman game (i.e., guessed letters won't be duplicated, letters won't be guessed past the end of the game, you'll only receive letters as input, etc.).
Below the hangman drawing must be the word to be guessed, with _ in place of letters yet unknown, separated by spaces. For example, if the word to be guessed was BOAT, then below the hangman drawing must be _ _ _ _. If the word was BOAT with A guessed, then below the drawing must be _ _ A _.
Below the word to be guessed must be letters already guessed that are not in the word. These can be in any order, and can be separated by any non-alphabetical separator, if so desired.

Here are the states of the hangman game, from initial start to game end. Each wrongly guessed letter advances the state by one. So the first wrongly guessed letter makes the head O appear, the next makes the body | appear, etc.
  +---+
  |   |
      |
      |
      |
      |
=========

  +---+
  |   |
  O   |
      |
      |
      |
=========

  +---+
  |   |
  O   |
  |   |
      |
      |
=========

  +---+
  |   |
  O   |
 /|   |
      |
      |
=========

  +---+
  |   |
  O   |
 /|\  |
      |
      |
=========

  +---+
  |   |
  O   |
 /|\  |
 /    |
      |
=========

  +---+
  |   |
  O   |
 /|\  |
 / \  |
      |
=========

Input

Two strings in any convenient format, with the first guaranteed non-empty.
You can take the input in either order (e.g., word to guess and then guessed letters, or vice versa). Please state in your submission the input order.

Output
The resulting ASCII art representation of the hangman game in progress, as described above, again in any convenient format.
Rules

Leading or trailing newlines or whitespace are all optional, so long as the characters themselves line up correctly.
Either a full program or a function are acceptable. If a function, you can return the output rather than printing it.
If possible, please include a link to an online testing environment so other people can try out your code!
Standard loopholes are forbidden.
This is code-golf so all usual golfing rules apply, and the shortest code (in bytes) wins.

Examples
#1
BOAT and ATG
  +---+
  |   |
  O   |
      |
      |
      |
=========
_ _ A T
G

#2
ZEPPELIN and
  +---+
  |   |
      |
      |
      |
      |
=========
_ _ _ _ _ _ _ _

#3
ZEPPELIN and EATOLINSHR
  +---+
  |   |
  O   |
 /|\  |
 / \  |
      |
=========
_ E _ _ E L I N
A T O S H R

#4
RHYTHM and ABCDE
  +---+
  |   |
  O   |
 /|\  |
 /    |
      |
=========
_ _ _ _ _ _
EDCBA

#5
BOAT and ATOB
  +---+
  |   |
      |
      |
      |
      |
=========
B O A T

#6
AIRPLANE and AJKEI
  +---+
  |   |
  O   |
  |   |
      |
      |
=========
A I _ _ _ A _ E
KJ

the wrong letters must preserve the input order?

@Rod No, don't need to preserve the order of the incorrect guesses.

Please add a test case where all the letters are correctly guesses and one where all have been guessed

@Mr.Xcoder I've added test case #5 where the person successfully guessed "BOAT" right away.

I've added a test case that has only 2 incorrect letters to distinguish between the correct building order and building top-to-bottom/left-to-right.

@JustinMariner Good clarification - thanks!

Python 2, 215 192 184 183 bytes
-8 bytes thanks to Raphaël Côté
-1 byte thanks to Jonathan Frech

a,b=input()
j=' '.join
s=b-set(a)
print"""  +---+
  |   |
  %s   |
 %s%s%s  |
 %s %s  |
      |
=========
"""%tuple('O/|\/\\'[:len(s)].ljust(6)),j(['_',i][i in b]for i in a),'\n',j(s)

Try it online!

By converting all \n to newlines and using a multiline string with """, and also by using " any convenient format " of input and setting the set calls back into the input, I was able to drop to 172 bytes.

hmm, could you link the changes? I only managed to reach 184 bytes

184 is good: removing the sets from the code actually broke the output, so that did not work. Changing the \n so they became newlines did help but I actually only removed 3 bytes to 189.https://tio.run/##NczBCoJAEAbg@z7FIMjs4qrQoUOwhw5CQaRUp1wJBaMVWcVdD4HvbqvVPwz/dximf9tXpzfzXPJKKN2PljLSCASMmk5pYoSpLa1YuFTJSD8obT3PAwjCMAwIwARuXfvmC98s8yP8tGYi4h/iXvh27NuaYhpPUsZSYr5ra00NK6K2GY2lW8Z4Q3N8IFdFrkBpqIpnN8DKknGUGt2FYfOM9yTLktPxjByT/S11uh4u@AE

I believe you should be showing the body piece (|) instead of the left arm (/) when there are 2 wrong letters: Try it online

"\\/" is equal to "\/".

Charcoal, 83 69 68 bytes
Ｆη¿№θι⁰«ι→⊞υι»←⸿Ｆθ«⎇№ηιι_→»←⸿×=⁸↖=←↑⁵←+←³↓+|ＦＬυ≡ι⁰↓O¹←|²/|³\⁴⸿ /⁵ \«

Try it online! Link is to verbose version of code. Edit: Saved 14 bytes by switching to switch. Saved 1 byte by printing the single | as a literal. Note: At the time the question was set, switch didn't work at all in Verbose mode and needed a trailing « in Succinct mode (the current version on TIO has neither bug, so it shows the Succinct translation as 67 bytes), while Map's bugs prevented me from using Print(Join(Map(q, Ternary(Count(h, i), i, "_")), " "));. Fortunately I managed to come up with a kludge for the same length (and indeed I also tried switching the other loop to a Map but it too came out at the same length). Explanation:
Ｆη              For each letter in the guess,
  ¿№θι⁰«        if the word to be guessed does not contain the letter,
        ι→      print the failed guess, leave a gap,
          ⊞υι»  and push the letter to the array.

←⸿              Move to the start of the previous line.

Ｆθ«             For each letter in the word to be guessed,
   ⎇№ηιι        if the letter has been guessed then print it
        _       otherwise print a _.
         →»     Either way, leave a gap.

←⸿              Move to the start of the previous line.

×=⁸             Print 8 =s
   ↖=←          Print a 9th =, moving into position to
      ↑⁵        print 5 |s upwards,
        ←+←³    a + and 3 -s left,
            ↓+| and a + and a | down.

ＦＬυ             Loop once for each incorrect guess.
   ≡ι           Choose what to print based on the loop index.
     ⁰↓O        For the first incorrect guess, print an O.
     ¹←|        For the second incorrect guess, print a |.
     ²/         For the third incorrect guess, print a /.
     ³|\        For the fourth incorrect guess, print a \.
     ⁴⸿ /       For the fifth incorrect guess, print a / on the next line.
     ⁵ \        For the sixth incorrect guess, print another \.

this language...it scares me.

@SergeyGrinev D: why is it so scary

@ASCII-only I noticed you fixed Map(string, expression) but Map(array, expression) is still buggy - it alters the original array when used as an expression rather than as a command. Try it online!

@ASCII-only hehe, it's a great idea for a language, but scripts looks like something Lovecraft would use to summon Cthulhu spell.

@Neil That's intended behavior, mostly so it modifies the canvas when mapping the Cells datatype, but I guess yeah you'd often need to use the original data after the map, it should be fixed by tomorrow

@ASCII-only So the idea will be that you can MapCommand(Peek...)?

Yeah, an example is in the showcase, not sure if it's in the repo as well (also crap haven't fixed this yet will be back on a computer in 10-12 hours)

@Neil god I'm honored to tie with a charcoal answer of yours lol. I literally spent 20 minutes looking for 1 last byte to beat you, but can't find it.

@MagicOctopusUrn Sorry to disappoint you...

Python 2, 220 bytes
x,y=input()
x=[['_',k][k in y]for k in x]
y-=set(x)
s='''  +---+
  |   |
  0   |
 213  |
 4 5  |
      |
'''
for i in range(6):s=s.replace(`i`,[' ','O|/\\/\\'[i]][len(y)>i])
print s+'='*9+'\n'+' '.join(x)+'\n'+''.join(y)

Try it online!
-35 bytes thanks to Raphaël Côté
-20 bytes using sets
-1 byte thanks to micsthepick

nice idea for the "replace" with numbers :)

@V.Courtois Thanks :) I was going to use translate but that turned out to be longer lol.

Hi @HyperNeutrino, good job with the submission!
I think that the 2 loops at the end could be put into one, using this
for i in range(7):s=s.replace(\i`,'O|/\/\'[i] if i<c else ' ')`.It gives you a single loop and you just switch out the replace if you are over c. You can lower to 251 bytes this way :)

@RaphaëlCôté Nice golf. Thanks!

c just became useless. Just use len(y) and save 4 bytes! We rock!

@RaphaëlCôté Hey perfect. Thanks!

Same thing here, save one byte by removing parentheses after print statement

y-=set(x), -1byte :D

@RaphaëlCôté ಠ_ಠ How did I not notice that :P Thanks!

Jelly,  72  73 bytes
+1 fixing an ace game bug that showed the full hanged person (changed LN to Lạ6 near the end)
e€a⁸o”_$,ḟ@©K€Y,@“¥[$⁼Ż⁸½c¤ṫȷṃl®ḌvNṂeL©?Ḥ’ṃ“ -¶|O/\=+”¤Y⁶“$"÷ȷñŒ‘ḣ®Lạ6¤¤¦

A dyadic link taking the word on the left and the (unique and within-game) letters on the right and returning a list of characters, or a full program taking the input as command line arguments and printing the result.
Try it online!
How?
Firstly:
“¥[$⁼Ż⁸½c¤ṫȷṃl®ḌvNṂeL©?Ḥ’ - base 250 number
                            = 305169639782226039115281574830092231403740634016078676

Is the numeric value of the full hanged person in base 9, where each of the 9 digits represent one of the characters:  <space>, <newline>, -, |, O, /, \, =, or +.
the rest of the program:
e€a⁸o”_$,ḟ@©K€Y,@“...’ṃ“...”¤Y⁶“...‘ḣ®Lạ6¤¤¦ - Main link word, letters
e€                                           - exists in letters for €ach char in word
  a⁸                                         - and with word (word with 0 at un-guessed)
    o”_$                                     - or with '_' (word with _ at un-guessed)
         ḟ@                                  - filter remove (incorrect guesses)
           ©                                 - copy the result to the register and yield
        ,                                    - pair
            K€                               - join €ach with spaces
              Y                              - join with (a) newlines
                            ¤                - nilad followed by link(s) as a nilad:
                 “...’                       - the number described above
                       “...”                 - list of chars " -¶|O/\=+" (¶ = a newline)
                      ṃ                      - base decompress using the chars as digits
               ,@                            - pair (using swapped @rguments)
                             Y               - join with (a) newlines
                                           ¦ - sparse application:
                              ⁶              -   of: a space character
                                             -   to indexes:
                                          ¤  -     nilad followed by links as a nilad:
                               “...‘         -       literal [36,34,28,26,27,19]
                                         ¤   -       another nilad chain:
                                     ®       -         recall from register
                                      L      -         length (# of bad guesses)
                                       ạ6    -         absolute difference with 6
                                    ḣ        -       head (get the indexes to "erase"
                                             -             by applying the space char)
                                             - as a full program: implicit print

This fails on the BOAT and ATOB test case. Try it online!

Ah thanks for pointing that out, I shall fix it for 2 bytes... just writing an explanation.

done, and make that 1 byte.

Note: The past tense for "hang" when it comes to people is "hanged", not "hung". Just a nitpick so have +1 for compensation :)

@ΗγρεŗN̛ευτŗιͷo Heh, I had hung in one place and hanged in another and changed the latter. (I also said "fully", as if the incomplete person had not been completely hanged too).

Ah I see :P Also +1 for the numeric value of the full hanged person in base 9 :P I will never forget that xD

That's quite the bar to beat ._.

Japt v2, 94 91 83 81 bytes
-3 bytes from some ideas from @ETHproductions' approach to this.
-8 bytes by using multiline string rotation.
-2 bytes by using v2.
["+|||||
-
-
-  35
+|01
   24
"r\d_¨VkU l ?S:"O|/\\/\\"gZÃz '=³³¡VøX ?X:'_Ã¸VkU]·

Takes both word inputs as arrays of characters, with the guessing word first and guessed letters second. Incorrect letters are shown separated by ,s. When there are no incorrect letters, the last line is blank (meaning output contains an extra trailing newline).
Try it online!
Explanation
Implicit: U and V are input char arrays.
["..."

Start an array and push the hanging man format string, rotated left 90°.
r\d_

Replace (r) every digit (\d) with the following function:
¨VkU l ?S:"O|/\\/\\"gZÃ

If the digit is >= (¨) the amount of wrong guesses (VkU l), a space (S), otherwise, get the appropriate body part for that digit ("..."gZ).
z '=³³

Rotate the hanging man right 90° and push = repeated 3*3 (³³) times to the array.
¡VøX ?X:'_Ã

Push the word-to-guess, with letters mapped (¡) to either themself (X) if contained in V (VøX), or _ if not, and joined with spaces (¸), to the array.
VkU]·

Push the guessed-letters, with the letters in the word-to-guess removed (k), to the output array. Close the array and join with newlines (·).
Rotation visualized:

+|||||      +---+
-           |   |
-      ->   0   |
-  35      213  |
+|01       4 5  |
   24

I had something similar: http://ethproductions.github.io/japt/?v=1.4.5&code=WyIgICstLS0rCiAgfCA5IDEgOTIzNDkyIDQ5ICAgICB8ImQ5IiAgfAogIiIlZCJAIiBPL3xcXCJnWCooV7A8VmtVIGzDJz2zs1Wso1b4WCA/WDonX8O4VmtVXbc=&input=IlpFUFBFTElOIgoiRUFUT0xJTlNSIg== (though now I notice I have the middle three segments put in in the wrong order). I see some parts in yours that are shorter than how I did it, maybe our answers can combine to something even shorter.

@ETHproductions I don't think your idea of incrementing W can work since the body parts don't appear left-to-right/top-to-bottom. I was able to save a few bytes from your version, though.

05AB1E, 83 bytes
•LO„Ÿ¼Ì‘Šη…ÔÆ#δʒΣ•6B4ÝJ"+ -|="‡²¹SK©Ùg"O/|\/\"s£v5y.;}7ô»„==«5ð:¹D²SKDg'_×‡Sðý®Sðý»

Try it online!

The Bitmap:
05AB1E, 18 bytes
•LO„Ÿ¼Ì‘Šη…ÔÆ#δʒΣ• # Push number described below in base-10.

Try it online!
This pushes the following bitmap plan:
1102220
1131113
1151113
1555113
1515113
1111113
4444444

Where the following additional bytes:
05AB1E, 13 bytes
6B            # Convert to base-6.
  4ÝJ         # Push 01234.
     "+ -|="  # Push that string.
            ‡ # Replace numbers with those letters.

Try it online!
Replace the pieces of the bitmap with the appropriate characters, leaving the 5's for replacing the pieces of the hangman later:
  +---+
  |   |
  5   |
 555  |
 5 5  |
      |
=======

The Hanged Man:
Next, we calculate how many times the user guessed wrong by grabbing the letters that are in the second input, but not in the first input:
05AB1E, 6 bytes
²¹SK   # Get wrong guesses.
    ©Ù # Store them, and get unique wrong letters.

Try it online!

Finally, we use a secondary bitmap to substitute in the hanged man, separating by newlines and preparing it for the final print:
05AB1E, 26 bytes
g                           # Get the number of "messups".
 "O/|\/\"s£                 # Only that many chars of the hanged "bitmap".
           v5y.;}           # Replace 5's with "bitmap".
                 7ô»        # Split into rows.
                    „==«5ð: # Remove additional 5's.

Try it online!
This results in the first pieces, the only remaining pieces being outputting the two words at the bottom in a diff format...

The Words Below:
Print the first word without the missing guesses:
05AB1E, 15 bytes
¹D²SK          # Word without the missing guesses.
     Dg'_×‡    # Replace missing guesses with "_".
           Sðý # Join by spaces.

Try it online!

05AB1E, 5 bytes
®     # Print stored missing guesses.
 Sðý  # Separated by spaces.
    » # Print everything in stack with newlines.

Try it online!
Print the calculated missed guesses from earlier we stored in a register.

I really like the bitmap idea (trying to implement it in my own answer, even), but your answer places the left arm (/) before the body (|). Two wrong letters should result in the head and body pieces showing. Try it online

Jelly, 86 bytes
3ȷ6Dẋ6Ḍ+“Ȧṇ⁹c’
œ-Lḣ@“Ñæçðøþ‘⁵*$€×“µI,’D¤¤S+¢Dị“+-|/\O ”Us7Y,”=x9¤Y;⁷,œ-ðjɓi@€ị³;”_¤K;⁷

Try it online!
Whew... this was fun. I've never used so many ¤ characters.
How it Works
3ȷ6Dẋ6Ḍ+“Ȧṇ⁹c’ (1) the literal 300000030000003000000300000030003001222100
3ȷ6              - literal 3*10^6 = 3000000
   D             - digits
    ẋ6           - repeat six times
      Ḍ          - return to integer: 300000030000003000000300000030000003000000
       +         - add
        “Ȧṇ⁹c’   - literal 2998222100

œ-Lḣ@“Ñæçðøþ‘⁵*$€×“µI,’D¤¤S+¢Dị“+-|/\O ”Us7Y,”=x9¤Y,œ-;⁷ð,ɓi@€ị³;”_¤K;⁷
œ-Lḣ@“Ñæçðøþ‘⁵*$€×“µI,’D¤¤S - representation of the body parts
œ-L                           - wrong letters length
   ḣ@                         - get that many elements from the start of
                        ¤¤    - the literal:
     “Ñæçðøþ‘                   - [16, 22, 23, 24, 29, 31]
             ⁵*$€               - 10 to the power of each of them
                 ×              - multiplies by
                  “µI,’D        - the list [6, 4, 3, 5, 4, 5]
                          S   - sum
+¢Dị“+-|/\O ”Us7Y,”=x9¤;⁷  - complete the man
+                           - add
 ¢                          - the literal 3000000...1222100 calculated by link 1
  D                         - digits
   ị“+-|/\O ”               - index into the string “+-|/\O ”
             Us7Y           - reverse, split into lines of 7, join by linefeeds
                 ,          - append
                  ”=x9¤;⁷     - the string “=========”
                       ;⁷    - add a newline
,œ-                 - append missed letters:
,                      - append
 œ-                    - set difference
ð,ɓi@€ị³;”_¤K;⁷     - append the blanks
ð,ɓ                   - append
   i@€ị³;”_¤            - each letter if it is included in guesses, _ otherwise
            K         - join by spaces
             ;⁷       - add a newline

This draws the man in the wrong order; the torso should come after the head, before the left arm.

C#, 305 296 bytes
using System.Linq;w=>g=>{var r=string.Concat(g.Where(c=>!w.Contains(c)));var n=r.Length;return$@"  +---+
  |   |
  {(n>0?"O":" ")}   |
 {(n>2?"/":" ")+(n>1?"|":" ")+(n>3?"\\":" ")}  |
 {(n>4?"/":" ")} {(n>5?"\\":" ")}  |
      |
=========
{string.Join(" ",w.Select(c=>g.Contains(c)?c:'_'))}
"+r;}

Svaed 9 bytes thanks to @raznagul.
Try it online!
Full/Formatted Version:
using System;
using System.Linq;

class P
{
    static void Main()
    {
        Func<string, Func<string, string>> f = w=>g=>
        {
            var r = string.Concat(g.Select(c => !w.Contains(c) ? c + "" : ""));
            var n = r.Length;

            return $@"  +---+
  |   |
  {(n > 0 ? "O" : " ")}   |
 {(n > 2 ? "/" : " ") + (n > 1 ? "|" : " ") + (n > 3 ? "\\" : " ")}  |
 {(n > 4 ? "/" : " ")} {(n > 5 ? "\\" : " ")}  |
      |
=========
{string.Join(" ", w.Select(c => g.Contains(c) ? c : '_'))}
" + r;
        };

        Console.WriteLine(f("BOAT")("ATG") + "\n");
        Console.WriteLine(f("ZEPPELIN")("") + "\n");
        Console.WriteLine(f("ZEPPELIN")("EATOLINSHR") + "\n");
        Console.WriteLine(f("RHYTHM")("ABCDE") + "\n");
        Console.WriteLine(f("BOAT")("ATOB") + "\n");

        Console.ReadLine();
    }
}

This also works for 314 bytes (could probably be shorter still):
using System.Linq;w=>g=>{var r=string.Concat(g.Select(c=>!w.Contains(c)?c+"":""));var s=$@"  +---+
  |   |
  0   |
 213  |
 4 5  |
      |
=========
{string.Join(" ",w.Select(c=>g.Contains(c)?c:'_'))}
"+r;for(int i=0;i<6;++i)s=s.Replace(i+"",i<r.Length?i<1?"O":i<2?"|":i<3?"/":i<4?"\\":i<5?"/":"\\":" ");return s;}

You can replace g.Select(c=>!w.Contains(c)?c+"":"") with g.Where(c=>!w.Contains(c)).

JavaScript (ES6), 203 196 187 186 185 184 180 177 176 bytes
Takes input as 2 arrays of individual characters in currying syntax.
a=>g=>`  +---+
  |   |
  1   |
 324  |
 5 6  |
      |
=========
${a.map(x=>g[s="includes"](x)?x:"_")}
`.replace(/\d|,/g,m=>" O|/\\/\\"[!!w[~-m]*~~m],w=g.filter(x=>!a[s](x)))+w

Try Play it

o.innerText=(f=
a=>g=>`  +---+
  |   |
  1   |
 324  |
 5 6  |
      |
=========
${a.map(x=>g[s="includes"](x)?x:"_")}
`.replace(/\d|,/g,m=>" O|/\\/\\"[!!w[~-m]*~~m],w=g.filter(x=>!a[s](x)))+w)([...i.value="ZEPPELIN"])([...j.value=""])
oninput=_=>o.innerText=f([...i.value.toUpperCase()])([...j.value.toUpperCase()])
label,input{font-family:sans-serif;font-size:14px;height:20px;line-height:20px;vertical-align:middle}input{margin:0 5px 0 0;width:100px;}
<label for=i>Word: </label><input id=i type=password><label for=j>Guesses: </label><input id=j><pre id=o>

The middle "body" piece should come second and the left arm third, so the numbers part of your string should be 1, 324, 5 6 (see last test case).

Oops, dunno how I did that. Thanks for pointing it out, @JustinMariner

Vim, 118 bytes
jYk:s/[^<C-r>0]/_/g
:s/./& /g
Yj:s/[<C-r>0]//g
oO|/\/\ <esc>ka <esc>jv$r dd{P|i |
 <esc>la
<esc>xpla
<esc>lxpo   <esc>:0,s/.*/ &  |/
o<esc>9i=<esc>{O  +---+

Try it online!

Batch 853 748 736 bytes
Run from the command line with 2 args:
%1 = word, %2 = "doublequoted,delimited,list,of,letters"
edit: requires Windows 10 / Virtual terminal support
Echo off&cls
Set "$=Set "
%$%O=Echo(&%$%F=For /L %%i in (&%$%P=^<nul Set/P &%$%"C=|findstr "
%f:L=f%'%O%prompt $E^|cmd')do %$%\=%%i[
%$%n=^

Setlocal EnableDelayedExpansion
%F:/L=%"e1=3;3HO" "e2=4;3H|" "e3=4;2H/" "e4=4;4H\" "e5=5;2H/" "e6=5;4H\" "D= +---+!n!  |   |!n!")Do %$%%%i
%F%1 1 5)Do %$%D=!D!      ^|!n!
%O%!D!=========!n!&If "%~2"=="" Exit /b
%$%W=%~1&%F:/L=%%~2)Do (%$%/A i+=1
%$%G!i!=%%i&%$%G=!G!/ic:"%%i" )
%F%30,-1,0)Do if not "!W:~%%i,1!"=="" If "!#!"=="" %$%"#=%%i"
%O%%\%10;2H&%F%0 1 !#!)Do (%$%/A X=%%i+2
%P%"=%\%10;!X!H."&%O%"!W:~%%i,1!"%C%!G! >nul &&%P%"=%\%1D!W:~%%i,1!")
%P%"=%\%11;2H"&%F%1 1 !i!)Do %O%!W!%C%/ic:"!G%%i!" >nul||(%P%"=!G%%i!"&%$%/A e+=1)
%F%1 1 !e!)Do %P%"=%\%!e%%~i!"
%O%%\%11;1H

How?
macros are used for repeated commands

Set  Variable assignment %$%
For /L %%i in ( loops %F%

Substring modification is used to recycle the macro as for /f (%F:L=f%) or basic for loops (%F:L=%)

Echo( (output type 1) %O%
< Nul Set /P (output type 2) %P%
Findstr (String comparison used in testing guesses against letters in word) %C%

The remarked ungolfed version:
@Echo off
 cls

:# define VT escape character 0x027
 For /f %%i in ('Echo(prompt $E^|cmd')do Set ESC=%%i[

:# define linefeed. empty lines required. must be expanded with delayed expansion
(Set \n=^

%= ABOVE EMPTY LINES REQUIRED =%)
:# enable environment to allow use of linefeed; modification of variables during code blocks and parsing of nested variables to emulate arrays
Setlocal EnableDelayedExpansion

:# define array of bodypart location and character representation 'incorrect.#'; define top 2 lines of Gallows
 For %%i in ("incorrect.1=3;3HO" "incorrect.2=4;3H|" "incorrect.3=4;2H/" "incorrect.4=4;4H\" "incorrect.5=5;2H/" "incorrect.6=5;4H\" "Gallows= +---+!\n!  |   |!\n!")Do Set %%i

:# define and output the remaining elements of the Gallows
 For /L %%i in (1 1 5)Do Set "Gallows=!Gallows!      |!\n!"
 Echo(!Gallows!=========!\n!

:# Exit script if second argument empty [ no letters guessed ]
 If "%~2"=="" Exit /b

:# assign word variable to facilitate substring assessment of word
 Set "Word=%~1"
 For %%i in (%~2)Do (                              %= For each delimited letter in argument =%
  Set /A "Guess.index+=1"                            %= Increment count                     =%
  Set "Guess.letter!Guess.index!=%%i"                %= Assign letter to Guess.letter array =%
  Set "Guess.letters=!Guess.letters!/ic:"%%i" "      %= Build list of findstr search values =%
 )

:# Calculate word string length [ 0 indexed ]
 For /L %%i in (30,-1,0)Do if not "!Word:~%%i,1!"=="" If "!Word.Length!"=="" Set "Word.Length=%%i"

:# move cursor to line 10 column 2 in advance of correct guess result output
 Echo(%ESC%10;2H

 For /L %%i in (0 1 !Word.Length!)Do (                   %= For each character in word                       =%
  Set /A "Xpos=%%i+2"                                    %= Assign X position offset for '.' output          =%
  <nul Set/P "=%ESC%10;!Xpos!H."                         %= Output '.' denoting unguessed letter spaces      =%
  Echo("!Word:~%%i,1!"| findstr !Guess.letters! >nul &&( %= Test letter in word against guessed letters list =%
   <nul Set/P "=%ESC%1D!Word:~%%i,1!"                    %= On match shift cursor left; overwrite unguessed marker '.' with matched letter =%
  )
 )

:# move cursor to line 11 column 2 in advance of incorrect guess result output
 <nul Set/P "=%ESC%11;2H"

 For /L %%i in (1 1 !Guess.index!)Do (                %= For each guessed letter                         =%
  Echo(!Word!|findstr /ic:"!Guess.letter%%i!" >nul||( %= Test index of guess array for a match in word   =%
   <nul Set/P "=!Guess.letter%%i!"                    %= On NO match output incorrectly guessed letter - =%
   Set /A "incorrect.guess.count+=1"                  %= and increment incorrect.guess.count             =%
  )
 )

:# For each index in incorrect.guess.count output incorrect.# array value - [ Y;Xcharacter ]
 For /L %%i in (1 1 !incorrect.guess.count!)Do <nul Set/P "=%ESC%!incorrect.%%~i!"
 Echo(%ESC%11;1H
``

Scala, 392 389 bytes
This might still be heavily golfable.
This is inside a function taking s and t as parameters, with s the word to guess and t the string containing already tried letters.
var f=s.map(x=>if(t contains x)x else"_") mkString " "
var o="""  +---+
  |   |
  0   |
 213  |
 4 5  |
      |
=========
"""
var c=0
var g=t.filter(x=>if(s contains x){false}else{c match{case 0=>o=o.replace("0","o")
case 1=>o=o.replace("1","|")
case y if y==2|y==5=>o=o.replace(y+"","\\")
case y if y==3|y==4=>o=o.replace(y+"","/")
case _=>()}
c+=1
true})
o.replaceAll("\\d"," ")+f+"\n"+g

EDIT:
-1 byte: t.contains(x) -> t contains x
-1 byte: s.contains(x) -> s contains x
-1 byte: .mkString(" ") ->  mkString " "
Try it online!

PHP 7, 246 bytes
for($t="  +---+
  |   |
  1   |
 324  |
 5 6  |
      |
=========
";$c=($w=$argv[1])[$i++];)$t.=strstr($g=$argv[2],$c)?"$c ":"_ ";for($t.="
";$c=$g[$k++];)strstr($w,$c)?:$t.=$c.!++$n." ";for(;$p++<6;)$t=strtr($t,$p," O|/\/\\"[$p>$n?0:$p]);echo$t;

takes input from command line arguments. Run with -nr or try it online.
for($t="  +---+\n  |   |\n  1   |\n 324  |\n 5 6  |\n      |\n=========\n";
    $c=($w=$argv[1])[$i++]; # 1. loop $c through word
)
    $t.=strstr($g=$argv[2],$c)  # if guessed,
        ?"$c ":"_ ";                # then append letter, else append underscore
for($t.="\n";$c=$g[$k++];)  # 2. loop through guesses
    strstr($w,$c)?:             # if not in word
        $t.=$c.!++$n." ";           # add to output, increment $n
for(;$p++<6;)               # 3. loop through possible false guesses
    $t=strtr($t,$p," O|/\/\\"[  # replace digit:
        $p>$n                   # if above no. of wrong guesses
            ?0:$p                   # then with space, else with hangman character
    ]);
echo$t;                     # 4. print


text:
Implement a strange automaton
I was playing around with cellular automaton and I found one that had some interesting behavior.  Here's how it works:
It reads a binary string from left to right, if it encounters a 1 followed by 2 other values it will append a 0 to the result and continue reading.  If it encounters a 0 (or there are less than 3 values left) it will append the current value and a 1 and continue reading.  At the end of the string it will append a single 1 to the result.
Here's a worked out example of one generation
01011111
^

We first encounter a 0 so we append 01 to our result
01011111
 ^
01

Now we encounter a 1 so we append a zero and skip the next two values
01011111
    ^
010

We encounter another 1 so we do the same
01011111
       ^
0100

We now have another 1 but not enough space to jump so we append the current cell and a 1 (in this case 11)
01011111
        ^
010011

We are at the end so we append a single 1 and terminate this generation
01011111
        ^
0100111

Task
Given input in any reasonable format you must create a function or program that computes one generation of the automaton.
This is a code-golf question so answers will be scored in bytes, with fewer bytes being better.
Sample implementation
Here is a sample implementation in Haskell (defines a function d, but the program prints a iterations indefinitely):
d('1':_:_:x) = "0" ++ d x
d(a:x) = a:'1':d x
d x = "1"
r x = x:map d(r x)

Try it online!

In your question you state We now have another 1 but not enough space to jump so we append the current cell and a 1 or 11. Is it 1 or 11?

Ah its just an 11 thats a case where english could use parens read it as  (we append the current cell and a 1) or 11  I'll try to make this clearer with an edit.

So then if we have a 10 it should print 11011?  I think a few more test cases would be helpful

@nmjcman101 That is correct.  The sample program is comprehensive.

@WheatWizard my fault should have seen the link!

@WheatWizard I would appreciate a clearer explanation, perhaps a table, of the rules

"an" automaton. SCNR.

I don't believe this is actually a cellular automaton, but feel free to enlighten me with a definition saying it is.

@feersum Indeed, it doesn't preserve number of cells. It's a finite-state transducer.

V, 26 22 21 bytes
Thanks to @CowsQuack for 4 bytes by combining regexes! And @ØrjanJohansen for another byte with some regex combinations.
Ó1../3
Ó./&1
Ó31/0
A1

Try it online!
Uses substitute multiple times and appends a 1 at the end.  Nothing too fancy.  I have a version that remaps 1 and 0 in insert mode to get the desired effect, but it's quite a bit longer.
(Multiple replacement version: Try it online!)

The second and third regexes can merge into Ó1ü0/&1 (ü is \|)

@Cowsquack genius!

It's even shorter to do Ó./&1 followed by Ó31/0.

JavaScript (ES6), 56 bytes
Takes input as an array of characters. Returns a string, or the number 1 if given an empty array.
f=([v,...a])=>v?(+v&&a[1]?a.splice(0,2)&&'0':v+1)+f(a):1

Demo

f=([v,...a])=>v?(+v&&a[1]?a.splice(0,2)&&'0':v+1)+f(a):1

console.log(f([...'01011111']))
console.log(f([...'10']))

Animated version
Examples of stable inputs: 0101, 010011111

f=([v,...a])=>v?(+v&&a[1]?a.splice(0,2)&&'0':v+1)+f(a):1

s = '1';
setInterval(_=>o.innerHTML=s=''+f([...s]), 200)
<input oninput="s=this.value" value="1" />

Python 2, 89 bytes
x=input()
y=0
k=[]
while x[y:]:v=1-x[y]*(y<len(x)-2);k+=[x[y]]*v+[v];y+=3-2*v
print k+[1]

Try it online!
-4 bytes thanks to Rod
-6 bytes thanks to ovs
-1 byte thanks to micsthepick

[0]if v else[x[y],1]can be rewritten as [[x[y],1],[0]][v], but you can invert the v value  to reach 96 bytes

90 bytes

Parentheses are not needed for print statement in python 2, so you can save one byte

Python 2, 88 bytes
I,r=input(),[]
while I:a=I[0]and len(I)>2;b=a<1;r+=[I[0]]*b+[+b];I=I[a*2+1:]
print r+[1]

Try it online!

Swift 3, 147 bytes
-1 thanks to @Mr.Xcoder
func g(i:[Int]){var r=[Int]();var s=ArraySlice(i);while let e=s.popFirst(){if 0<e&&2<s.count{r+=[0];s=s.dropFirst(2)}else{r+=[e,1]}};print(r+[1])}

Ungolfed, returning the value rather than printing:
func iterate(state: [Int]) -> [Int] {
    var result = [Int]()

    var inputSlice = ArraySlice(state)

    while let element = inputSlice.popFirst() {
        if 0 < element && 2 < inputSlice.count {
            result += [0]
            inputSlice = inputSlice.dropFirst(2)
        }
        else {
            result += [element, 1]
        }

        //debugPrint(result.map(String.init).joined(separator: ""))
    }

    return result + [1]
}

You can replace 3<=s.count with 2<s.count for -1 bytes.

@Mr.Xcoder Thanks! I can also detects 1s in the input with 0 < element rather than element == 0

Nim, 70 bytes
import re,sugar
x=>x.multiReplace([(re"1..","0"),(re"(.)","$#1")])&"1"

Try it online!
multiReplace allows us to do substitutions simultaneously. The index of the tuple within the sequence acts as the priority if there is a situation where more than one substitution can be made. The priority rises the lower the index is.

Perl 5, 62 + 2 (-F) = 64 bytes
$r.=$F[$i]&&$i+2<@F&&($i+=2)?0:"$F[$i]1";++$i<@F&&redo;say$r.1

Try it online!

Python 2, 81 bytes
Both input and output are lists (thanks to Erik the Outgolfer)
def f(Z):return Z and((1>Z[0]or 3>len(Z))and[Z[0],1]+f(Z[1:])or[0]+f(Z[3:]))or[1]

Try it online!
Some cases
[0,1,0,1,1,1,1,1] --> [0,1,0,0,1,1,1]
[0] ----------------> [0,1,1]
[1] ----------------> [1,1,1]
[] -----------------> [1]
[0,1] --------------> [0,1,1,1,1]
[1,0] --------------> [1,1,0,1,1]

Python 2, 85 bytes
Both input and output are strings (initial solution)

def f(Z):return Z and(('0'==Z[0]or 3>len(Z))and Z[0]+'1'+f(Z[1:])or'0'+f(Z[3:]))or'1'

Try it online!
Some cases
'01011111'--> 0100111
'0'---------> 011
'1'---------> 111
''----------> 1
'01'--------> 01111
'10'--------> 11011

Explication It is simplily a golf of a recursive method.

Using lists is shorter.

@EriktheOutgolfer thanks :)

Oh, and you can do 1>Z[0] instead of 0==Z[0].

Ruby, 47 bytes
This is a direct port of the sample implementation Haskell code.
f=->s{s=~/^1../??0+f[$']:s=~/./?$&+?1+f[$']:?1}

Attempt This Online!
More readable
$& is the matched text from the previous regexp match (=~) and $' is the text after the match.
f = ->s{
  if s =~ /^1../ then "0" + f[$']
  elsif s =~ /./ then $& + "1" + f[$']
  else "1"
  end
}

Julia 0.6, 69 65 bytes
~s=s>""?s<"1"?"01"*~s[2:end]:length(s)>2?"0"*~s[4:end]:s*"11":"1"

Try it online!
Ungolfed and commentated algorithm:
function ~(s)

  # Return "1" on the empty string
  # (End case for automata ending in "0" or "1..")
  if s == ""
    return "1"

  # "0" always becomes "01"
  elseif s[1] == '0'
    return "01" * ~s[2:end]

  # "1.." always becomes "0"
  elseif length(s) > 2
    return "0" * ~s[4:end]

  # Otherwise, append "11"
  # (End case for automata ending in "1" or "1.")
  else return s * "11"

  end
end

Try it online!

-3 bytes thanks to MarcMush: Test the value of s instead of s[1]
-1 byte thanks to MarcMush: Rewrite with s>"" instead of s==""

65 bytes

Scala, 131+29=160 bytes
This is inside a function taking the string a as parameter and returning the output as a string.
var s=""
var k=0
for(c<-0 to a.length-1)breakable{if(k>0){k-=1
break}
if(a(c)==49&c{var t="";for(int i=0,b=n.Length;i'0'&i+2<b){t+="0";i+=3;}else t+=n[i++]+"1";}return t+"1";}

Try it online!
Input taken as a string, and a string is returned as output.