# Ninjas in a Chat Log

Thanks to HyperNeutrino for making more test cases

Often in chat, someone will ask a question, and multiple people will answer it at the same time. Usually, the person who was beaten to the gun will say "ninja'd", creating even more unnecessary chat.

Given a chat log similar to the following:

Community: Hi
Test: Hi
Rando: What is 4 times 4?
Test: @Rando 16
Community: @Rando 16
Community: ninja'd


You are looking for the number of extraneous lines, which in the above exchange is 2. Two users both replied to another user with the same text, although he only wanted one answer, and then the second user said "ninja'd".

# Extraneous Messages

Note that for the following statement, a message is only the content left of the :<space>. However, if an extraneous message is removed, the <username>:<space> is also removed.

Your only task is finding extraneous messages in the input, and counting them. The first type of extraneous message is a message starting with @ that is basically (spaces and case differences are ignored) the same as the message before it. The second type of extraneous message is a message reading exactly ninja'd (case insensitive) immediately after an extraneous message of the first type by the same user (there will never be users with the same name in different cases, and the same user will always be in the same case).

# Input

Your input is the chat log, including the user's names, followed by a colon and a space, followed by their message. You may take the input as a newline-separated string, a list of strings, or another appropriate input format.

# Output

Your output is the number of extraneous messages.

# Test Cases

Community: Hi
Test: Hi
Rando: What is 4 times 4?
Test: @Rando 16
Community: @Rando 16
Community: NINJA'D

2


A: how is everyone doing today
B: good
C: good
C: this doesn't work: print5
B: ninja'd
C: ninja'd

2


A: test
B: @A hi
C: @Ahi
C: ninja'd

2


A: test
B: @A hi
B: @A hi
B: ninja'd

2


A:
B: @
B: @
B: ninja'd
B: ninja'd

2


A: ninja'd
B: ninja'd
C: @B ninja'd
B: @B ninja'd
B: ninja'd
C: ninja'd
C: ninja'd

2


Test: test
Testie: @Test TESTIE
Test: @Testie TESTIE
Test: ninja'd
Testie: TESTIE
Test: TESTIE

0


A: @B hi
C: @B hi
C: ninja'd
B: @C no
A: @CNO
A: ninja'd

4

• Sandbox – Stephen Jul 20 '17 at 19:12
• This reminds me of when ninja'd was ninja'd, than the explanation of what ninja'd means was ninja'd, and than the subsequent comment of being ninja'd while talking about ninja'd was ninja'd. – programmer5000 Jul 21 '17 at 1:02
• @programmer5000 ninja'd. – ATaco Jul 21 '17 at 6:43

# Retina, 50 bytes

TlL

(:@.*)¶(.+)\1
b\$2a
b(.*)a¶\1:NINJA'D
aa
a


Try it online!

• This is the answer to life, the universe, and everything ... +1 – Zacharý Jul 20 '17 at 21:16
• @Zacharý Not anymore :( – ovs Jul 21 '17 at 6:21

# Python 2, 237 bytes

l=lambda s:s[1].lower().replace(' ','')
m=[x.split(': ')for x in input()]
i=[0]
for j in range(1,len(m)):i+=[[m[j][1].lower()=="ninja'd"and i[-1]>1and m[j-1][0]==m[j][0],2][l(m[j-1])==l(m[j])and'@'==m[j][1][0]]]
c=i.count
print c(1)+c(2)


Try it online!

-19 bytes thanks to Zacharý

• @totallyhuman No >.< I solved it after I came back from playing outside with my brother lol. – HyperNeutrino Jul 20 '17 at 19:29
• Dude. Ýou really need to learn to remove useless spaces: 1 and=>1and. (Put the ý in if ýou credit, please). – Zacharý Jul 20 '17 at 21:11
• Change the final line into these two: c=i.count and print c(1)+c(2). – Zacharý Jul 20 '17 at 21:13
• @Zacharý ok, thanks. will make those edits – HyperNeutrino Jul 20 '17 at 21:14
• Can you combine the for loop into this: for j in range(1,len(m)):i+=[2]if'@'==m[j][1][0]and l(m[j-1][1])==l(m[j][1])else[m[j][1].lower()=="ninja'd"and i[-1]>1and m[j-1][0]==m[j][0]]? – Zacharý Jul 20 '17 at 21:18

# Python 3, 122 bytes

lambda s:sub(r"b(.*)a\n\1:NINJA'D",'aa',sub(r'.+(:@.*)\n(.+)\1',r'b\2a',sub(' ','',s.upper()))).count('a')
from re import*


Try it online!