text:
Different number, same weight
Background
The Hamming weight of an integer is the number of ones in its binary representation. For this challenge, integers are represented with 32 bits, and they are unsigned.
Challenge
Given an integer between 0 and 2^32-1 (non-inclusive), output a different integer within the same range, and also with the same Hamming weight.
Examples
Input (Decimal) | Input (Binary) | Hamming weight | Possible output (Decimal)
       46       |   0b0010 1110  |       4        |      15
       12       |   0b0000 1100  |       2        |      3
        1       |   0b0000 0001  |       1        |      2
        3       |   0b0000 0011  |       2        |      6
      2^31      |   0b1000....0  |       1        |      1
      2^31+2    |   0b1000...10  |       2        |      3
      2^32-5    |   0b1111..011  |       31       |      2^31-1
      2^32-2    |   0b1111....0  |       31       |      2^31-1
        0       |   0b0000 0000  |       0        | None (This case need not be handled)
      2^32-1    |   0b1111....1  |       32       | None (This case need not be handled)

Scoring
This is code-golf, so the solution in the fewest bytes in each language wins.

I'd suggest adding an odd number between 2^31+1 and 2^32-3, as some answers are failing at that.

Related.

Since you just added 2^31+2, I'll repeat that I said an odd number. The answers in question only failed when both the highest and the lowest bit are 1.

I'm a fool. Thank you. Will fix that

@musicman523 I just happened to be browsing active questions and saw this one. And noticed that you still haven't added the requested test cases.

@Draco18s I haven't really been active on here in a couple years. Would you like to add the requested test cases?

They'd be nice! I don't plan on writing an answer, I was just a bit amused and thought I'd ping. :)

Ok, I added 2^32-5 as a test case

x86-64 assembly, 5 4 bytes
   0:   97                      xchg   %eax,%edi
   1:   d1 c0                   rol    %eax
   3:   c3                      retq

A function using the C calling convention that bitwise rotates its argument left by 1 bit.

Dammit - I was about to post exactly this - well done :)

assembly beats Jelly :o

Isn't this multiplying by 2? If so, then my 2 byte Pyth answer probably wins

@NoOneIsHere No, this is not multiplication by 2. Multiplication by 2 sends half of the inputs outside of the required range, and if you ignore the overflow bit on the left, you’ve decreased the Hamming weight by 1. This is a bitwise rotation, which brings the overflow bit back in from the right.

@NoOneIsHere https://stackoverflow.com/questions/4976636/whats-the-purpose-of-the-rotate-instructions-rol-rcl-on-x86

FYI, gcc will emit (almost) exactly this code if you compile unsigned h(unsigned n){return (n<<31)|(n>>1);} with -S -O1.  The only thing I couldn't figure out is how to get a rol instead of a ror when rotating by a constant number of bits.

@DigitalTrauma GCC 4.9.0 and later are smart enough to compile n << 1 | n >> 31 into rol instead of ror (saving a byte).

Python, 20 bytes
lambda x:x*2%~-2**32

Bitwise rotation left by 1 bit.

Jelly, 10 8 bytes
‘&~^^N&$

Swaps the least significant set and unset bit.
Try it online!
How it works
‘&~^^N&$  Main link. Argument: n

‘         Increment; yield n+1, toggling all trailing set bits and the rightmost
          unset bit.
  ~       Bitwise NOT; yield ~n, toggling ALL bits of n.
 &        Bitwise AND; yield (n+1)&~n, keeping the only bit that differs in n+1 and
          ~n, i.e., the rightmost unset bit.
   ^      Perform bitwise XOR with n, toggling the rightmost unset bit.
       $  Combine the two links to the left into a monadic chain.
     N        Negate; yield -n. Since ~n = -(n+1) in 2's complement, -n = ~n+1.
      &       Take the bitwise AND of n and -n. Since -n = ~n + 1 and n = ~~n, the
              same reasoning that applied for (n+1)&~n applies to -n&n; it yields
              the rightmost unset bit of ~n, i.e., the rightmost set bit of n.
    ^      XOR the result to the left with the result to the right, toggling the
           rightmost set bit of the left one.

MATL, 9 bytes
32&B1YSXB

Circularly shifts the 32-digit binary representation one step to the right.
Try it online!

JavaScript (ES6), 35 31 bytes
Looks for the first bit transition (0 → 1 or 1 → 0) and inverts it.
f=(n,k=3)=>(n&k)%k?n^k:f(n,k*2)

Demo

f=(n,k=3)=>(n&k)%k?n^k:f(n,k*2)

;[ 46, 12, 255, 2**32-2 ]
.map(n => {
  r = f(n);
  console.log((n >>> 0), '=', (n >>> 0).toString(2), '-->', (r >>> 0), '=', (r >>> 0).toString(2));
})

Bit rotation, 14 bytes
Much shorter but less fun.
n=>n>>>31|n<<1

Demo

let f =

n=>n>>>31|n<<1

;[ 46, 12, 255, 2**32-2 ]
.map(n => {
  r = f(n);
  console.log((n >>> 0), '=', (n >>> 0).toString(2), '-->', (r >>> 0), '=', (r >>> 0).toString(2));
})

The JavaScript bitwise operators give 32-bit signed integers rather than unsigned. For example, f(2147483647) is -1073741825 and (n=>n>>>31|n<<1)(2147483647) is -2.

It's fine as long as there are no more than 32 bits.

Can you add an explanation for the first one? I'm trying to learn Javascript, and am kind of at a loss as to how you are calling f with k undefined and still getting a reasonable answer!

@musicman523 Here is the corresponding tip. Basically, k is initially set to undefined and we take advantage of the fact that ~undefined equals -1.

@musicman523 (I'm not using this tip anymore in the updated version. But don't hesitate to ask if you have other questions about the original answer.)

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

Try it online!
Returns 2n if n < 2^31, and 2n+1-2^32 otherwise.  Unfortunately, because Brain-Flak doesn't have any fast way to determine the sign of a number, the program times out on TIO if the input differs from 2^31 by more than about 500000.
Explanation
First, push -2^32 onto the stack:
(([()()])[[]()])                               push (initial value) -2 and (iterator) -5
                {((){}<                >)}     do 5 times:
                       ({({})({}())}{})        replace the current (negative) value with the negation of its square
                                            {}   pop the (now zero) iterator

Then, compute the desired output:
      (({}){})                        replace n by 2n on left stack
   ({}        ())                     push 2n+1-2^32 on left stack
  (              <>)                  push again on right stack
([                  ])                push its negation on right stack
                      {({}())<>}      add 1 to the top value of each stack until one of them reaches zero
                                {}    pop this zero, and implicitly print the number below it on the stack

dc, 10
?2~z31^*+p

Try it online.
This is an arithmetic implementation of a 32bit right-rotate:
?           # input
 2~         # divmod by 2 - quotient pushed first, then the remainder
   z        # z pushes the size of the stack which will be 2 (quotient and remainder) ...
    31^     #  ... and take that 2 to the 31st power
       *    # multiply the remainder by 2^31
        +   # add
         p  # output

APL, 12 bytes
(2⊥32⍴1)|2×⊢

How?
           ⊢  ⍝ monadic argument
         2×   ⍝ shift left (×2)
(2⊥32⍴1)|     ⍝ modulo 2^32 - 1

Java 8, 117 17 29 bytes
n->n*2%~-(long)Math.pow(2,32)

+12 bytes by changing int to long, because int's max size is 2³¹-1
100 89 bytes saved by creating a port of @AndersKaseorg's amazing Python answer.
Try it here.
Outputs:
46 (101110):                                     92 (1011100)
12 (1100):                                       24 (11000)
1 (1):                                           2 (10)
3 (11):                                          6 (110)
10000 (10011100010000):                          20000 (100111000100000)
987654 (11110001001000000110):                   1975308 (111100010010000001100)
2147483648 (10000000000000000000000000000000):   1 (1)
4294967294 (11111111111111111111111111111110):   4294967293 (11111111111111111111111111111101)

Old answer (117 118 bytes):
n->{long r=0;for(;!n.toBinaryString(++r).replace("0","").equals(n.toBinaryString(n).replace("0",""))|r==n;);return r;}

+1 byte by changing int to long, because int's max size is 2³¹-1
Try it here.
Outputs:
46 (101110):                                     15 (1111)
12 (1100):                                       3 (11)
1 (1):                                           2 (10)
3 (11):                                          5 (101)
10000 (10011100010000):                          31 (11111)
987654 (11110001001000000110):                   255 (11111111)
2147483648 (10000000000000000000000000000000):   1 (1)

Mathematica, 29 bytes
Mod@##+Quotient@##&[2#,2^32]&

Try it at the Wolfram sandbox
Rotates left arithmetically: first multiply by 2, which possibly shifts the number out of range, then cut off the out-of-range digit with Mod[...,2^32] and add it back on the right with +Quotient[...,2^32].
(Mathematica does have a single builtin that gives the modulus and the quotient in one go, but it's QuotientRemainder, which is a bit of a golfing handicap…)

Mod 2^32-1? (4 more to go)

05AB1E, 5 bytes
·žJ<%

Try it online!
Explanation
Uses the trick to rotate the binary representation left by 1 bit from Anders Kaseorg's python answer.
·       # input * 2
    %   # modulus
 žJ<    # 2^32-1

R, 42 63 bytes
function(x){s=x;while(s==x){sample(binaryLogic::as.binary(x))}}

Shuffles the bits around randomly, but checks to make sure it didn't return the same number by chance.

Whitespace, 81 80 bytes
(1 byte saved thanks to @Ørjan Johansen reminding me dup is shorter than push 0)

Try it online!
Basically implements a cyclic right bitshift using integer arithmetic. Pushing a large constant is expensive in Whitespace so we save some bytes by pushing 2^8 and squaring it twice. (Saves 1 byte over (2^16)^2 and 10 bytes over pushing 2^32 directly.)
Explanation
sssn  ; push 0
sns   ; dup
tntt  ; getnum from stdio
ttt   ; retrieve n from heap and put it on the stack
sns   ; dup
ssstsn ; push 2
tstt  ; mod - check if divisible by 2 (i.e. even)
ntsn  ; jez "even"
ssstssssssssn ; push 2^8
sns   ; dup
tssn  ; mul - square it to get 2^16
sns   ; dup
tssn  ; mul - square it to get 2^32
tsss  ; add 2^32 so MSB ends up set after the divide
nssn  ; even:
ssstsn ; push 2
tsts  ; divide by 2, aka shift right
tnst  ; putnum - display result

I think you can replace the second push 0 with a dup one command earlier.

You're right, I just finished adding shortcut syntax to my transpiler so I've been using it too much...

Python 2.7, 89 bytes
Full Program:
from random import*;a=list(bin(input())[2:].zfill(32));shuffle(a);print int(''.join(a),2)

Try it online!
Suggestions welcome! :)

That is not valid because it can by chance return the same number again.

Pari/GP, 15 bytes
n->2*n%(2^32-1)

Try it online!

Perl 5 -p, 39 bytes
$_=sprintf'0b%b',$_;$_=oct$_.int s/10//

Try it online!

C++ (gcc), 45 39 bytes
-6 bytes thanx to ceilingcat
auto h(unsigned x){return x%2<<31|x/2;}

Try it online!

-6 bytes using x= instead of return.

That's not valid in C++.

It doesn't have to be. This is code golf.

Python 3, 45 bytes
lambda i:int(f'{i:32b}'[1:]+f'{i:32b}'[:1],2)

Try it online!

Japt, 5 bytes
Ñ%3pH

Bitwise rotation, like most answers here.
Try it

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

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


text:
Convert Japanese Mario titles to American titles
The naming conventions for games in the Super Mario series is very strange, and don't match up between regions.
| Japanese Name       | American Name                      |
|---------------------|------------------------------------|
| Super Mario Bros.   | Super Mario Bros.                  |
| Super Mario Bros. 2 | Super Mario Bros.: The Lost Levels |
| Super Mario USA     | Super Mario Bros. 2                |
| Super Mario Bros. 3 | Super Mario Bros. 3                |
| Super Mario Bros. 4 | Super Mario World                  |

What a mess!

Challenge:
Given a string consisting of the Japanese name of a Super Mario game, output the corresponding American name. You may input the Japanese string through any reasonable method, and output the American string (with an optional newline) through any reasonable method.
You must use the exact strings shown above. Standard loopholes are forbidden!
The shortest code (in bytes) is the winner.

https://codegolf.meta.stackexchange.com/questions/8047/things-to-avoid-when-writing-challenges/8101#8101 try to avoid fancy tables...

But I thought the Japanese name for Super Mario Bros. 2 was Doki Doki Panic. Or did they re-release the same game in Japan again but with the Mario skins?

@Shufflepants IIRC, yes, they did re-release it with Mario skins as "Super Mario USA".

Can we assume the input must be the exact Japanese names?

@SteveFest Yes.

sed, 52

1 byte saved thanks to @MikeScott

Straightforward replacement:
s/ 2/: The Lost Levels/
s/USA/Bros. 2/
s/B.*4/World/

Try it online.

You can save a character by making the last line s/B.*4/World/.

@MikeScott yes - thanks!

Retina, 43

1 byte saved thanks to @MikeScott

Direct port of my sed answer:
 2
: The Lost Levels
USA
Bros. 2
B.*4
World

Try it online.

My saved character from the sed version works here too -- use B.*4 instead of \S* 4.

JavaScript (ES6), 82 81 bytes
s=>s.replace(/ 2|o.*4|USA/,(_,i)=>['Bros. 2',': The Lost Levels','o World'][i&3])

Try it online!
How?
There are three patterns to look for and replace. We search all of them at once and use the position \$i\$ of the match to deduce the substitution string.
Pattern | Found in              | Position in string | Position MOD 4 | Replaced with
--------+-----------------------+--------------------+----------------+--------------------
/ 2/    | "Super Mario Bros. 2" |                 17 |              1 | ": The Lost Levels"
/o.*4/  | "Super Mario Bros. 4" |                 10 |              2 | "o World"
/USA/   | "Super Mario USA"     |                 12 |              0 | "Bros. 2"

Now that's clever.

PHP, 81 Bytes
<?=str_replace([" 2",USA,"Bros. 4"],[": The Lost Levels","Bros. 2",World],$argn);

Try it online!

Python 2, 96 92 bytes
lambda s:r(r(r(s,' 2',': The Lost Levels'),'USA','Bros. 2'),'Bros. 4','World')
r=str.replace

Try it online!

JavaScript (ES6), 84 bytes
s=>s[r='replace'](' 2',': The Lost Levels')[r]('USA',(b='Bros. ')+2)[r](b+4,'World')

f=
s=>s[r='replace'](' 2',': The Lost Levels')[r]('USA',(b='Bros. ')+2)[r](b+4,'World')

console.log(
    f('Super Mario Bros.'),
    f('Super Mario Bros. 2'),
    f('Super Mario USA'),
    f('Super Mario Bros. 3'),
    f('Super Mario Bros. 4')
)

+1 for the [r='replace'] trick.

I don't know JS much... how does using the [] work as a function?

@totallyhuman 1) JS object properties can be accessed with either of these two syntaxes: object.property or object['property']. 2) A method of an object is a property that is assigned a function. 3) Under the hood, JS briefly turns a primitive type such as a string into an object when a property access syntax is used on it. Conclusion: by combining all of the above, we can understand why s['replace']() does exactly what it says on the tin.

Japt, 48 bytes
d" 2"`: T” Lo¡ Levels`"USA"`Bžs. 2``Bžs. 4``WŽld

Try it online!
Explanation:
 d" 2"`: T” Lo¡ Levels`"USA"`Bžs. 2``Bžs. 4``WŽld

U                                //  Implicit U = Input
 d                               //  Replace:
   " 2"                          //    " 2" with
       `...`                     //    ": The Lost Levels" decompressed,
            "USA"                //    "USA" with
                 '...'           //    "Bros. 2" decompressed,
                      '...'      //    "Bros. 4" decompressed with
                           '...' //    "World" decompressed

Japt uses the shoco library for string compression. Backticks are used to decompress strings.

R, 86 bytes
function(x)sub("Bros. 4","World",sub("USA","Bros. 2",sub(" 2",": The Lost Levels",x)))

Jelly,  44  43 bytes
⁹
HḂ+2⁹Ḳ¤ḣK;⁸ị“¥ḄḞ“ḋṗYP8ḷẇ?Ṅ“¡Ạ ṙṗ%»¤
0ịVĊŀ

A full program that prints the result.
Try it online!
How?
⁹ - Link 1: yield right argument: number a, list of characters b
⁹ - link's right argument, b

HḂ+2⁹Ḳ¤ḣK;⁸ị“¥ḄḞ“ḋṗYP8ḷẇ?Ṅ“¡Ạ ṙṗ%»¤ - Link 0: change a name: number a, list of characters b
                   ...Note: at this point a will be 0, 2 or 4 for USA, 2 and 4 respectively
H                                   - halve a (0,1, or 2)
 Ḃ                                  - mod 2   (0,1, or 0)
  +2                                - add 2   (2,3, or 2)
      ¤                             - nilad followed by link(s) as a nilad:
    ⁹                               -   link's right argument, b
     Ḳ                              -   split at spaces
       ḣ                            - head (first two for USA or 4, first three for 2)
        K                           - join with spaces
                                  ¤ - nilad followed by link(s) as a nilad:
          ⁸                         -   link's left argument a
            “¥ḄḞ“ḋṗYP8ḷẇ?Ṅ“¡Ạ ṙṗ%»  -   list of dictionary/string compresions:
                                    -     [" World",": The Lost Levels"," Bros. 2"]
           ị                        - index into (1-based & modular; respectively [4,2,0])

0ịVĊŀ - Main link: list of characters, J
0ị    - index 0 into J - gets the last character '.', '2', 'A', '3', or '4'
  V   - evaluate as Jelly code - the evaluations are:
      -     "Super Mario Bros." :  . - literal 0.5
      -   "Super Mario Bros. 2" :  2 - literal 2
      -       "Super Mario USA" :  A - absolute value (default argument is 0) = 0
      -   "Super Mario Bros. 3" :  3 - literal 3
      -   "Super Mario Bros. 4" :  4 - literal 4
   Ċ  - ceiling - changes a 0.5 to 1 and leaves others as they were
    ŀ - call link at that index as a dyad (left = the evaluation, right = J)
      -   this is one based and modular so 1 & 3 go to Link 1, while 0, 2 & 4 go to Link 0.

Nice workaround to "crossed-out 44 is normal 44".

Mathematica, 80 bytes
#~StringReplace~{" 2"->": The Lost Levels","USA"->"Bros. 2","Bros. 4"->"World"}&

Anonymous function. Takes a string as input and returns a string as output.

Python 3: 111 bytes
from re import sub as r
print(r(" USA","Bros. 2",r(" 2",": The Lost Levels",r("Bros. 4","World",input()))))

Gets user input, runs a series of regex-based substitutions, and prints the result.

Welcome to the site! I think it's shorter if you do from re import* instead of from re import sub as r. Then the second line would become: print(sub(" USA","Bros. 2",sub(" 2",": The Lost Levels",sub("Bros. 4","World",input()))))

Aha, excellent. Thank you!

Go, 134 bytes
import."strings"
func f(s string)string{r:=Replace;return r(r(r(s," 2",": The Lost Levels",1),"USA","Bros. 2",1),"Bros. 4","World",1)}

Try it online!
Since Go doesn't support default values for arguments, you have to manually pass 1 every time.

Batch, 237 99 bytes
Assuming input is in exact format in the question
@set s=%*
@set s=%s: 2=: The Lost Levels%
@set s=%s:USA=Bros. 2%
@set s=%s:Bros. 4=World%
@echo %s%

Pascal (FPC), 184 182 bytes
const s='Super Mario ';b='Bros.';m=s+b;var t:string;z:array[0..4]of string=(m+' 2',m+' 3',m,s+'World',m+': The Lost Levels');begin read(t);write(z[(length(t)+ord(t[19])*2)mod 5])end.

Try it online!
Explanation:
z is the array that holds 5 possible outputs, we just need to find the way to index into it. I noticed 2 parameters that can be used to distinguish input. The first part is length of the input:
Super Mario Bros.   -> 17
Super Mario Bros. 2 -> 19
Super Mario USA     -> 15
Super Mario Bros. 3 -> 19
Super Mario Bros. 4 -> 19

Only 3 inputs have the same length mod 5. The second part is that, at position 19 in the inputs, 2, 3 and 4 have consecutive code points, so they can be easily used to fill out the rest of the indexes while the remaining 2 inputs are shorter.
The String type defaults to ShortString and by default has capacity for 255 characters, all initialized with zeroes, so it is safe to use t[19] on all strings and its codepoint is 0 for shorter strings, not changing anything for indexing, so shorter strings' indexes are 0 and 2. Therefore, we need indexes 1, 3 and 4 from 2, 3 and 4.
  | Codepoint |  *2 | +19 | mod 5
2 |        50 | 100 | 119 | 4
3 |        51 | 102 | 121 | 1
4 |        52 | 104 | 123 | 3

05AB1E, 37 bytes
l„ 2“:€€‹×Œä“:'„À"bros. 2"©:®Y4:'‚ï:™

Try it online or verify all test cases.
Explanation:
l                  # Convert the input to lowercase
 „ 2         :     # Replace " 2" with:
    “:€€‹×Œä“      #  ": the lost levels"
 '„À          :    # Then replace "usa" with:
    "bros. 2"      #  "bros. 2"
             ©     # And store the string "bros. 2" in the register
 ®                 # Retrieve "bros. 2" from the register,
  Y4:              # and replace its "2" with "4"
        :          # Then replace "bros. 4" with:
     '‚ï           #  "world"
™                  # Convert the result to title-case (and output implicitly)

See this for more information why “:€€‹×Œä“ is ": the lower levels"; '„À is "usa"; and '‚ï is "world".

source: Stack Exchange

license: 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/

sort: votes


text:
These are the Frequencies, Kenneth
The Challenge
Generate 1 sec of an 8 bit tone sampled at 256 samples per second. The tone will be made up of a number of sine waves. The frequency of each sine wave will be determined from the input data.
These are deep tones, too low for a human to perceive, but I've chosen 8 bit numbers here since it's code-golf.
The Input
You will receive an array (or a list) of (non-negative) 8 bit signed integer values (0-127), each number will represent a frequency. An empty list is allowed and numbers may appear more than once in the list. All input frequencies must be assumed to be equal in amplitude.
The Output
Your program or function must output an array (or list) of 8 bit signed integer values that represents the signal generated.
Some graphical examples follow, but the actual output of your program is to be a list of integers. Not a graph and not a stream of bytes.
Also, your output must be normalized. That is, it must fill the window of possible values from -128 to 127. In other words, if you calculate a signal and its [min,max] is [-64,63], then you must amplify (multiply) the entire signal ×2. A flat signal will be all zeros. There should be no DC component in any output signal (ie. the average value should be 0). Since most (practically all) generated signals will be symmetrical then most likely your normalized signal will never contain a -128.

The actual expected output of these datasets are as follows:
[]                                    => [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
[2]                                   => [0,6,12,18,24,30,36,42,48,54,59,65,70,75,80,85,89,94,98,102,105,108,112,114,117,119,121,123,124,125,126,126,127,126,126,125,124,123,121,119,117,114,112,108,105,102,98,94,89,85,80,75,70,65,59,54,48,42,36,30,24,18,12,6,0,-6,-12,-18,-24,-30,-36,-42,-48,-54,-59,-65,-70,-75,-80,-85,-89,-94,-98,-102,-105,-108,-112,-114,-117,-119,-121,-123,-124,-125,-126,-126,-127,-126,-126,-125,-124,-123,-121,-119,-117,-114,-112,-108,-105,-102,-98,-94,-89,-85,-80,-75,-70,-65,-59,-54,-48,-42,-36,-30,-24,-18,-12,-6,0,6,12,18,24,30,36,42,48,54,59,65,70,75,80,85,89,94,98,102,105,108,112,114,117,119,121,123,124,125,126,126,127,126,126,125,124,123,121,119,117,114,112,108,105,102,98,94,89,85,80,75,70,65,59,54,48,42,36,30,24,18,12,6,0,-6,-12,-18,-24,-30,-36,-42,-48,-54,-59,-65,-70,-75,-80,-85,-89,-94,-98,-102,-105,-108,-112,-114,-117,-119,-121,-123,-124,-125,-126,-126,-127,-126,-126,-125,-124,-123,-121,-119,-117,-114,-112,-108,-105,-102,-98,-94,-89,-85,-80,-75,-70,-65,-59,-54,-48,-42,-36,-30,-24,-18,-12,-6]
[1,3]                                 => [0,8,16,24,32,39,47,54,61,68,75,81,87,93,98,103,107,111,115,118,120,123,124,126,126,126,126,126,125,123,121,119,116,113,110,106,102,98,94,89,84,79,74,69,64,59,54,49,44,39,35,30,26,22,18,15,12,9,7,4,3,1,0,0,0,0,0,1,3,4,7,9,12,15,18,22,26,30,35,39,44,49,54,59,64,69,74,79,84,89,94,98,102,106,110,113,116,119,121,123,125,126,126,127,126,126,124,123,120,118,115,111,107,103,98,93,87,81,75,68,61,54,47,39,32,24,16,8,0,-8,-16,-24,-32,-39,-47,-54,-61,-68,-75,-81,-87,-93,-98,-103,-107,-111,-115,-118,-120,-123,-124,-126,-126,-127,-126,-126,-125,-123,-121,-119,-116,-113,-110,-106,-102,-98,-94,-89,-84,-79,-74,-69,-64,-59,-54,-49,-44,-39,-35,-30,-26,-22,-18,-15,-12,-9,-7,-4,-3,-1,0,0,0,0,0,-1,-3,-4,-7,-9,-12,-15,-18,-22,-26,-30,-35,-39,-44,-49,-54,-59,-64,-69,-74,-79,-84,-89,-94,-98,-102,-106,-110,-113,-116,-119,-121,-123,-125,-126,-126,-126,-126,-126,-124,-123,-120,-118,-115,-111,-107,-103,-98,-93,-87,-81,-75,-68,-61,-54,-47,-39,-32,-24,-16,-8]
[15,14,13,12,11,10,9,8,7,6,5,4,3,2,1] => [0,32,63,89,109,122,126,124,114,100,82,62,43,26,13,4,0,0,3,9,16,24,30,35,37,36,33,27,21,14,8,3,0,-1,0,2,6,10,15,18,21,21,21,18,15,10,6,2,0,-1,-1,0,1,5,8,11,13,15,15,14,11,8,5,2,0,-1,-2,-1,0,1,4,6,9,10,11,11,9,7,5,2,0,-1,-2,-3,-2,0,1,3,6,7,8,9,8,6,4,2,0,-1,-3,-3,-3,-2,0,1,3,5,6,7,7,6,4,2,0,-2,-3,-4,-4,-4,-2,0,1,3,4,5,5,5,4,2,0,-2,-4,-5,-5,-5,-4,-3,-1,0,2,4,4,4,3,2,0,-2,-4,-6,-7,-7,-6,-5,-3,-1,0,2,3,3,3,1,0,-2,-4,-6,-8,-9,-8,-7,-6,-3,-1,0,2,3,2,1,0,-2,-5,-7,-9,-11,-11,-10,-9,-6,-4,-1,0,1,2,1,0,-2,-5,-8,-11,-14,-15,-15,-13,-11,-8,-5,-1,0,1,1,0,-2,-6,-10,-15,-18,-21,-21,-21,-18,-15,-10,-6,-2,0,1,0,-3,-8,-14,-21,-27,-33,-36,-37,-35,-30,-24,-16,-9,-3,0,0,-4,-13,-26,-43,-62,-82,-100,-114,-124,-127,-122,-109,-89,-63,-32]
[3,5,7,11,13,17,23]                   => [0,47,88,115,126,123,107,86,65,48,38,35,36,38,38,35,29,21,14,12,14,22,32,40,45,43,34,20,3,-10,-19,-22,-17,-10,-2,0,-3,-14,-30,-48,-60,-64,-56,-36,-7,22,49,66,70,60,40,14,-11,-31,-42,-44,-38,-29,-20,-14,-12,-14,-19,-23,-25,-23,-19,-14,-12,-14,-20,-29,-38,-44,-42,-31,-11,14,40,60,70,66,49,22,-7,-36,-56,-64,-60,-48,-30,-14,-3,0,-2,-10,-17,-22,-19,-10,3,20,34,43,45,40,32,22,14,12,14,21,29,35,38,38,36,35,38,48,65,86,107,123,126,115,88,47,0,-47,-88,-115,-126,-123,-107,-86,-65,-48,-38,-35,-36,-38,-38,-35,-29,-21,-14,-12,-14,-22,-32,-40,-45,-43,-34,-20,-3,10,19,22,17,10,2,0,3,14,30,48,60,64,56,36,7,-22,-49,-66,-70,-60,-40,-14,11,31,42,44,38,29,20,14,12,14,19,23,25,23,19,14,12,14,20,29,38,44,42,31,11,-14,-40,-60,-70,-66,-49,-22,7,36,56,64,60,48,30,14,3,0,2,10,17,22,19,10,-3,-20,-34,-43,-45,-40,-32,-22,-14,-12,-14,-21,-29,-35,-38,-38,-36,-35,-38,-48,-65,-86,-107,-123,-127,-115,-88,-47]
[1,1,2,3,5,8,13,21,34]                => [0,52,88,99,90,75,68,73,84,92,88,74,60,56,67,87,104,104,85,55,30,25,43,73,101,112,105,85,66,57,58,59,51,34,14,4,15,46,87,118,127,112,84,60,50,56,68,73,64,45,27,18,23,32,36,24,1,-21,-28,-11,26,70,103,114,103,83,66,61,63,63,53,34,13,4,13,36,59,68,54,23,-8,-27,-24,-6,14,23,15,-2,-20,-28,-25,-19,-21,-34,-52,-62,-51,-17,31,77,103,104,88,68,57,60,69,74,67,49,32,24,31,45,54,47,23,-7,-29,-29,-6,26,55,64,54,32,12,1,0,-1,-12,-32,-54,-64,-55,-26,6,29,29,7,-23,-47,-54,-45,-31,-24,-32,-49,-67,-74,-69,-60,-57,-68,-88,-104,-103,-77,-31,17,51,62,52,34,21,19,25,28,20,2,-15,-23,-14,6,24,27,8,-23,-54,-68,-59,-36,-13,-4,-13,-34,-53,-63,-63,-61,-66,-83,-103,-114,-103,-70,-26,11,28,21,-1,-24,-36,-32,-23,-18,-27,-45,-64,-73,-68,-56,-50,-60,-84,-112,-126,-118,-87,-46,-15,-4,-14,-34,-51,-59,-58,-57,-66,-85,-105,-112,-101,-73,-43,-25,-30,-55,-85,-104,-104,-87,-67,-56,-60,-74,-88,-92,-84,-73,-68,-75,-90,-99,-88,-52]

Additional Rules
All component frequencies are to begin at 0° phase. Basically, that means that they should start at 0 proceed to +127 at 90°, 0 again at 180°, -127 at 270° and then back to 0 at 360°.
It is acceptable if your outputs are slightly different due to rounding, from the examples posted here. They should be normalized to fill (or nearly fill) the range of possible signed ints (-128..127).
The usual loopholes are prohibited.
This is code-golf, shortest code wins.
IMPORTANT!
Practically everybody has made the same mistake in this challenge. 128 is NOT a valid signed 8 bit integer. You should not have output that contains this number or any number over 128.

I recall one of my Physics teachers saying, on many occasion, that sec is not an abbreviation of second and to use the correct abbreviation, s.

...Don't have your speakers too loud people, you may get sick.

Related

an array of 8 bit signed integers vs. not a stream of bytes.  In some languages (e.g. [tag:c]) an array of 8 bit signed integers is exactly the same as a stream of bytes.  Can that be resolved?

The statements "...must fill the window of possible values from -128 to 127" and "...at 0 proceed to +127 at 90°, 0 again at 180°, -127 at 270° and then back to 0 at 360°." are in conflict. I imagine it would be kindest to the developers to allow -128 to be left out if they wish.

@Jonathan, well, almost all of these generated signals will be (nearly) symmetrical so I don't see -128 appearing very often if at all. normalization should not normally add a dc component, but I'll clarify

@Digital Trauma, output the data as shown in the examples. A set of non-printable ASCII characters (a byte stream) would not be acceptable. This is still totally solvable in C/C++

For [2], why does the 5th value (0-indexed) 30 instead of 31? 128*sin(2*5/256*2*pi) is 31.1014630276

@Leaky Nun, don't care. close enough. Actually you should probably multiply by 127 or you'll get an overflow. Or you could clamp. I don't care which.

...so shouldn't the output for [3,5,7,11,13,17,23] range from -128 to 127? (the example output has min -127 and max 126) - or is this within the "rounding" allowance?

@Jonathan Allan, "It is acceptable if your outputs are slightly different due to rounding"

your output must be normalized. That is, it must fill the window of possible values from -128 to 127 This contradicts the result for empty input. Can you clarify? Or maybe not consider empty input at all?

@Luis, what is the sentence immediately following that in the very same paragraph? Clarified! How else would you handle a zero signal. A little bit of common sense isn't out of the question.

@JonathanAllan my teachers told me never to use secs because physicists never have any.

@Octopus if this were done in C, what would the inputs and outputs be? char arrays or are int arrays acceptable? Or does the output actually need to be printed with commas and brackets?

Jelly, 23 28 bytes
Ṁ1Ṁ?
⁹Ḷµ×³×ØP÷⁹ḤÆSSµ€µ×127:Ç

Try it online!
+5 bytes for handling input []
All rounding errors are within +/- 2.
How it works
Ṁ1Ṁ?  - helper link, returns the maximum of a list unless the maximum is 0, where it returns 1
  Ṁ?  - if the maximum is truthy:
Ṁ     - return the maximum. Else:
 1    - return 1.

⁹Ḷµ×³×ØP÷⁹ḤÆSSµ€µ×127:Ṁ - main link, nilad
⁹Ḷ                      - the literal [0,1,2,3,...,254,255]
  µ           µ€        - compute the relative amplitude for each using the chain:
   ×³                   - multiply each element frequency by x
     ×ØP÷⁹Ḥ             - scale because the sine function uses degrees.
           ÆS           - take the sine
             S          - return the sum of the list of sines of component waves.
                µ×127:Ç - scale to 127, with divison by 0 handled by the helper link

This does not give the desired result for empty input

26 bytes Ṁ1Ṁ? doesn't need it's own line

Python 3, 119 bytes
from math import*
def f(a):b=[sum(sin(m*i*pi/128)for m in a)for i in range(256)];return[127*x//(max(*b)or 1)for x in b]

Try it online!

2*pi/256 -> pi/128

instead of m*i*2*pi/256, why not m*i*pi/128?

Save four bytes by writing the function on a single line.

Save five more more using c=max(*b)or 1 and 127*x//c

@JonathanAllan how to write the function on a single line? The return statement cannot start at the middle, and I cannot convert the function into a lambda.

(link too long for a comment with the test cases) like this

Or with the other suggestion

4 answers so far, and this is the only one that meets all criteria of the challenge.

MATL, 34 bytes
Oh!8W:q7W/YP**Y,XstX:X>|a?1M/127*k

Try at MATL online!. Or add code XG to see a plot.

This is good, but see the IMPORTANT! addendum I added.

@Octopus Thanks, corrected now

Mathematica, 75 bytes
(m=MaxValue[f=Tr[Sin[x/128Pi#]&/@#],x]+.1^9;Round[127f/m]~Table~{x,0,255})&

Try the code online at https://sandbox.open.wolframcloud.com.
Explanation:
            f=Tr[Sin[x/128Pi#]&/@#]                                         Define expression f contains variable x equal to the frequency
                                                                               as x runs from 0 to 256 (x/128Pi runs from 0 to 2Pi)
 m=MaxValue[                       ,x]                                      Find the maximum of f
                                      +.1^9                                 Avoid case of empty list when m=0
                                            Round[127f/m]                   Normalize value of f to correct range
                                                         ~Table~{x,0,255}   and make a table of the value.

Notes:

Using MaxValue instead of NMaxValue may have some symbolic issues, which is displayed as warning.
It can be proved that the function have MaxValue + MinValue == 0, so it is not necessary to calculate MinValue.
To run the code, put [{1,3}] for example after the code for input {1,3} and press Shift+Enter on Wolfram Sandbox.
Although the code produce exact result, it is not mathematically correct due to the bad way of handle empty input case. This version (78 bytes) is better.

(m=MaxValue[f=Tr[Sin[x/128Pi#]&/@#],x];Round[127f/m]~Table~{x,0,255}/.0/0->0)&

or (80 bytes)
(m=MaxValue[f=Tr[Sin[x/128Pi#]&/@#],x];If[m<1,0,Round[127f/m]]~Table~{x,0,255})&

This works because it can be proven that the maximum is at least 1 for all non-empty input.

Please do post an online IDE link

...how do we call the function?

I'm with John. I can't figure out how to use the wolfram sandbox. Please tell us what to paste in (including an input sample) and what to do to make it go.

Does this handle empty input correctly? It should produce an array of zeros

The format I see output in the sandbox isn't the format asked for in the challenge, unless I did something wrong?

@Octopus The format looks fine to me.

The output of this is sometimes off from the test cases by 1. Is this a rounding error, and if so, is that allowed?

this is what i see in wolfram

@Octopus You pasted the "or" as part of the code. user202729 gave two different options for pasting in his comment.

still

Here is what I see: https://i.stack.imgur.com/bB3cy.png

TI-BASIC, 47 41 48 bytes
-6 thanks to @Octopus
+7 for handling 0
:Prompt Y                         //Get list of inputs, 3 bytes
:"sum(sin(XʟY→Y₁                  //Store sum of sines function to Y₁, 10 bytes
:Y₁(128ֿ¹πseq(B,B,0,255           //Use the function to compute the values at 256 points, 20 bytes
:iPart(127Ans/max({1ᴇ~9,max(Ans   //Normalize values and round, 8 bytes

This will not work for empty input, since TI-BASIC will never accept empty input (see here).
GIF:

How does this take input then? What if I give it [] or 0?

I'll add a .gif.

If you give it a list with with a zero {0}, it'll work...

I think you'll find that since the signals are always symmetrical, finding just the max is sufficient in the last line

@Octopus K, thanks.

Perl 6, 101 bytes
{my @w=[Z+] |(0 xx 256 xx 2),|.map:
(^256 »/»(128/π/*))».sin;(@w »*»(127/(@w.max||1)))».floor}

The frequencies are taken from the single list passed to this anonymous function.

Ruby, 102 bytes
->r{(o=(0..255).map{|i|r.sum{|n|Math::sin(0.024544*i*n)}}).map{|f|(f*127/[1,*o].map(&:abs).max).to_i}}

Try it online!
I know this is a slightly old one, but it looked like fun. The margin of error (for the given tests, anyway) is within ±1.


text:
Am I an engineer?
Recently, an electrical engineer studying traffic light timings was fined $500 by the state of Oregon for referring to himself as an engineer.
Given a 2 letter string as input, representing a US state, output:

I am not an engineer if the state is Oregon (OR)
I am an engineer if the state is any other US state
What is an engineer? given any other input

Output may not contain any leading whitespace, but may contain as much trailing whitespace as you wish.
You can assume the input will always be 2 uppercase letters.
Here is a list of all 50 US state abbreviations:
AL, AK, AZ, AR, CA, CO, CT, DE, FL, GA, HI, ID, IL, IN, IA, KS, KY, LA, ME,
MD, MA, MI, MN, MS, MO, MT, NE, NV, NH, NJ, NM, NY, NC, ND, OH, OK, OR, PA,
RI, SC, SD, TN, TX, UT, VT, VA, WA, WV, WI, WY

Scoring
This is code-golf, so fewest bytes in each language wins!

Can I have a trailing space in the output?

@BusinessCat yes, will update spec to say that

Side note: If you concatenate the whole string together, you get "...OKORPARISCSDTN..."  ;-)

Mats Järlström wouldn't be allowed to present himself as an engineer in Texas, either.

C#, 311 309 240 237 222 195 184 183 bytes
s=>s=="OR"?"I am not an engineer":"MINCALA MSCTNMNVAKY WAZ PAR FL GA NHID COKSD ME MDE MA MTX NE NJ NY ND MOH RIA UT WVT WIL WY".Contains(s)?"I am an engineer":"What is an engineer?";

Try it online!
Saved 2 bytes by adding the space before an to b
-69 (huehue) -72 bytes thanks to TheLethalCoder
-15 bytes thanks to TotallyHuman's genius states string
-38 bytes cos more string compression
Ungolfed:
public static string a(string s)
{
    var b = " an engineer";
    if (s == "OR")
    {
        return "I am not" + b;
    }
    else
    {
        if ("MINCALA MSCTNMNVAKY WAZ PAR FL GA NHID COKSD ME MDE MA MTX NE NJ NY ND MOH RIA UT WVT WIL WY".Contains(s))
        {
            return "I am" + b;
        }
        else
        {
            return $"What is{b}?";
        }
    }
}

Use ..."+b instead of interpolated strings, change if..else if...else to return s=="OR"?....:System.Arr...i.e. use a ternary. Useu.Containsinstead ofArray.Exists. I think if you use spaces instead of commas then .Split()` with no params will work.

declare b and u in the same line and even though you have to use explicit type string should still save you a byte

@StefanDelport u is an array not string. However, you can save bytes by setting u as a string and using .Contains on it.

240 bytes: s=>{var b=" an engineer";return s=="OR"?"I am not"+b:"AL AK AZ AR CA CO CT DE FL GA HI ID IL IN IA KS KY LA ME MD MA MI MN MS MO MT NE NV NH NJ NM NY NC ND OH OK PA RI SC SD TN TX UT VT VA WA WV WI WY".Contains(s)?"I am"+b:$"What is{b}?";};. Think I've removed all the relevant whitespace. (Untested)

237: s=>s=="OR"?"I am not an engineer":"AL AK AZ AR CA CO CT DE FL GA HI ID IL IN IA KS KY LA ME MD MA MI MN MS MO MT NE NV NH NJ NM NY NC ND OH OK PA RI SC SD TN TX UT VT VA WA WV WI WY".Contains(s)?"I am an engineer":"What is an engineer?"; implicit return with all strings fully hardcoded, untested but should work. Mmm probably should have made my own solution... Oh well have this for free :P

An anonymous user suggested saving a byte by dropping the O from ORIA.

PAR and RIA can be joined to save 2 bytes.

The input "" responds "I am an engineer." instead of "What is an engineer?".

I think COHINCALAKSCTNVARIAZ MNMOKY WVTX MSDE MIL WID FL GA ME MA NJ NY NH PA WA WY NE MD MT ND UT works an saves 2 bytes.

You can golf this by defining " an engineer" as a separate variable to save some bytes.

JavaScript (ES6), 182 bytes
s=>['I am'+(x=' an engineer'),`What is${x}?`,'I am not'+x][s=='OR'?2:'MNNMLATNAKALARAZCACOCTDEFLGAHIIAIDILINKSKYMAMDMEMIMOMSMTNCNDNENHNJNVNYOHOKPARISCSDTXUTVAVTWAWIWVWY'.search(s)&1]

Demo

let f =

s=>['I am'+(x=' an engineer'),`What is${x}?`,'I am not'+x][s=='OR'?2:'MNNMLATNAKALARAZCACOCTDEFLGAHIIAIDILINKSKYMAMDMEMIMOMSMTNCNDNENHNJNVNYOHOKPARISCSDTXUTVAVTWAWIWVWY'.search(s)&1]

console.log(f("OR"))
console.log(f("NY"))
console.log(f("TX"))
console.log(f("YO"))

Fails for e.g. LA :/

@Christoph Should be OK now. Thanks for reporting this!

Thought it was missing OR for moment - silly!

Use https://codegolf.stackexchange.com/a/124164/76323 to optimize

C, 215 208 190 bytes
-7 thanks to Cool Guy
#define z" an engineer"
#define f(s)!strcmp(s,"OR")?"I am not"z:strstr("MINCALA MSCTNMNVAKY WAZ PAR FL GA NHID COKSD ME MDE MA MTX NE NJ NY ND MOH RIA UT WVT WIL WY",s)?"I am"z:"What is"z"?"

Used @totallyhuman's "genus string".
How it works:

"string"z automatically concatenates "string" with z (" an engineer"). Yes, C does that.
!strcmp(s,"OR") compares the string against "OR".
?"I am not"z returns "I am not an engineer" if true. Otherwise...
:strstr(...,s) checks if @totallyhuman's genius string contains the provided string.
?"I am"z returns "I am an engineer" if so, and...
:"What is"z"?") returns "What is an engineer?" otherwise.

Try it online!

206 bytes: #define z " an engineer" f(char*s){!strcmp(s,"OR")?puts("I am not"z):strstr("MINCALA MSCTNMNVAKY WAZ PAR FL GA NHID COKSD ME MDE MA MTX NE NJ NY ND MOH RIA UT WVT WIL WY",s)?puts("I am"z):puts("What is"z);}

@CoolGuy That won't work for "What is an engineer?" But I got it to work in 209 bytes. Thanks!

You can return the string instead of printing it

@l4m2 Did something similar.

Python 2, 228 168 bytes
lambda s:('What is%s?','I am'+' not'*(s=='OR')+'%s')[s in'MINCALA MSCTNMNVAKY WAZ PAR FL GA NHID COKSD ME MDE MA MTX NE NJ NY ND MOH ORIA UT WVT WIL WY']%' an engineer'

Try it online!

The state encoding is hilarious.

Python 2, 192 186 182 178 176 bytes
Could probably compress the state string more.
lambda s,e=' an engineer':'I am'+' not'*(s=='OR')+e if s in'MINCALAZ SCT FL GA WIAKSD ME MD MA MNMS MOKY MTNE NVTX NH NJ NY ND COHIDE OR PARIL UT VA WA WV WY'else'What is%s?'%e

Try it online!

You only use u in if s in u can you note use it directly instead of declaring it?

@TheLethalCoder Yup, just doing that right now lol.

@totallyhuman that string compression is pretty amazing, nice one!

@totallyhuman VALA WAZ NCA COH CTX SDE FL GA HID WIL MIN IAKSC KY ME MD MA MNMS MOK MTNE NH NJ NY ND PARI UT NVT WV WY is the smallest I can make it

'MINCALA MSCTNMNVAKY WAZ PAR FL GA NHID COKSD ME MDE MA MTX NE NJ NY ND MOH ORIA UT WVT WIL WY'

The above string is still shorter

Whoops, sorry it took me so long. Seems I have lost as copying that string doesn't make my answer better than the one using it. Please stop upvoting this and upvote the other better answer.

@totallyhuman I'll upvote your comment instead for being a good sport

Java (JDK 10), 184 bytes
s->s.format(s.equals("OR")?"I am not%s":"MINCALA MSCTNMNVAKY WAZ PAR FL GA NHID COKSD ME MDE MA MTX NE NJ NY ND MOH RIA UT WVT WIL WY".contains(s)?"I am%s":"What is%s?"," an engineer")

Try it online!
I apologize for reusing the compressed string: I couldn't find anything better by myself... :(

05AB1E, 104 103 101 bytes
„€À€ˆ„I€Ü‚.•~Zµ∞/'—¶[@øl•Œ2ù.•9₆\|&×ƒΩ#àöF},cΓ páe;ð²∍₆jÌn#dÅ?DvĆ8A•2ôìuIå©è¹„ORQi'€–}„€¤©É)ðýª'?®_×J

Try it online!
Old 104 byte version in case that is more easily improved.
„€À€ˆ„I€Ü‚.•ÂkXñ…ΓVt€Ïè∍‡Λi„2¶’að=–½6™oÑþÁāõgO·ð~
λ†₃›;â&ÄFv¾‡1~ǝQa«;cS•u2ôIå©è¹„ORQi'€–}„€¤©É)ðýª'?®_×J

Not happy with the compression nor the special case for ?.

OK what is this? Did you just re-order the states or something?

@EriktheOutgolfer: The 104 byte version is just a compression of the numbers corresponding to the characters positions in the alphabet (A=1,C=3 ...). The 103 byte version does the same for some states and merge some states that end in the same letter that a new state starts with. I'm sure this can still be improved and I'll add a better explanation when I've golfed it more.

Nice answer! I like the .•~Zµ∞/'—¶[@øl•Œ2ù you've used for some of the states, instead of just compressing all the states and doing the 2ô. And nice approach overall. (Glad I saw your answer before attempting something myself, because it definitely wouldn't have been as short..)

F#, 222 211 bytes
let f v=let(a,b)=if"OR"=v then("I am not",".")elif"WALAKSCARINMNVTNCTX NHIDE MOHIL COKY MSD PAZ WIA WVA FL GA MA MD ME MI MT NE ND NJ NY UT WY".Contains v then("I am",".")else("What is","?")in a+" an engineer"+b

Try it online!
Expanded:
let f v =
    let (a,b) =
        if "OR" = v then ("I am not",".")
        elif "WALAKSCARINMNVTNCTX NHIDE MOHIL COKY MSD PAZ WIA WVA FL GA MA MD ME MI MT NE ND NJ NY UT WY".Contains v then ("I am",".")
        else ("What is","?")
    a + " an engineer" + b

Given a two-letter state v passed to the function f, build a tuple (a, b) representing the head and tail of the "engineer" sentence.
Feel free to use the "compressed state string" freely; it's one whole byte shorter than the MINCALA one...

R, 109 96 bytes
function(x)sub("#"," an engineer",c("I am not#","I am#","What is#?"))[2-x%in%state.abb+!x=="OR"]

Try it online!
13 bytes thanks to J.Doe - through use of regex and indexation.

97 bytes

@J.Doe sub is much better, thank you!

96 bytes

@J.Doe Of course!

Japt, 136 135 131 129 128 bytes
More savings may be available by experimenting with the order of the state abbreviations - I'll come back to that in a while.
`mnnmlãGLÏz¯¬ct¸flgaá[9¨kyµmçpCijmsmtnhnvnyn¬kpÂÉcsdk¡x©vavt°±wvwy`ò øUv)?"I am {¥"OR"?"not ":P}"+` à¨\ `:`Wt   à¨\?

Try it online

Explanation

We take a compressed string of the lowercased abbreviations, decompress it, and split it into an array of 2 character strings using the ò method.
We then use the ø method to see if the array contains Uv, which is the input string converted to lowercase.
If we so, we build our output string, beginning with "I am "
Checking if the input string ¥ (is equal to) "OR" allows us to append either "not " or the empty string variable P.
And then we decompress and append the compressed string "an engineer".
If the input was not found in the array, then we output the decompression of compressed string "What is an engineer?".

CJam, 143 bytes
"ORIA MINCALA MSCTNMNVAKY WAZ PAR FL GA NHID COKSD ME MDE MA MTX NE NJ NY ND MOH UT WVT WIL WY"q#g"I am not
I am
What is?"N/=)" an engineer"\

Try it online! or as a test suite
Explanation
"ORIA...."       e# Push a string in which every state is a substring, but no non-state is
                 e# a substring.
q                e# Read the input.
#                e# Find the index of the input in the string. (-1 if not found)
g                e# Signum of the index: -1 for negative, 0 for 0, 1 for positive.
"I am.... "      e# Push this string. Note the trailing space on the first two lines of it.
N/               e# Split it on newlines.
=                e# Get the string at index given by the signum.
)                e# Pull out the last character.
" an engineer"\  e# Push " an engineer" and bring the other character to the TOS.
                 e# Implicit output.

Since Oregon (OR) is at the start of the string, finding the signum of the index of the input in that will be -1 if not found, 0 if OR, 1 if any other state. Which string to print can be decided by that.

Python 3, 180 179 178 bytes
def f(s):e=" not"*(s=="OR")+" an engineer";return"I am"+e if s in"PALAKSCAZ CTNMINCOR FL GA MDE ME MND MA MSD MOKY NE NH NJ NY WA OHID UTX MTNVARIA WIL WVT WY"else"What is"+e+"?"

Try it online!

Yep, it's correct: Try it online!

166 bytes. I'm sure the string can also be tightened up a liitle more by reusing states

Thanks @JoKing. It resembles the Python 2 answer too much at this point IMO :). I've been trying to compress the string, but the shortest I could get was 92 symbols. I've written a short script to do that, but it can only cut it down to 94 characters, and it doesn't compress optimally. I also think that in this particular challenge the magic string itself should not be included in the byte count.

Haskell, 220 214 210 209 bytes
s(a:b:c)=[a,b]:s(b:c)
s _=[]
a="I am "
e="an engineer "
i"OR"=a++"not "++e
i x|x`elem`s"MINCALA MSCTNMNVAKY WAZ PAR FL GA NHID COKSD ME MDE MA MTX NE NJ NY ND MOH RIA UT WVT WIL WY"=a++e
i _="What is "++e++"?"

Try it online!

otherwise = True, 1<2 is even shorter

Facepalm, thanks!

You have included OR in the long string in the second definition of i

I stole the long string from the other answers. OR isn't part of it though?

No, not anymore :)

PHP, 188 Bytes
$e=" an engineer";echo strpos(_TNNMLAALAKAZARCACOCTDEFLGAHIIDILINIAKSKYMEMDMAMIMNMSMOMTNENVNHNJNYNCNDOHOKORPARISCSDTXUTVTVAWAWVWIWY,$argn)&1?"I am".($argn!="OR"?"":" not").$e:"What is$e?";

Try it online!

in_array(...) to strpos(_AKALARAZCACOCTDEFLGAHIIAIDILINKSKYLAMAMDMEMIMNMOMSMTNCNDNENHNJNMNVNYOHOKPARISCSDTNTXUTVAVTWAWIWVWY,$argn)&1.

@Christoph works not for an Input for example of LA

Hm right :/ maybe we can reorder the string a bit .. I'll try. Also invalidates the js answer btw.

_NMMNINTNRIHIMIWISCNCCTMTUTVTWVNVFLILCAALGAIAMAPAVAWACOLAMOAKARKSMSNHOHOKORAZDEIDKYMEMDNENJNYNDSDTXWY works

@Christoph Or my order work too.

C#, 178 bytes
s=>(s=="OR"?"I am notx":"MINCALA MSCTNMNVAKY WAZ PARIA FL GA NHID COKSD ME MDE MA MTX NE NJ NY ND MOH UT WVT WIL WY".Contains(s)?"I amx":"What isx?").Replace("x"," an engineer");

Run in C# Pad
Golf based on Mayube's solution; new here, so I don't have enough rep to comment.

Might want to edit in a link in to his solution :) If you click share on his solution, it gives you a link straight to it.

@StephenS Thanks for the tip!

Javascript 204
s=>{h=/^(A[LKZR]|C[AOT]|DE|FL|[GPLV]A|[HR]I|I[DLNA]|K[SY]|M[EDAINSOT]|N[EVHJMYCD]|O[HK]|S[CD]|T[NX]|[VU]T|W[AVIY]|(OR))$/.exec(s);return(!h?"What is ":"I am "+(h[2]?"not ":""))+"an engineer"+(!h?'?':'')}

Pure optimize s=>(!(h=/(A[LKZR]|C[AOT]|DE|FL|[GPLV]A|[HR]I|I[DLNA]|K[SY]|M[EDAINSOT]|N[EVHJMYCD]|O[HKR]|S[CD]|T[NX]|[VU]T|W[AVIY])/.test(s))?"What is":"I am"+(s=='OR'?" not":""))+" an engineer"+['?'[+h]]

@l4m2 nice, that's got my answer beat.

Java, 173 bytes
s->(!"MINCALARIA MSCTNMNVAKY WAZ PAR FL GA NHID COKSD ME MDE MA MTX NE NJ NY ND MOH UT WVT WIL WY OR".contains(s)?"What is":"I am"+(s.equals("OR")?" not":""))+" an engineer"

Welcome to PPCG! All entries must be a full program or a function; I believe you can turn this into a valid lambda expression (and therefore function) by adding s-> to the beginning.

AWK, 189 bytes
/A[LKZR]|C[AOT]|DE|FL|[GPV]A|HI|I[DLNA]|KS|KY|LA|M[EDAINSOT]|N[EVHJMYCD]|O[HKR]|RI|SC|SD|TN|TX|UT|VT|W[AVIY]/{print"I am "($0~OR?"not ":"")"an engineer";exit}
{print"What is an engineer?"}

If input matches a regex containing all the state abbreviations, print "I am an engineer" with a 'not' inserted in the middle if the state is Oregon, then exit.
If the input does not match the regex, it must not be a US state abbreviation.

Python 3, 238 bytes
def f(x):s=x in('ALAKAZARCACOCTDEFLGAHIIDILINIAKSKYLAMEMDMAMIMNMSMOMTNENVNHNJNMNYNCNDOHOKORPARISCSDTNTXUTVTVAWAWVWIWY'[i:i+2]for i in range(0,100,2));o=x=='OR';q=(1-o)*(1-s);return q*'What is'+(1-q)*('I am'+o*' not')+' an engineer'+q*'?'

Explanation
No compression techniques used.
def f(x):
    # Check if State
    s = x in ('ALAK...WIWY'[i:i+2]
              for i in range(0, 100, 2))

    # Check if Oregon
    o = x == 'OR'

    # Check if neither Oregon nor State
    q = (1-o) * (1-s)

    # Construct output string
    return q * 'What is' + \
        (1-q) * ('I am' + o * ' not') + \
        ' an engineer' + \
        q * '?'

It's Oregon, not Ohio.

@L3viathan Not sure how I mess that up after seeing Oregon everywhere due to Life is Strange... ¯\(ツ)/¯

Stax, 100 bytes
This language postdates the challenge.  But the author (me) didn't see it until now.
éë&W≈#W¬π█▐╜╣╟◙√a☻∞ZrπU♫ÿô♠▌⌠Që≡AûpI⌡ÄNAç¶µ↑╝╣òøΩ.¬É]╩Æ↓d∩é¡2Å²eB┼¼▬5∟┤sW♠♂↑q▐WMï╝|Ñ↑╫+3¼↔îûvlLΩ∟┬oë

Run and debug it

JavaScript ES6, 175171 Bytes
x=>[`What is${e=" an engineer"}?`,`I am${x=="OR"?" not"+e:e}`][+!!'MINCALA MSCTNMNVAKY WAZ PAR FL GA NHID COKSD ME MDE MA MTX NE NJ NY ND MOH ORIA UT WVT WIL WY'.match(x)]

Joined lots of good
Or 152 bytes on ISO encoding
Generator:
'x=>[`What is${e=" an engineer"}?`,`I am${x=="OR"?" not"+e:e}`][+!!btoa`*`.match(x)]'.replace('*',atob('MINCALA MSCTNMNVAKY WAZ PAR FL GA NHID COKSD ME MDE MA MTX NE NJ NY ND MOH ORIA UT WVT WIL WY '.replace(/ /g,'/')))

It might be possible to rearrange the string so using btoa to expand

C (gcc), 0+176 bytes
-Dz"=an engineer" -Df(s)*s-79|1[s]-82?strstr("MINCALA=MSCTNMNVAKY WAZ PAR FL GA NHID COKSD ME MDE MA MTX NE NJ NY ND MOH RIA UT WVT WIL WY",s)?"I am"z:"What is"z"?":"I am not"z
Try it online!
pure translate

Powershell, 175 bytes
(('I am'+' not'*!($i='ORIA MINCALA MSCTNMNVAKY WAZ PAR FL GA NHID COKSD ME MDE MA MTX NE NJ NY ND MOH UT WVT WIL WY'.IndexOf($args))+($e=' an engineer')),"What is$e`?")[!++$i]

Test script:
$f = {

$e=' an engineer'
$i='ORIA MINCALA MSCTNMNVAKY WAZ PAR FL GA NHID COKSD ME MDE MA MTX NE NJ NY ND MOH UT WVT WIL WY'.IndexOf($args)
(('I am'+' not'*!$i+$e),"What is$e`?")[!++$i]

# Important! OR is a first state in the modified @totallyhuman's genuis string

}

@(
    ,('OR', 'I am not an engineer')
    ,('AL', 'I am an engineer')
    ,('IL', 'I am an engineer')
    ,('ZZ', 'What is an engineer?')
) | % {
    $s,$e = $_
    $r = &$f $s
    "$($r-eq$e): $r"
}

Output:
True: I am not an engineer
True: I am an engineer
True: I am an engineer
True: What is an engineer?

Python 3, 236 182 181 bytes
lambda s:'I am not'+e if s=='OR'else'I am'+e if s in'MINCALA MSCTNMNVAKY WAZ PAR FL GA NHID COKSD ME MDE MA MTX NE NJ NY ND MOH RIA UT WVT WIL WY'else'What is%s?'%e
e=' an engineer'

Try it online!
TIO contains test cases for all the states.
-54 bytes thanks to the string compression

You can use the string compression from the other answers to save bytes

MINCALA MSCTNMNVAKY WAZ PAR FL GA NHID COKSD ME MDE MA MTX NE NJ NY ND MOH ORIA UT WVT WIL WY is better compression

q/kdb+, 174 bytes
Solution:
{a:" an engineer?";$[(#:)l:ss["ORIA MINCALA MSCTNMNVAKY WAZ PAR FL GA NHID COKSD ME MDE MA MTX NE NJ NY ND MOH UT WVT WIL WY";x];-1_"I am",$[l~(),0;" not";""],a;"What is",a]}

Explanation:
  {
  // save string into variable a
  a:" an engineer?";
  // try to find the input x in the condensed string, save location in variable l, $ is a if/else
  $[(#:)l:ss["ORIA MINCALA MSCTNMNVAKY WAZ PAR FL GA NHID COKSD ME MDE MA MTX NE NJ NY ND MOH UT WVT WIL WY";x];
  // found a match, check if it was at index 0 ('OR') and inject " not" if so, drop the '?' off the end
  -1_"I am",$[l~(),0;" not";""],a;
  // otherwise return 'What is an engineer?'
  "What is",a]
  }

Notes:
Used the 'compressed' string from other answers, struggling to find a way to bring it into a single line in order to avoid assignment of the a variable (yet still add the ? when input is not a state.

Retina, 175 bytes
..
I am $&~MINCALAZ SCT FL GA WIAKSD ME MD MA MNMS MOKY MTNE NVTX NH NJ NY ND COHIDE PARIL UT VA WA WV WY
(..)~.*\1.*
~
OR~.*
not ~
I am ..~.*
What is ~?
~
an engineer

Try it online! Hopefully I've appropriated the best state list. Explanation:
..
I am $&~MINCALAZ SCT FL GA WIAKSD ME MD MA MNMS MOKY MTNE NVTX NH NJ NY ND COHIDE PARIL UT VA WA WV WY

Start building up the result. Also, insert the state list for use by the next stage.
(..)~.*\1.*
~

If it's one of the 49 states, delete the state and list.
OR~.*
not ~

If it's Oregon, replace the state with not, and delete the list.
I am ..~.*
What is ~?

If it's anything else, replace everything with the other output.
~
an engineer

Add these word in last to avoid repetition.

Crystal, 232 207 205 Bytes
i="ORALAKAZARCACOCTDEFLGAHIIDILINIAKSKYLAMEMDMAMIMNMSMOMTNENVNHNJNMNYNCNDOHOKPARISCSDTNTXUTVTVAWAWVWIWY".split(/(..)/).index ARGV[0];p (i ?"I am ": "What is ")+(i==1 ?"not ": "")+"an engineer"+(i ?"": "?")

Try it online. (slightly modified due to an issue of ARGV)

Factor, 135 bytes
USE: usa-cities [ " an engineer"swap [ "I am"swap string>state OR =
[ " not"append ] when ""] [ 2drop "What is" "?"] recover surround ]

More readable, and named:
: engineer? ( state-name -- str )
  [ " an engineer" ] dip ! put this below the input on the stack
  [
    [ "I am" ] dip       ! put this below the input too but above the other
    string>state OR =    ! string>state throws on a non-state name
    [ " not" append ] when ""  ! otherwise and if it is OR, append this
  ]
  [ 2drop "What is" "?" ] recover surround ; ! catch error, surround string

[ x ] dip and x swap are equivalent in stack effect but the first is shorter only when nested: [ [ [ x ] dip ] dip ] dip.

Python 2, 213 211 194 Bytes
c="uTXnMSCORIDEwVAKYmTNHILfLAZpALmNEmOKSDwINCARmEwAnJnDmAmIAgAwYcTnVToHnYmD"
r=(lambda x:x in c or x[0].lower()+x[1]in c)(i)^1
u="What is "*r+("I am "+"not "*(i=="OR"))*(r^1)+"an engineer"+"?"*r

Try It Online
Stuff i'm working on shortening:

(i=="OR")
or x[0].lower()+x[1]in c

Update:

Saved 2 Bytes by replacing s=not r with s=r^1
Separated header and footer of code

Ruby, 164 bytes
->s{r="What is an engineer?"
j=379
"##(*Q0'7q;N>%*$o(.F%#&'#&#5##%$%+%5%)5r@#P,B353*/%".bytes{|i|s==(j+=i-34).to_s(36).upcase&&r="I am not"[0,i==41?8:4]+r[7,12]}
r}

Uses a run length encoding, therefore magic string is 50 bytes long, one per state. In order to build this, it was first necessary to put the state codes in alphabetical order of state code, rather than state name. Unfortunately 7 bytes are needed to convert the base36 representation of j from a lowercase statecode into an uppercase statecode.
Ungolfed in test program
f=->s{                                                  #s is the input string.
  r="What is an engineer?"                              #Set r to "What is an engineer?"
  j=379                                                 #Set j to one less than 380, which in base36 becomes AK, the first statecode alphabetically
  "##(*Q0'7q;N>%*$o(.F%#&'#&#5##%$%+%5%)5r@#P,B353*/%". #Iterate through the run length encoded string
  bytes{|i|                                             #(each character represents how far in base 36 each state code is from the previous one)
    s==(j+=i-34).to_s(36).upcase&&                      #take the ascii value of the character and subtract 34 (example #=35-34=1) and add to j. Convert j to base36 to get a state code.
      r="I am not"[0,i==41?8:4]+r[7,12]                 #if the state code matches s, modify r. Take the first 4 characters of "I am not" (first 8 in the case of OR where i==41)
  }                                                     #and add r[7,12]==" an engineer" (12 characters of the existing value of r, starting at character 7
r}                                                      #return r

%w{AL AK AZ AR CA CO CT DE FL GA HI ID IL IN IA KS KY LA ME MD MA MI MN MS MO MT NE NV NH NJ NM NY NC ND OH OK OR PA RI SC SD TN TX UT VT VA WA WV WI WY XX}.map{|i|p [i,f[i]]}

Excel VBA, 261 254 Bytes
an anonymous vbe immediate window function that takes input as expected type Variant\String from cell [A1] and outputs my status as an engineer in the given US state to the VBE immediate window.
Golfed
e=" an engineer":i="I am":?IIf(UBound(Filter(Split("AL AK AZ AR CA CO CT DE FL GA HI ID IL IN IA KS KY LA ME MD MA MI MN MS MO MT NE NV NH NJ NM NY NC ND OH OK PA RI SC SD TN TX UT VT VA WA WV WI WY"),[A1])),IIf([A1]="OR",i+" not"+e,"What is"+e+"?"),i+e)

Ungolfed
Function AmIAnEngineer(ByVal state As String) As String

    Dim i As String, _
        e As String

    Let i = "I am"
    Let e = " an engineer"

    Let AmIAnEngineer = _
        IIf(UBound(Filter( _
                Split("AL AK AZ AR CA CO CT DE FL GA HI ID IL IN IA KS KY LA ME MD MA MI MN MS MO MT NE NV NH NJ NM NY NC ND OH OK PA RI SC SD TN TX UT VT VA WA WV WI WY"), _
                state)), IIf(state = "OR", i & " not" & e, "What is" & e & "?"), i & e)
End Function

''# Usage:
''#
''#     ?AmIAnEngineer("VA")
''#     I am an engineer

/// (Slashes), 2102 bytes
/*/\/-\/\///$/\/,\/\///OR/_not .//AL*AK*AZ*AR*CA*CO*CT*DE*FL*GA*HI*ID*IL*IN*IA*KS*KY*LA*ME*MD*MA*MI*MN*MS*MO*MT*NE*NV*NH*NJ*NM*NY*NC*ND*OH*OK*PA*RI*SC*SD*TN*TX*UT*VT*VA*WA*WV*WI*WY*AA$AB$AC$AD$AE$AF$AG$AH$AI$AJ$AM$AN$AO$AP$AQ$AS$AT$AU$AV$AW$AX$AY$BA$BB$BC$BD$BE$BF$BG$BH$BI$BJ$BK$BL$BM$BN$BO$BP$BQ$BR$BS$BT$BU$BV$BW$BX$BY$BZ$CB$CC$CD$CE$CF$CG$CH$CI$CJ$CK$CL$CM$CN$CP$CQ$CR$CS$CU$CV$CW$CX$CY$CZ$DA$DB$DC$DD$DF$DG$DH$DI$DJ$DK$DL$DM$DN$DO$DP$DQ$DR$DS$DT$DU$DV$DW$DX$DY$DZ$EA$EB$EC$ED$EE$EF$EG$EH$EI$EJ$EK$EL$EM$EN$EO$EP$EQ$ER$ES$ET$EU$EV$EW$EX$EY$EZ$FA$FB$FC$FD$FE$FF$FG$FH$FI$FJ$FK$FM$FN$FO$FP$FQ$FR$FS$FT$FU$FV$FW$FX$FY$FZ$GB$GC$GD$GE$GF$GG$GH$GI$GJ$GK$GL$GM$GN$GO$GP$GQ$GR$GS$GT$GU$GV$GW$GX$GY$GZ$HA$HB$HC$HD$HE$HF$HG$HH$HJ$HK$HL$HM$HN$HO$HP$HQ$HR$HS$HT$HU$HV$HW$HX$HY$HZ$IB$IC$IE$IF$IG$IH$II$IJ$IK$IM$IO$IP$IQ$IR$IS$IT$IU$IV$IW$IX$IY$IZ$JA$JB$JC$JD$JE$JF$JG$JH$JI$JJ$JK$JL$JM$JN$JO$JP$JQ$JR$JS$JT$JU$JV$JW$JX$JY$JZ$KA$KB$KC$KD$KE$KF$KG$KH$KI$KJ$KK$KL$KM$KN$KO$KP$KQ$KR$KT$KU$KV$KW$KX$KZ$LB$LC$LD$LE$LF$LG$LH$LI$LJ$LK$LL$LM$LN$LO$LP$LQ$LR$LS$LT$LU$LV$LW$LX$LY$LZ$MB$MC$MF$MG$MH$MJ$MK$ML$MM$MP$MQ$MR$MU$MV$MW$MX$MY$MZ$NA$NB$NF$NG$NI$NK$NL$NN$NO$NP$NQ$NR$NS$NT$NU$NW$NX$NZ$OA$OB$OC$OD$OE$OF$OG$OI$OJ$OL$OM$ON$OO$OP$OQ$OS$OT$OU$OV$OW$OX$OY$OZ$PB$PC$PD$PE$PF$PG$PH$PI$PJ$PK$PL$PM$PN$PO$PP$PQ$PR$PS$PT$PU$PV$PW$PX$PY$PZ$QA$QB$QC$QD$QE$QF$QG$QH$QI$QJ$QK$QL$QM$QN$QO$QP$QQ$QR$QS$QT$QU$QV$QW$QX$QY$QZ$RA$RB$RC$RD$RE$RF$RG$RH$RJ$RK$RL$RM$RN$RO$RP$RQ$RR$RS$RT$RU$RV$RW$RX$RY$RZ$SA$SB$SE$SF$SG$SH$SI$SJ$SK$SL$SM$SN$SO$SP$SQ$SR$SS$ST$SU$SV$SW$SX$SY$SZ$TA$TB$TC$TD$TE$TF$TG$TH$TI$TJ$TK$TL$TM$TO$TP$TQ$TR$TS$TT$TU$TV$TW$TY$TZ$UA$UB$UC$UD$UE$UF$UG$UH$UI$UJ$UK$UL$UM$UN$UO$UP$UQ$UR$US$UU$UV$UW$UX$UY$UZ$VB$VC$VD$VE$VF$VG$VH$VI$VJ$VK$VL$VM$VN$VO$VP$VQ$VR$VS$VU$VV$VW$VX$VY$VZ$WB$WC$WD$WE$WF$WG$WH$WJ$WK$WL$WM$WN$WO$WP$WQ$WR$WS$WT$WU$WW$WX$WZ$XA$XB$XC$XD$XE$XF$XG$XH$XI$XJ$XK$XL$XM$XN$XO$XP$XQ$XR$XS$XT$XU$XV$XW$XX$XY$XZ$YA$YB$YC$YD$YE$YF$YG$YH$YI$YJ$YK$YL$YM$YN$YO$YP$YQ$YR$YS$YT$YU$YV$YW$YX$YY$YZ$ZA$ZB$ZC$ZD$ZE$ZF$ZG$ZH$ZI$ZJ$ZK$ZL$ZM$ZN$ZO$ZP$ZQ$ZR$ZS$ZT$ZU$ZV$ZW$ZX$ZY$ZZ$-/_.//_/I am //./an engineer//,/What is .?/

Try it online
Somewhat ungolfed
/OR/_not ./

/AL/-//AK/-//AZ/-//AR/-//CA/-//CO/-//CT/-//DE/-//FL/-//GA/-//HI/-//ID/-//IL/-//IN/-//IA/-//KS/-//KY/-//LA/-//ME/-//MD/-//MA/-//MI/-//MN/-//MS/-//MO/-//MT/-//NE/-//NV/-//NH/-//NJ/-//NM/-//NY/-//NC/-//ND/-//OH/-//OK/-//PA/-//RI/-//SC/-//SD/-//TN/-//TX/-//UT/-//VT/-//VA/-//WA/-//WV/-//WI/-//WY/-/

/AA/,//AB/,//AC/,//AD/,//AE/,//AF/,//AG/,//AH/,//AI/,//AJ/,//AM/,//AN/,//AO/,//AP/,//AQ/,//AS/,//AT/,//AU/,//AV/,//AW/,//AX/,//AY/,//BA/,//BB/,//BC/,//BD/,//BE/,//BF/,//BG/,//BH/,//BI/,//BJ/,//BK/,//BL/,//BM/,//BN/,//BO/,//BP/,//BQ/,//BR/,//BS/,//BT/,//BU/,//BV/,//BW/,//BX/,//BY/,//BZ/,//CB/,//CC/,//CD/,//CE/,//CF/,//CG/,//CH/,//CI/,//CJ/,//CK/,//CL/,//CM/,//CN/,//CP/,//CQ/,//CR/,//CS/,//CU/,//CV/,//CW/,//CX/,//CY/,//CZ/,//DA/,//DB/,//DC/,//DD/,//DF/,//DG/,//DH/,//DI/,//DJ/,//DK/,//DL/,//DM/,//DN/,//DO/,//DP/,//DQ/,//DR/,//DS/,//DT/,//DU/,//DV/,//DW/,//DX/,//DY/,//DZ/,//EA/,//EB/,//EC/,//ED/,//EE/,//EF/,//EG/,//EH/,//EI/,//EJ/,//EK/,//EL/,//EM/,//EN/,//EO/,//EP/,//EQ/,//ER/,//ES/,//ET/,//EU/,//EV/,//EW/,//EX/,//EY/,//EZ/,//FA/,//FB/,//FC/,//FD/,//FE/,//FF/,//FG/,//FH/,//FI/,//FJ/,//FK/,//FM/,//FN/,//FO/,//FP/,//FQ/,//FR/,//FS/,//FT/,//FU/,//FV/,//FW/,//FX/,//FY/,//FZ/,//GB/,//GC/,//GD/,//GE/,//GF/,//GG/,//GH/,//GI/,//GJ/,//GK/,//GL/,//GM/,//GN/,//GO/,//GP/,//GQ/,//GR/,//GS/,//GT/,//GU/,//GV/,//GW/,//GX/,//GY/,//GZ/,//HA/,//HB/,//HC/,//HD/,//HE/,//HF/,//HG/,//HH/,//HJ/,//HK/,//HL/,//HM/,//HN/,//HO/,//HP/,//HQ/,//HR/,//HS/,//HT/,//HU/,//HV/,//HW/,//HX/,//HY/,//HZ/,//IB/,//IC/,//IE/,//IF/,//IG/,//IH/,//II/,//IJ/,//IK/,//IM/,//IO/,//IP/,//IQ/,//IR/,//IS/,//IT/,//IU/,//IV/,//IW/,//IX/,//IY/,//IZ/,//JA/,//JB/,//JC/,//JD/,//JE/,//JF/,//JG/,//JH/,//JI/,//JJ/,//JK/,//JL/,//JM/,//JN/,//JO/,//JP/,//JQ/,//JR/,//JS/,//JT/,//JU/,//JV/,//JW/,//JX/,//JY/,//JZ/,//KA/,//KB/,//KC/,//KD/,//KE/,//KF/,//KG/,//KH/,//KI/,//KJ/,//KK/,//KL/,//KM/,//KN/,//KO/,//KP/,//KQ/,//KR/,//KT/,//KU/,//KV/,//KW/,//KX/,//KZ/,//LB/,//LC/,//LD/,//LE/,//LF/,//LG/,//LH/,//LI/,//LJ/,//LK/,//LL/,//LM/,//LN/,//LO/,//LP/,//LQ/,//LR/,//LS/,//LT/,//LU/,//LV/,//LW/,//LX/,//LY/,//LZ/,//MB/,//MC/,//MF/,//MG/,//MH/,//MJ/,//MK/,//ML/,//MM/,//MP/,//MQ/,//MR/,//MU/,//MV/,//MW/,//MX/,//MY/,//MZ/,//NA/,//NB/,//NF/,//NG/,//NI/,//NK/,//NL/,//NN/,//NO/,//NP/,//NQ/,//NR/,//NS/,//NT/,//NU/,//NW/,//NX/,//NZ/,//OA/,//OB/,//OC/,//OD/,//OE/,//OF/,//OG/,//OI/,//OJ/,//OL/,//OM/,//ON/,//OO/,//OP/,//OQ/,//OS/,//OT/,//OU/,//OV/,//OW/,//OX/,//OY/,//OZ/,//PB/,//PC/,//PD/,//PE/,//PF/,//PG/,//PH/,//PI/,//PJ/,//PK/,//PL/,//PM/,//PN/,//PO/,//PP/,//PQ/,//PR/,//PS/,//PT/,//PU/,//PV/,//PW/,//PX/,//PY/,//PZ/,//QA/,//QB/,//QC/,//QD/,//QE/,//QF/,//QG/,//QH/,//QI/,//QJ/,//QK/,//QL/,//QM/,//QN/,//QO/,//QP/,//QQ/,//QR/,//QS/,//QT/,//QU/,//QV/,//QW/,//QX/,//QY/,//QZ/,//RA/,//RB/,//RC/,//RD/,//RE/,//RF/,//RG/,//RH/,//RJ/,//RK/,//RL/,//RM/,//RN/,//RO/,//RP/,//RQ/,//RR/,//RS/,//RT/,//RU/,//RV/,//RW/,//RX/,//RY/,//RZ/,//SA/,//SB/,//SE/,//SF/,//SG/,//SH/,//SI/,//SJ/,//SK/,//SL/,//SM/,//SN/,//SO/,//SP/,//SQ/,//SR/,//SS/,//ST/,//SU/,//SV/,//SW/,//SX/,//SY/,//SZ/,//TA/,//TB/,//TC/,//TD/,//TE/,//TF/,//TG/,//TH/,//TI/,//TJ/,//TK/,//TL/,//TM/,//TO/,//TP/,//TQ/,//TR/,//TS/,//TT/,//TU/,//TV/,//TW/,//TY/,//TZ/,//UA/,//UB/,//UC/,//UD/,//UE/,//UF/,//UG/,//UH/,//UI/,//UJ/,//UK/,//UL/,//UM/,//UN/,//UO/,//UP/,//UQ/,//UR/,//US/,//UU/,//UV/,//UW/,//UX/,//UY/,//UZ/,//VB/,//VC/,//VD/,//VE/,//VF/,//VG/,//VH/,//VI/,//VJ/,//VK/,//VL/,//VM/,//VN/,//VO/,//VP/,//VQ/,//VR/,//VS/,//VU/,//VV/,//VW/,//VX/,//VY/,//VZ/,//WB/,//WC/,//WD/,//WE/,//WF/,//WG/,//WH/,//WJ/,//WK/,//WL/,//WM/,//WN/,//WO/,//WP/,//WQ/,//WR/,//WS/,//WT/,//WU/,//WW/,//WX/,//WZ/,//XA/,//XB/,//XC/,//XD/,//XE/,//XF/,//XG/,//XH/,//XI/,//XJ/,//XK/,//XL/,//XM/,//XN/,//XO/,//XP/,//XQ/,//XR/,//XS/,//XT/,//XU/,//XV/,//XW/,//XX/,//XY/,//XZ/,//YA/,//YB/,//YC/,//YD/,//YE/,//YF/,//YG/,//YH/,//YI/,//YJ/,//YK/,//YL/,//YM/,//YN/,//YO/,//YP/,//YQ/,//YR/,//YS/,//YT/,//YU/,//YV/,//YW/,//YX/,//YY/,//YZ/,//ZA/,//ZB/,//ZC/,//ZD/,//ZE/,//ZF/,//ZG/,//ZH/,//ZI/,//ZJ/,//ZK/,//ZL/,//ZM/,//ZN/,//ZO/,//ZP/,//ZQ/,//ZR/,//ZS/,//ZT/,//ZU/,//ZV/,//ZW/,//ZX/,//ZY/,//ZZ/,/

/-/_./
/_/I am /
/./an engineer/
/,/What is .?/

TIO, with some examples

Python 2, 277 275 201 bytes
Here's one where I've compressed the list to 70 characters. But the compression is complex enough that my decompression makes the code uncompetitively heavy. Perhaps someone else has a better decompression idea.
[edit:] You could do this in binary compressed data pretty trivially and save another 25% on the list size. You only need 6 bits/char to do upper and lower case letters. And it'd probably be even more wordy to decode.
The list is lowercase first letter, followed by upper case second letters of everything with that first letter. Order doesn't matter; I used one extra lowercase at the end to make the regular expression work this way.
Using the lambda cleverness from above, it's 201 bytes, but is still too fattened by that regex:

lambda s,e=' an engineer':'I am'+' not'*(s=='OR')+e if re.match('.*%s[A-Z]*%s[A-Z]*[a-z]'%(s[0].lower(),s[1]),'aLKZRcAOTdEfLgAhIiDLNAkSYlAmEDAINSOTnEVHJMYCDoHKRpArIsCDtNXuTvTAwAVIYz')else'What is%s?'%e

def m(t):
 p='I am'
 e=' an engineer'
 if t=='OR':print(p+' not'+e);return()
 else:
  w='What is'
  if re.match('.*%s[A-Z]*%s[A-Z]*[a-z]'%(t[0].lower(),t[1]),'aLKZRcAOTdEfLgAhIiDLNAkSYlAmEDAINSOTnEVHJMYCDoHKRpArIsCDtNXuTvTAwAVIYz')==None:print(w+e+'?');return()
  print(p+e)

Try it online!

199 bytes.

nice. One byte at a time, eh?:)

$|201 - 199| = 2 \neq 1$.

Okay, two bytes at a time. It was a sentiment, not a count, but I'll roll with ya here.

Jq 1.5, 186 bytes
if.=="OR"then"I am not X"elif inside("MINCALA MSCTNMNVAKY WAZ PAR FL GA NHID COKSD ME MDE MA MTX NE NJ NY ND MOH RIA UT WVT WIL WY")then"I am X"else"What is X?"end|sub("X";"an engineer")

Expanded
  if   . =="OR"                                then "I am not X"
  elif inside("@totallyhuman's genius string") then "I am X"
  else                                              "What is X?"
  end
| sub("X";"an engineer")

Try it online!
Jq 1.5, 195 bytes
if.=="OR"then"I am not X" elif test("A[LKRZ]|I[ADLN]|M[ADEINOST]|N[CDEHJMVY]|W[AIVY]|[GCLPV]A|[CUV]T|CO|DE|FL|HI|KS|KY|OH|OK|RI|SC|SD|TN|TX")then"I am X"else"What is X?"end|sub("X";"an engineer")

Expanded
  if   . =="OR"          then "I am not X"
  elif test("big regex") then "I am X"
  else                        "What is X?"
  end
| sub("X";"an engineer")

Try it online!

Python 3, 227 bytes
lambda i:['What is an engineer?','I am '+'not '*(i>'OR')+'an engineer'][i in'AL&AK&AZ&AR&CA&CO&CT&DE&FL&GA&HI&ID&IL&IN&IA&KS&KY&LA&M&MD&MA&MI&MN&MS&MO&MT&NE&NV&NH&NJ&NM&NY&NC&ND&OH&OK&OR&PA&RI&SC&SD&TN&TX&UT&VT&VA&WA&WV&WI&WY']

Try it online!

JavaScript (Node.js), 180 bytes
x=>[`What is${e=" an engineer"}?`,`I am${x=="OR"?" not"+e:e}`][+!!/A[LKZR]|CO|DE|FL|[GPVCL]A|[HR]I|I[DLNA]|K[SY]|M[EDAINSOT]|N[EVHJMYCD]|O[HKR]|S[CD]|T[NX]|[UVC]T|W[AVIY]/.exec(x)]

Try it online!
Somehow the combination of the previous 2 JS answers.

Why use !!reg.exec not reg.test?

@l4m2 Oh I forgot .test method! That helps!

Python 3, 161 bytes
o=('What is%s?','I am'+' not'*(i=='OR')+"%s")[i in'MINCALA MSCTNMNVAKY WAZ PAR FL GA NHID COKSD ME MDE MA MTX NE NJ NY ND MOH ORIA UT WVT WIL WY']%' an engineer'

Try it online!

Yeah uh, from looking at others' answers, mine is pretty much exactly the same as a couple others. Not sure if this counts, but I came to this answer independently.

Hello and welcome to PPCG. As an answer to your comment, yes -- you can answer duplicate answers -- we try to give the benefit of the doubt that the answer was not simply copied.
However, your answer does not comply with our default I/O -- either write a function or print to stdout.

Pyth, 145 bytes
I wish I could do stack manipulation in Pyth. Overly late to the party...
X_1@c"I am not
I am
What is?"b._x"ORIA MINCALA MSCTNMNVAKY WAZ PAR FL GA NHID COKSD ME MDE MA MTX NE NJ NY ND MOH UT WVT WIL WY"Q" an engineer"

Try it online!
Explanation
"ORIA MINCALA MSCTNMNVAKY WAZ PAR FL GA NHID COKSD ME MDE MA MTX NE NJ NY ND MOH UT WVT WIL WY"

The magic string from @BusinessCat's answer

x↑Q

What is the string's index in the above magic string? -1 for nonexistent.

._↑

Find the sign, yielding 1, 0, -1.

c"I am not
I am
What is?"b

Split the string into a list of newlines.

@↑ ↑↑

Index the sign into the above splitted list

X_1↑" an engineer"

Insert the string " an engineer" before the last character
```


text:
Elo Rating Calculator
Related
Task
Your task is to calculate the new Elo rating (FIDE rating system) for a player after winning, losing or drawing a game of chess.
To calculate the Elo rating two formulas are needed:
R' = R0 + K*(S - E)
E = 1 / (1 + 10 ^ ((R1 - R0) / 400))

where:

R' is the new rating for player0,
R0 is the current rating of player0 and R1 is the current rating of player1,
S is the score of the game: 1 if player0 wins, 0 if player0 loses or
0.5 if player0 draws,
K = 40 if the given history has a length < 30, even if it exceeds 2400
K = 20 if the given history has a length >= 30 and never exceeds 2400 (<2400),
K = 10 if the given history has a length >= 30 and exceeds 2400 at any point (>=2400)

(if history has a length < 30 but a max value >= 2400 K will equal 40)
Input

History of player0's ratings as an array of positive integers greater than 0, where the last item is the players current rating. If no history is given, the current rating will be 1000
Rating of player1 as an integer
Score, either 1, 0 or 0.5

Output
R', A decimal integer of player0's new rating
Examples
input: [], 1500, 1
  K = 40 (length of history is less than 30)
  E = 1 / (1 + 10 ^ ((1500 - 1000) / 400)) = 0.0532
  R' = 1000 + 40*(1 - 0.0532) = 1038
output: 1038

input: [1000, 1025, 1050, 1075, 1100, 1125, 1150, 1175, 1200, 1225, 1250, 1275, 1300, 1325, 1350, 1375, 1400, 1425, 1450, 1475, 1500, 1525, 1550, 1575, 1600, 1625, 1650, 1675, 1700, 1725], 1000, 0
  K = 20 (length of history is more than 30 but never exceeds 2400)
  E = 1 / (1 + 10 ^ ((1000 - 1725) / 400)) = 0.9848
  R' = 1725 + 20*(0 - 0.9848) = 1705
output: 1705

input: [1000, 1025, 1050, 1075, 1100, 1125, 1150, 1175, 1200, 1225, 1250, 1275, 1300, 1325, 1350, 1375, 1400, 1425, 1450, 1475, 1500, 1525, 1550, 1575, 1600, 1625, 1650, 1800, 2100, 2500], 2200, 0.5
  K = 10 (length of history is more than 30 and exceeds 2400)
  E = 1 / (1 + 10 ^ ((2200 - 2500) / 400)) = 0.8490
  R' = 2500 + 10*(0.5 - 0.8490) = 2497
output: 2497

Test cases:
[2256,25,1253,1278,443,789], 3999, 0.5 -> 809
[783,1779,495,1817,133,2194,1753,2169,834,521,734,1234,1901,637], 3291, 0.5 -> 657
[190,1267,567,2201,2079,1058,1694,112,780,1182,134,1077,1243,1119,1883,1837], 283, 1 -> 1837
[1665,718,85,1808,2546,2193,868,3514,436,2913,6,654,797,2564,3872,2250,2597,1208,1928,3478,2359,3909,581,3892,1556,1175,2221,3996,3346,238], 2080, 1 -> 248
[1543,2937,2267,556,445,2489,2741,3200,528,964,2346,3467,2831,3746,3824,2770,3207,613,2675,1692,2537,1715,3018,2760,2162,2038,2637,741,1849,41,193,458,2292,222,2997], 3814, 0.5 -> 3002

Notes
You won't get an input with fewer scores than 30 and a maximum score higher than 2400
This is code-golf, so the shortest code in bytes wins!

I'm assuming len(history)<30 and max(history)>2400 is either impossible, or results in K=40?

@StewieGriffin That is possible and does result in K=40

Is it though? In reality?

Can we assume that the player's history will never have 0?

@StewieGriffin From my understanding from the official FIDE website I believe it is.

@Arjun I'm not sure officially, but for this challenge yes, you can assume a player's rating and history will always be > 0

@StewieGriffin Tested your code and it works for the test cases I provided, so it looks to be fine

Note: According to the FIDE-scoring system: If you play 41 games against a player having a score of 5000 (more than 2000 points higher than the highest achieved score ever), you'll end up with a score of 2400. I believe that fewer scores than 30, and a maximum score higher than 2400 should be considered invalid input (but that's OP's decision). There might be solutions that will get k!=40 for such an input (it's not one of the current test cases).

@StewieGriffin Oh right, I see what you mean, if you start with 1000 there's no way to reach 2400 in under 30 games. I'll change the test cases.

@StewieGriffin Yep, but a few of the test cases have less 30 scores and a maximum higher than 2400, so they'll need to be changed :)

@Tom, ah, I see... :)

@Arjun "Output: R', An integer of player0's new rating", integer usually means a whole, rounded number ;) So I would say you need to have them rounded

@Arjun You'll have to round to match the test cases, I believe it's rounded when officially calculating the Elo.

Rather than passing in an empty array, can we take no input for the history?

@Giuseppe That would be okay

Section 8.54 of https://www.fide.com/fide/handbook.html?id=197&view=article might be of use. Rating difference of >400 is treated as =400

Octave, 106 bytes
This assumes the history never contains a zero.
@(h,r,s)(h=[1e3,h])(n=nnz(h))+((40-(20*(n>30)))-(10*((n>30)&(max(h)>2401))))*(s-(1/(1+10^((r-h(n))/400))))

This outputs (after some formatting):
Correct - Calculated
1038    - 1037.87
1705    - 1705.3
2497    - 2496.51

Try it online!

Note: According to the FIDE-scoring system: If you play 41 games against a player having a score of 5000 (more than 2000 points higher than the highest achieved score ever), you'll end up with a score of 2400. I believe that fewer scores than 30, and a maximum score higher than 2400 should be considered invalid input (but that's OP's decision).
Check it here

JavaScript (ES7), 124 bytes
This is a valid JavaScript anonymous function. Add f= at the beginning and invoke like f(arg1,arg2,arg3). Assumes that the first element of history is not 0 (which is allowed).
(a,r,s)=>(e=a.some(c=>c>2400),a=a[0]?a:[1e3],Math.round((y=a.pop())+((a.length<30?40:(e?20:10))*(s-1/(1+10**((r-y)/400))))))

let f=
(a,r,s)=>(e=a.some(c=>c>2400),a=a[0]?a:[1e3],Math.round((y=a.pop())+((a.length<30?40:(e?20:10))*(s-1/(1+10**((r-y)/400))))))

btnTrigger.onclick = () => {
  let a = inputA.value.split`,`.map(c=>parseInt(c,10)),
      r = parseInt(inputR.value,10),
      s = parseFloat(inputS.value,10);

  console.log(f(a,r,s));
}

Add a Single Comma in History input box for empty History

<input type="text" id="inputA" placeholder="Comma Separated History">
<input type="text" id="inputR" placeholder="Value for R1">
<input type="text" id="inputS" placeholder="Value for S">

<button type="button" id="btnTrigger">Submit</button>

Your calculations seem to be wrong, for [2256,25,1253,1278,443,789], 3999, 0.5 the output should be 809

@Tom Fixed. It was something wrong with Test Snippet (it was parsing 0.5 as 0). And I have added the rounding part too. It really costed me a lot!

Nice, looks good now!

Python 3, 106 bytes
def f(h,b,s):a=([1e3]+h)[-1];return round(a+((len(h)<30)*4or-~(max(h)<2400))*10*(s-1/(1+10**((b-a)/400))))

Try it online!

without rounding, 98 bytes:
def f(h,b,s):a=([1e3]+h)[-1];return((len(h)<30)*4or-~(max(h)<2400))*10*(s-1/(1+10**((b-a)/400)))+a

Try it online!

R, 109 bytes
function(p,s,h=1000,l=length(h))round(h[l]+`if`(l<30,40,`if`(any(h>2400),10,20))*(s-1/(1+10^((p-h[l])/400))))

Returns an anonymous function that takes several arguments: p, player 1's rating, s, the score of the game, and h, the history. Technically takes another argument l but it defaults to the length of h. h defaults to 1000 so if there is no historical record of games, no value is provided for h.
Try it online!

JavaScript, 105 bytes
(h,r,s,u=h.length?h.pop():1e3,k=h.length>28?h.some(v=>v>2400)?10:20:40)=>u+k*s-k/(1+10**((r-u)/400))+.5|0

oK, 66 bytes
{*|x+_.5+(40-(10*2+|/2399<x)*29<#x)*z-1%1+exp((y-*|x)%400)*log 10}

Try it online.
For regular k, add two bytes by turning log and exp into `log and `exp respectively.

Haskell 158 bytes
g h o s=round$p+k*(s-1/(1+10**((o-p)/400)))
 where
 p=if(l h<1)then 1000else last h
 k=40-(if(l h)>=30then 20else 0)-if(any(>=2400)h)then 10else 0
 l=length

g is a function that takes a list h representing the history of the player, o, the opponent points and,s the  score of the game.


text:
ASCII Arc Length: How long is a piece of string?
Given an ASCII representation of a piece of string, determine its length.
Input
An multi-line ASCII rendering of a piece of string, which runs from top to bottom, with one 'node' (corner) on each line of input. The delimiter may be assumed to be CR, LF, CRLF, or LFCR. Input may be accepted from STDIN, Command Line Argument, Function Parameter, or whatever daft method your language of choice necessitates if none of the prior are applicable.
  #
 #
 #
  ####
##
  ##
 #
  ##
  #

Each line in the context of the previous tells you the position of one of the nodes on the string. The first line always has exactly one hash #, so the position is trivially found. Each following line has a hash '#' on the node itself, and on all calls which must be included to make the string 'complete' (attached to itself). All positions will be between 0 and 9 inclusive, but the difference is what realy matters.
For example, the string defined by the sequence 1, 3, 6, 5, 1, 3, 4 has the following nodes:
 #
   #
      #
     #
 #
   #
 #
     #
    #

Which we must join up on a line by line basis starting from the top (nodes marked with X for clarity, they will be hashes in actual imputs). This means, the first line has no hashes, and each following line has exactly as many hashes as are rquired to 'connect' the previous node to the current with hashes. This can be thought of as putting a hash in every space between the two nodes (on the lower line) and then removing any that appear on the line above. Example:
 X
  #X
    ##X
     X
 X###
   X
 X#
   ##X
    X

There will be no fewer than 2 lines, and no more than 100. The input will be padded with spaces to form a rectangle of width 10 (excluding the line delimiters). You may require a trailing new-line be present or absent, but declare any such requirements in your answer.
Computing the Arc Length
You must output the arc length of this string. You compute the arc length by taking the distances between each consequtive nodes. The distance between one node and the next is sqrt(d^2 + 1) where d is the difference in position (that is, the current position minus the previous). For example, the sequence 4, 8, 2, 3, 4, 4 has differences 4, -6, 1, 1, 0, which gives distances (rounded to 2 dp) 4.12, 6.08, 1.41, 1.41, 1 by squaring, adding one, and square-rooting. The arc length is then the sum of these distances, 14.02.
You must reduce the result of the square-root to 2 decimal places before summing (this is to allow sqrt tables and make answers consistent/comparable across systems; see below).
Using the input example at the top`
  #    2 -1  1.41
 #     1 +0  1.00
 #     1 +4  4.12
  #### 5 -5  5.10
##     0 +3  3.16
  ##   3 -2  2.24
 #     1 +2  2.24
  ##   3 -1  1.41
  #    2

            20.68 (total)

Output
You must output the arc length as exactly one number, or a decimal string represenation with 2 decimal places of precision. Numerical output must be rounded, but I'm not going to quibble about minute floating point inaccuracies.
SQRT Table
This is a table of the rounded squareroots you must conform to. You can either use this table itself, or verify that your system conforms to the results.
1  1.00
2  1.41
5  2.24
10 3.16
17 4.12
26 5.10
37 6.08
50 7.07
65 8.06
82 9.06

Powershell to produce this table:
0..9 | % {"" + ($_ * $_ + 1) + " " + [System.Math]::Sqrt($_ * $_ +1).ToString("0.00")}

Test Cases
Input:
  #
 #
 #
  ####
##
  ##
 #
  ##
  #

Output: 20.68
Input:
   #
###
   ####
      #
   ###
    #
     ###
 ####
   #
  #
##
  ########
         #
      ###
######

Output: 49.24
Input:
         #
       ##
 ######
 #
  ####
      #
######
#
 ########
     #
 ####
     ####

Output: 44.34
Test Code
A larger test case and a C# solver and example generator can be found as a Gist.
Victory Criterion
This is code-golf, the shortest code will win.

"where d is the difference in position" - Can you elaborate on that? Maybe it's just too early but, reading through your examples, I can't see how you're arriving at the d for each value in the sequences.

@shaggy I thought the examples would be sufficient, but I'll try to come up with some sensible wording. They are the literally the position minus the previous position.

@user202729 sorry for confusion, thought I'd explained that better... (made some edits that hopefully clarify). B is correct, you can think of it as filling in the hashes, starting at the top, and working your way down.

JavaScript (ES6), 158 bytes
-1 byte thanks to @VisualMelon
s=>s.split`
`.map(s=>(s=s.replace(/./g,(m,i)=>m>" "?i:""),n=s[0]>n?s.slice(-1):s[0]),n=p=0).reduce((t,v,i)=>(r=i&&t+(((p-v)**2+1)**.5*100+.5|0)/100,p=v,r),0)

Output is sometimes not exact  (0.999 instead of 1) due to floating-point imprecision, but rounding was done part-way through the steps in order to match the square root table.
Test Snippet
Note that trailing spaces on each line are ignored, so they can be omitted from the input.

f=
s=>s.split`
`.map(s=>(s=s.replace(/./g,(m,i)=>m>" "?i:""),n=s[0]>n?s.slice(-1):s[0]),n=p=0).reduce((t,v,i)=>(r=i&&t+(((p-v)**2+1)**.5*100+.5|0)/100,p=v,r),0)
<textarea id=I rows=15 cols=12></textarea><br>
<button onclick="O.value=f(I.value)">Run</button> <input id=O disabled>

Input and output look fine to me! I'm dreadful at JS, but do you need d? Would (p-v)**2 not work? Unless another surprise answer pops out of the ether, I'll accept this in a couple of days.

@VisualMelon Yeah, I was stuck on using d*d since that was shorter than d**2. Will update when I'm at a computer.