6 kyu

T.T.T.23: Silly birds

41 of 62myjinxin2015

Description:

Story

Maybe you've been asked a question about the bird: there are eight birds in the tree. "Bang!", a man shot and killed a bird. How many birds are there in the tree now? If you are a child, you may answer 7. We are not children. We know that the bird will fly away after hearing the sound of the gun, there are 0 birds in the tree. Unless, they are silly birds ;-)

Task

Complete function sillyBirds() that accept an array updown that contains two strings, and a string shot. We can imagine the string in updown are two parallel wires, some silly birds stand on the wire.

updown = [
"____B____",
"_________"
]

They hear shots don't fly away, only to change their position. They always fly in the direction of 45 degrees (up or down). They always fly to the right (if there is no other bird in that position).

shot="Bang!"   //Shoot 1 time
return value === [
"_________",
"_____B___"
]

//another example of shoot 2 times:
updown = [
"____B____",
"_________"
]

shot="Bang!Bang!"   //Shoot 2 times
return value === [
"______B__",
"_________"
]

If there is another bird on the right, it will fly to the left.

updown = [
"____B____",
"_____B___"
]
shot="Bang!"   //Shoot 1 time
return value === [
"______B__",
"___B_____"
]

If there is another bird on both sides, it will fly away.(not too silly ;-)

updown = [
"____B____",
"___B_B___"
]
shot="Bang!"   //Shoot 1 time
return value === [
"__B___B__",
"_________"
]

If the bird's position is on the border, it will fly close to the middle.

updown = [
"B_______B",
"_________"
]
shot="Bang!"   //Shoot 1 time
return value === [
"_________",
"_B_____B_"
]

If there are obstacles (other birds), it will fly away.

updown = [
"B________",
"_B_______"
]
shot="Bang!"   //Shoot 1 time
return value === [
"__B______",
"_________"
]

If there are no birds, return two wires ;-)

updown = [
"_________",
"_________"
]
shot="Bang!"   //Shoot 1 time
return value === [
"_________",
"_________"
]

Finally, I want to say is that this is just a game, I do not want to kill the birds with a gun, we should take care of birds and other animals ;-)

Puzzles
Games
Strings

Stats:

CreatedAug 9, 2016
PublishedAug 9, 2016
Warriors Trained223
Total Skips19
Total Code Submissions475
Total Times Completed62
JavaScript Completions41
Python Completions26
Total Stars5
% of votes with a positive feedback rating94% of 25
Total "Very Satisfied" Votes23
Total "Somewhat Satisfied" Votes1
Total "Not Satisfied" Votes1
Total Rank Assessments5
Average Assessed Rank
6 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • myjinxin2015 Avatar
  • kazk Avatar
  • Voile Avatar
  • mauro-1 Avatar
Ad