SHARE
TWEET

Untitled

a guest Mar 5th, 2017 133 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _02.Japanese_Roulette
  8. {
  9.     /*Russian roulette is a game of chance where a single player places a single bullet in a revolver, spins the cylinder,
  10.      points the muzzle against their head and pulls the trigger. Japanese people however are not that brave (crazy) so they play with toy guns.
  11.     Every player can spin the cylinder with different strength. The numeric representation of the strength is with how many places they can move
  12.     the bullet while spinning. Note that the cylinder has only 6 places but the strength could be much more than 6 due to several
  13.     rotations of the cylinder.  
  14.     You are given an array of integers which represent the cylinder of the revolver where 0 means empty and 1 represents the bullet.
  15.     There is exactly one bullet in the cylinder.
  16.     You will receive another array, this time of strings where every index is a different player and every value is the strength of the player and
  17.     the direction to which the player rotates the cylinder.
  18.     The elements in the array will be separated by spaces. The power and the direction will be separated by a comma (”,”) e.g.: “111,Left”.
  19.     The muzzle IS at index 2 of the cylinder. If the element at that position is 1, the current player loses the game.
  20.  
  21.     Note! After a player pulls the trigger the cylinder spins with one position to the right.
  22.     The next player starts spinning with the new state of the cylinder.
  23.     Assume that the order of the players is according to their places in the array. The player with index 0 shots first, index 1-second and so on…
  24.     Your task is to go through all players, and see if anyone will shoot himself with the toy gun. */
  25.     class JapaneseRoulette
  26.     {
  27.         static void Main(string[] args)
  28.         {
  29.             int[] cylinder = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
  30.             string[] rotation = Console.ReadLine().Split(' ').ToArray();
  31.            
  32.            
  33.             var initialPosition = 0;
  34.             var endPosition = 0;
  35.             bool dead = false;
  36.  
  37.             for (int i = 0; i < rotation.Length; i++)
  38.             {
  39.                 if (cylinder[i] == 1)
  40.                 {
  41.                     initialPosition = i;
  42.                 }
  43.             }
  44.             for (int i = 0; i < rotation.Length; i++)
  45.             {
  46.                 dead = false;
  47.                 string[] currentCommand = rotation[i].Split(',');
  48.                 var force = int.Parse(currentCommand[0]);
  49.                 var direction = currentCommand[1];
  50.  
  51.                 switch (direction)
  52.                 {
  53.                     case "Right":
  54.                         endPosition = (initialPosition + force) % cylinder.Length;
  55.                         initialPosition = endPosition;
  56.                         break;
  57.                     case "Left":
  58.                         endPosition = Math.Abs(initialPosition - force) % cylinder.Length;
  59.                         initialPosition = endPosition;
  60.                         break;
  61.                 }
  62.  
  63.                 if (endPosition == 2)
  64.                 {
  65.                     Console.WriteLine($"Game over! Player {i} is dead.");
  66.                    
  67.                     break;
  68.                 }
  69.                 initialPosition++;
  70.                
  71.             }
  72.             if (!dead)
  73.             {
  74.                 Console.WriteLine($"Everybody got lucky!");
  75.             }
  76.            
  77.         }
  78.        
  79.     }
  80. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top