6
\$\begingroup\$

Objective

Given the name of a robot master in Mega Man: Powered Up except the trailing string Man, output the name of the robot master (again, except the trailing string Man) whom the inputted robot master has advantage over in fighting (with his weapon).

Mapping

(Input -> Output)

Cut -> Bomb
Bomb -> Ice
Ice -> Fire
Fire -> Oil
Oil -> Elec
Elec -> Time
Time -> Guts
Guts -> Cut

I/O Format

It is implementation-defined whether to accept leading or trailing whitespace on the input.

Outputting a trailing newline in the output is permitted.

Otherwise flexible.

\$\endgroup\$
4
  • \$\begingroup\$ Is a trailing space permitted? \$\endgroup\$
    – Neil
    Commented Nov 28 at 0:53
  • \$\begingroup\$ Potential duplicate \$\endgroup\$
    – Shaggy
    Commented Nov 28 at 1:26
  • \$\begingroup\$ @Neil No, unless it's directly followed by a newline. \$\endgroup\$ Commented Nov 28 at 1:36
  • 7
    \$\begingroup\$ Another potential duplicate \$\endgroup\$
    – tsh
    Commented Nov 28 at 3:36

15 Answers 15

13
+300
\$\begingroup\$

Python, 61 bytes

-3 thanks to @Jonathan Allan

lambda b:"FGBTEOCIiuoiliucrtmmelteesbec"[int(b,36)%9075&7::8]

Attempt This Online!

Was:

Python, 66 bytes

lambda b:"GBFETCIOuoiliucitmremtelsbece"["TCIOEGBF".find(b[0])::8]

Attempt This Online!

A bit boring.

Python, 67 bytes

for f in 0,eval:*Cut,Guts,Time,Elec,Oil,Fire,Ice,Bomb,Cut=globals()

Attempt This Online!

This one is exhilaratingly dirty.

How?

Creates global variables named Cut, Guts, etc. such that eval can be used to retrieve their robot master (or whatever the story is) from their names.

The assignment needs to be done twice: First pass adds the variable names to the global dictionary (which remembers insertion order). Note that the packed assignment ignores the values of globals() and assigns whatever names happen to have been last inserted (we don't care in the first pass) as values to the new variables .

At the second pass the names (rotated by one because we list Cut twice) will be at the end of the dictionary. So the value "Cut" will be assigned to variable Guts etc.

\$\endgroup\$
3
  • 1
    \$\begingroup\$ @JonathanAllan Thanks! I managed to shave off another one by using int instead of ord. I'm not very good with this whole mod chain business, so feel free to 1up me again ;-) \$\endgroup\$ Commented Nov 30 at 6:45
  • \$\begingroup\$ @JonathanAllan how did you come up with the modular formula? \$\endgroup\$
    – Jonah
    Commented Dec 1 at 4:22
  • 1
    \$\begingroup\$ @Jonah I just brute-forced it until I found something short that worked. \$\endgroup\$ Commented Dec 5 at 20:54
5
\$\begingroup\$

Python 3, 72 bytes

dict(zip(l:="Cut Bomb Ice Fire Oil Elec Time Guts".split()*2,l[1:])).get

Try it online!

Creates a dictionary whose keys in order are Cut, Bomb, ... (doubled), and whose corresponding values are those with the first item removed. The main function is the .get method of the dictionary; if the dictionary itself suffices, those 4 bytes can be cut.

Also 72 bytes, using id just for as the shortest predefined variable:

{id:(id:=x)for x in"Cut Bomb Ice Fire Oil Elec Time Guts".split()*2}.get

Try it online!

Python, 73 bytes

lambda s:l[l.index(s)-1]
l="Guts Time Elec Oil Fire Ice Bomb Cut".split()

Try it online!

Uses that indices wrap around into the negatives, so the index before 0 is -1 which selects the last element.

Python 3, 73 bytes

lambda s:"Guts Time Oil Cut Elec Fire | Ice Bomb".split()[ord(s[0])%25%9]

Try it online!

Only looks at the boss's letter (which are all distinct), and uses a mod chain to classify it. Bytestring input would save 5 bytes.

\$\endgroup\$
0
4
\$\begingroup\$

Retina 0.8.2, 75 bytes

T`B-H\OITcel-obs`IB_T\OC-Gemit_c_
But
Bomb
ct
ce
em
ire
ii
lec
itm
uts
rm
l

Try it online! Link includes test cases. Explanation:

T`B-H\OITcel-obs`IB_T\OC-Gemit_c_

Transliterate as many letters as possible, including all of the upper case letters. This is enough to handle Elec to Time and Guts to Cut. (O normally means 13579 so it needs to be escaped. Other escaped letters are avoided by including them in a range.)

But
Bomb

Cut transliterates to But so fix it to become Bomb without changing Cut transliterated from Guts.

ct
ce

Bomb transliterates to Ict so fix it to become Ice without changing Guts or Cut.

em
ire

Ice transliterates to Fem so fix it to become Fire.

ii
lec

Oil transliterates to Eii to fix it to become Elec.

itm
uts

Time transliterates to Gitm to fix it to become Guts.

rm
l

Fire transliterates to Oirm to fix it to become Oil.

\$\endgroup\$
3
\$\begingroup\$

Bash + coreutils, 56

grep -Po $1\\K.[a-z]+<<<CutBombIceFireOilElecTimeGutsCut

Try it online!

\$\endgroup\$
3
\$\begingroup\$

JavaScript (Node.js), 61 bytes

x=>'CutGutsTimeElecOilFireIceBombCut'.match(`(.[a-z]*)`+x)[1]

Try it online!

-2B emanresu A

\$\endgroup\$
1
2
\$\begingroup\$

APL+WIN, 58 bytes

Prompts for name.

↑(r⍳⊂⎕)⌽r←(+\(⎕av⍳r)>43)⊂r←'CutBombIceFireOilElecTimeGuts'

Try it online! Thanks to Dyalog Classic

\$\endgroup\$
2
\$\begingroup\$

Google Sheets, 64 bytes 83 bytes 93 bytes

=regexextract("CutBombIceFireOilElecTimeGutsCut",A1&"(.[a-z]+)")

Using l4m2's regex approach.

The other way:

=let(a,split("Cut1Bomb1Ice1Fire1Oil1Elec1Time1Guts1Cut",1),index(a,match(A1,a,)+1))

screenshot

\$\endgroup\$
2
\$\begingroup\$

Charcoal, 40 39 bytes

§⪪”↶0²«gR→X?→?ïM↘⌈⟦ⅈH×↷⟲&↨⟧‽≧jβ” ﹪⍘Sγ⁹⁷

Try it online! Link is to verbose version of code. Explanation: The input string is converted from base 95, then reduced modulo 97 and again modulo 9 via modular indexing into a compressed string of the relevant words split on spaces.

\$\endgroup\$
1
\$\begingroup\$

Jelly, 27 bytes

“B¢ċḅßṗœyœḳlsɲṀƥṆQ_»ḲṖ€ṙiḢɗ

A monadic link that accepts a list of characters and yields a list of characters.

Try it online!

How?

“...»ḲṖ€ṙiḢɗ - Link: list of characters, Name
“...»        - compressed string -> "Icel Fired Oily Elect Timex Gutsy Cute Bombe"
     Ḳ       - split at spaces
      Ṗ€     - pop each -> Names = ["Ice","Fire","Oil","Elec","Time","Guts","Cut","Bomb"]
           ɗ - last three links as a dyad - f(Names, Name)
         i   -   1-indexed index of {Name} in {Names}
        ṙ    -   rotate {Names} left by {that}
          Ḣ  -   head
\$\endgroup\$
1
\$\begingroup\$

05AB1E, 29 bytes

”GutsížÆ™ĊĊٵـº”#4δ£Dyk>è

Try it online or verify all test cases.

Explanation:

”GutsížÆ™ĊĊٵـº”
           # Push dictionary string "Guts Cut Bomb Ice Fire Oil Electricity Time"
 #         # Split it on spaces
   δ       # Map over each word:
  4 £      # Only keep the first 4 characters to fix "Electricity"→"Elec"
     D     # Duplicate this list
      Ik   # Get the index of the input in this list
        >  # Increase it by 1
         è # Modular index it into the list again
           # (after which the result is output implicitly)

See this 05AB1E tip of mine (section How to use the dictionary?) to understand why ”GutsížÆ™ĊĊٵـº” is "Guts Cut Bomb Ice Fire Oil Electricity Time".

\$\endgroup\$
1
\$\begingroup\$

Kotlin, 81 bytes

{s->"Cut Bomb Ice Fire Oil Elec Time Guts Cut".split(" ").run{get(indexOf(s)+1)}}

Try it online!

or if you accept leading spaces:

Kotlin, 67 bytes

{s->"CutBomb IceFire OilElecTimeGutsCut".substringAfter(s).take(4)}

Try it online!

both of these use val f:(String)->String= as the header

\$\endgroup\$
1
\$\begingroup\$

Java (JDK), 71 bytes

It seems splitting is shorter than regex here.

s->"Cut Bomb Ice Fire Oil Elec Time Guts Cut".split(s)[1].split(" ")[1]

Try it online!


Alternative solution (74 bytes) if lowercase is allowed in the output:

s->"CbombCBiceBIfireIFoilFOelecOEtimeETgutsTGcut".split(""+s.charAt(0))[1]

Try it online!

\$\endgroup\$
1
\$\begingroup\$

AWK, 76 bytes

{for(split("Cut Bomb Ice Fire Oil Elec Time Guts",a);a[i++]!~$1;);}$0=a[i%8]

Try it at home!

awk '{for(split("Cut Bomb Ice Fire Oil Elec Time Guts",a);a[i++]!~$1;);}$0=a[i%8]' <<< Guts

However, it would get stuck in a loop with invalid input.

{for(split("Cut Bomb Ice Fire Oil Elec Time Guts",a); # Robot Masters
a[i++]!~$1;);}                                        # match and next
$0=a[i%8]                                             # output/catch loop
\$\endgroup\$
1
\$\begingroup\$

Perl 5 -p, 55 bytes

CutBombIceFireOilElecTimeGutsCutX=~/$_(.+?)[A-Z]/;$_=$1

Try it online!

Input must have first letter capitalized.

\$\endgroup\$
1
\$\begingroup\$

Tcl, 86 bytes

set L {Cut Bomb Ice Fire Oil Elec Time Guts Cut}
puts [lindex $L [lsearch $L $argv]+1]

Try it online!

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.