3
1
Wanna be an Alchemist
I've been watching Full Metal Alchemist these past days and I've been wondering, It is really possible to trans-mutate matter? In the real world, I don't know if it is possible, but in the machine world, we think we "can".
Problem
Your task is, Given an input of N chemical elements (K, Mg, C, O, etc...), you are going to:
- Get the first letter of the element
- Convert that letter into binary
- Rotate 2 bits to the right
- Apply Binary Addition
- If the result is more that 8 bits then get the one's complement of the result and removes the highest bit
- Output the ASCII (ISO 8859-1) representation of the result
Example
Given Chemical Elements: (K, Ca, Mg)
- Get the first letter of the element
K, C, M
- Convert that letter into binary
K => 01001011, C => 01000011, M => 01001101
- Rotate 2 bits to the right
K => 11010010, C => 11010000, M => 01010011
Sum bits
K => 11010010
+C => 11010000
+M => 01010011
=111110101
If the result is more that 8 bits then get the one's complement and removes the highest bit
00001010
- Output the ASCII representation of the result.
Result:
Test Cases
(H, Mn, C) => Ê
(I, H, Se) => Ç
(K, Ca, Mg) =>
This is code golf so the shortest answer wins
When you say "Convert that letter into binary" am I correct in thinking you mean using ASCII? Or is it ok to use EBDIC or UTF-32? :) – Andrew – 2018-03-06T20:58:16.163
@AndrewPiliser ASCII. Sorry if i was misunderstood – Luis felipe De jesus Munoz – 2018-03-06T20:59:50.953
1
This is a great idea! In the future though, if you have an idea but it isn't a complete challenge, or if you just need help, you can use the Sandbox.
– NoOneIsHere – 2018-03-06T21:01:01.9606The binary sum question needs addressing, the test cases don't work and the given link is about adding numbers that are represented in binary (which does not work out with the examples either). I am voting to close this as unclear in the interim (i.e. will vote to reopen when that is addressed). – Jonathan Allan – 2018-03-06T21:13:00.307
@totallyhuman yuup, I really don't know why I thought I read that. – Magic Octopus Urn – 2018-03-06T21:58:35.240
1Step 3 of the problem and example don't match (shift discards bits, rotate keeps them). Also, your test cases are wrong because the problem requires "ASCII" and the result characters are not in the seven-bit character set known as ASCII (perhaps you want ISO 8859-1?) – Fox – 2018-03-07T14:00:32.190
I'd recommend changing "ASCII" to "Unicode" and remove the requirement to check whether the result is printable or not (allow the output to be the character, no matter what it is) – caird coinheringaahing – 2018-03-07T14:06:00.807
@Fox Sorry, I meant the Extended ASCII (ISO 8859) that includes 8 bits . About the shit, I meant rotate. I'll update my question – Luis felipe De jesus Munoz – 2018-03-07T14:16:16.380
@cairdcoinheringaahing from
00000000
to00011111
are non printable characters. – Luis felipe De jesus Munoz – 2018-03-07T14:19:10.163@LuisfelipeDejesusMunoz 1) That doesn't include all the non-printable characters and 2) it adds unnecessary overhead to the challenge, which isn't recommended – caird coinheringaahing – 2018-03-07T14:20:33.120
@cairdcoinheringaahing ok, so just removing that part will be ok? – Luis felipe De jesus Munoz – 2018-03-07T14:22:16.410
Personally, I'd allow results with more than 8 bits to stay as they were (but that's up to you). If you remove the printable part, I'd definitely vote to reopen – caird coinheringaahing – 2018-03-07T14:23:46.160