Which Ninjutsu am I casting?
JavaScript (ES6), 95 bytes
A shorter version suggested by @tsh
Expects [1,2,3]
for "TCJ"
.
(a,b,c)=>a^b&&a^c&&b^c?',Hu,Do,Sui,Hyo,Rai,Ka'.split`,`[c||7-b]+'ton':b?'Bunny':'Fuma Shuriken'
Try it online!
JavaScript (ES6), 99 bytes
Expects "012"
for "TCJ"
.
s=>/(.).?\1/.test([,b,c]=s)?'Bunny':b?'Hu,Do,Sui,Hyo,Rai,Ka'.split`,`[c||5-b]+'ton':'Fuma Shuriken'
Try it online!
Commented
s => // s = input string
/(.).?\1/ // regex to detect a duplicate character
.test([, b, c] = s) // apply it to s; at the same time, load the 2nd
// and 3rd characters into b and c respectively
? // if there's a duplicate:
'Bunny' // return 'Bunny'
: // else:
b ? // if the 2nd character is defined:
'Hu,Do,Sui,Hyo,Rai,Ka' // lookup string of prefixes
.split`,` // split it
[c || 5 - b] // use c if it's defined, or 5 - b otherwise
+ 'ton' // append the suffix
: // else:
'Fuma Shuriken' // return 'Fuma Shuriken'
R, 153 149 144 139 bytes
Edit: -5 bytes thanks to Giuseppe
function(x)`if`(any(table(x)>1),'Bunny',`if`((l=sum(x|1))-1,a[l*3-6+x[l]],'Fuma Shuriken'));a=paste0(scan(,''),'ton')
Ka
Rai
Hyo
Hu
Do
Sui
Try it online!
Input is 1
for 'Ten', 2
for 'Chi', 3
for 'Jin'.
Ungolfed:
a=paste0(scan(,''),'ton') # scan(,'') reads the subsequent strings until it finds an empty one,
Ka # paste0 joins them each together with 'ton'.
Rai
Hyo
Hu
Do
Sui
function(x){
if(any(table(x)>1))'Bunny' # if there are any duplicates: 'Bunny'
else{ # otherwise
l=length(x) # define l=length of x (the R golfy way: sum(x|1) because 'length' is 6 letters)
if(l-1)a[l*3-6+tail(x,1)] # if it isn't length 1, output the relevant element from the vector 'a' of ninjutsu names
else'Fuma Shuriken' # otherwise (it's length 1): 'Fuma Shuriken'.
}
}
```
Haskell, 116 109 bytes
saved 7 bytes thanks to @ovs, and obscure things in the stdlib (why is word
but not split
in Prelude?)
n[_]="Fuma Shuriken" -- matches a list of one element
n(a:b)|a`elem`b="Bunny" -- matches a list starting with a where a is in b `| `(cond)` =` is a guard that checks cond
n[a,b]=words"Ka Rai Hyo Ho Do Sui"!!b++"ton" -- !! is indexing, ++ is appending
n[a,b,c]=n[b+3,c+3] -- don't mistake n[] as indexing, it's calling n with a list.
-- b+3 so it will still catch duplicates where b=c
Highly readable (IMO), and highly not PHP (sorry PHP). This makes excessive use of pattern matching. It takes input as a list of Ten=0, Chi=1, Jin=2. Trailing whitespace and comments (starting with --) are not counted.
ideone it!