




from __future__ import annotations

import random

from matplotlib import animation
from matplotlib import pyplot as plt

# Frame rate of the animation
SCREAMING_SNAKE_CASE:    Any											=   2_0

# Time between time steps in seconds
SCREAMING_SNAKE_CASE:    Optional[Any]											=   INTERVAL / 1_0_0_0



class       lowercase_		:



      def __init__( self  :      Any				,       snake_case__  :      Optional[int]				,       snake_case__  :      Any				,       snake_case__  :      int				,       snake_case__  :      Optional[int]				,       snake_case__  :      str = 1.0				,       snake_case__  :      int = 1.0				,       snake_case__  :      Any = "blue"				,       ):

        """simple docstring"""

        SCREAMING_SNAKE_CASE_							=       position_x
        SCREAMING_SNAKE_CASE_							=       position_y
        SCREAMING_SNAKE_CASE_							=       velocity_x
        SCREAMING_SNAKE_CASE_							=       velocity_y
        SCREAMING_SNAKE_CASE_							=       mass
        SCREAMING_SNAKE_CASE_							=       size
        SCREAMING_SNAKE_CASE_							=       color



      @property
      def   __a				( self  :      str     ):

        """simple docstring"""

        return self.position_x, self.position_y



      @property
      def   __a				( self  :      List[Any]     ):

        """simple docstring"""

        return self.velocity_x, self.velocity_y



      def   __a				( self  :      List[str]				,       snake_case__  :      Optional[Any]				,       snake_case__  :      Dict				,       snake_case__  :      Dict     ):

        """simple docstring"""

        self.velocity_x += force_x * delta_time
        self.velocity_y += force_y * delta_time






      def   __a				( self  :      Any				,       snake_case__  :      List[str]     ):

        """simple docstring"""

        self.position_x += self.velocity_x * delta_time
        self.position_y += self.velocity_y * delta_time



class       lowercase_		:



      def __init__( self  :      int				,       snake_case__  :      str				,       snake_case__  :      Optional[Any] = 1.0				,       snake_case__  :      int = 1.0				,       snake_case__  :      Tuple = 0.0				,       ):

        """simple docstring"""

        SCREAMING_SNAKE_CASE_							=       bodies
        SCREAMING_SNAKE_CASE_							=       gravitation_constant
        SCREAMING_SNAKE_CASE_							=       time_factor
        SCREAMING_SNAKE_CASE_							=       softening_factor



      def __len__( self  :      List[str]     ):

        """simple docstring"""

        return len(self.bodies     )






      def   __a				( self  :      Union[str, Any]				,       snake_case__  :      List[str]     ):

        """simple docstring"""

        for bodya in self.bodies:
          SCREAMING_SNAKE_CASE_							=       0.0
          SCREAMING_SNAKE_CASE_							=       0.0
          for bodya in self.bodies:
            if bodya != bodya:
              SCREAMING_SNAKE_CASE_							=       bodya.position_x - bodya.position_x
              SCREAMING_SNAKE_CASE_							=       bodya.position_y - bodya.position_y

              # Calculation of the distance using Pythagoras's theorem
              # Extra factor due to the softening technique
              SCREAMING_SNAKE_CASE_							=       (dif_x**2 + dif_y**2 + self.softening_factor) ** (
                  1 / 2
              )

              # Newton's law of universal gravitation.
              force_x += (
                  self.gravitation_constant * bodya.mass * dif_x / distance**3
              )
              force_y += (
                  self.gravitation_constant * bodya.mass * dif_y / distance**3
              )

            # Update the body's velocity once all the force components have been added
          bodya.update_velocity(lowerCamelCase__				,       lowerCamelCase__				,       delta_time * self.time_factor     )

        # Update the positions only after all the velocities have been updated
        for body in self.bodies:
          body.update_position(delta_time * self.time_factor     )


def 				_a       (				lowerCAmelCase						,	lowerCAmelCase						,	lowerCAmelCase   )->  Dict:
  body_system.update_system(lowerCAmelCase   )

  # Update the positions of the patches
  for patch, body in zip(lowerCAmelCase						,	body_system.bodies   ):
    SCREAMING_SNAKE_CASE_							=       (body.position_x, body.position_y)


def 				_a       (				lowerCAmelCase						,	lowerCAmelCase						,	lowerCAmelCase = -1						,	lowerCAmelCase = 1						,	lowerCAmelCase = -1						,	lowerCAmelCase = 1						,	)->  List[str]:
  SCREAMING_SNAKE_CASE_							=       plt.figure()
  fig.canvas.set_window_title(lowerCAmelCase   )
  SCREAMING_SNAKE_CASE_							=       plt.axes(
      xlim=(x_start, x_end)						,	ylim=(y_start, y_end)   )  # Set section to be plotted
  plt.gca().set_aspect('equal'   )  # Fix aspect ratio

  # Each body is drawn as a patch by the plt-function
  SCREAMING_SNAKE_CASE_							=       [
      plt.Circle((body.position_x, body.position_y)						,	body.size						,	fc=body.color   )
      for body in body_system.bodies
  ]

  for patch in patches:
    ax.add_patch(lowerCAmelCase   )

  # Function called at each step of the animation
  def update(lowerCAmelCase   ) -> list[plt.Circle]:
    update_step(lowerCAmelCase						,	lowerCAmelCase						,	lowerCAmelCase   )
    return patches

  SCREAMING_SNAKE_CASE_							=       animation.FuncAnimation(  # noqa: F841
      lowerCAmelCase						,	lowerCAmelCase						,	interval=lowerCAmelCase						,	blit=lowerCAmelCase   )

  plt.show()


def 				_a       (				)->  Union[str, Any]:
  SCREAMING_SNAKE_CASE_							=       0.9_7_0_0_4_3_6
  SCREAMING_SNAKE_CASE_							=       -0.2_4_3_0_8_7_5_3
  SCREAMING_SNAKE_CASE_							=       0.4_6_6_2_0_3_6_8_5
  SCREAMING_SNAKE_CASE_							=       0.4_3_2_3_6_5_7_3

  SCREAMING_SNAKE_CASE_							=       [
      Body(lowerCAmelCase						,	lowerCAmelCase						,	lowerCAmelCase						,	lowerCAmelCase						,	size=0.2						,	color='red'   ),
      Body(-position_x						,	-position_y						,	lowerCAmelCase						,	lowerCAmelCase						,	size=0.2						,	color='green'   ),
      Body(0						,	0						,	-2 * velocity_x						,	-2 * velocity_y						,	size=0.2						,	color='blue'   ),
  ]
  return BodySystem(lowerCAmelCase						,	time_factor=3   )


def 				_a       (				)->  Optional[Any]:
  SCREAMING_SNAKE_CASE_							=       7.3_4_7_6E2_2
  SCREAMING_SNAKE_CASE_							=       5.9_7_2E2_4
  SCREAMING_SNAKE_CASE_							=       1022
  SCREAMING_SNAKE_CASE_							=       384399000
  SCREAMING_SNAKE_CASE_							=       6.6_7_4E-1_1

  # Calculation of the respective velocities so that total impulse is zero,
  # i.e. the two bodies together don't move
  SCREAMING_SNAKE_CASE_							=       earth_mass * velocity_dif / (earth_mass + moon_mass)
  SCREAMING_SNAKE_CASE_							=       moon_velocity - velocity_dif

  SCREAMING_SNAKE_CASE_							=       Body(-earth_moon_distance						,	0						,	0						,	lowerCAmelCase						,	lowerCAmelCase						,	10000000						,	'grey'   )
  SCREAMING_SNAKE_CASE_							=       Body(0						,	0						,	0						,	lowerCAmelCase						,	lowerCAmelCase						,	50000000						,	'blue'   )
  return BodySystem([earth, moon]						,	lowerCAmelCase						,	time_factor=1000000   )


def 				_a       (				)->  Optional[Any]:
  SCREAMING_SNAKE_CASE_							=       []
  for _ in range(10   ):
    SCREAMING_SNAKE_CASE_							=       random.uniform(-0.5						,	0.5   )
    SCREAMING_SNAKE_CASE_							=       random.uniform(-0.5						,	0.5   )

    # Bodies are created pairwise with opposite velocities so that the
    # total impulse remains zero
    bodies.append(
        Body(
            random.uniform(-0.5						,	0.5   )						,	random.uniform(-0.5						,	0.5   )						,	lowerCAmelCase						,	lowerCAmelCase						,	size=0.0_5						,	)   )
    bodies.append(
        Body(
            random.uniform(-0.5						,	0.5   )						,	random.uniform(-0.5						,	0.5   )						,	-velocity_x						,	-velocity_y						,	size=0.0_5						,	)   )
  return BodySystem(lowerCAmelCase						,	0.0_1						,	10						,	0.1   )


if __name__ == "__main__":
      plot('''Figure-8 solution to the 3-body-problem''', example_a(), -2, 2, -2, 2)
      plot(
          '''Moon\'s orbit around the earth''',
          example_a(),
          -4_3_0_0_0_0_0_0_0,
          4_3_0_0_0_0_0_0_0,
          -4_3_0_0_0_0_0_0_0,
          4_3_0_0_0_0_0_0_0,
      )
      plot('''Random system with many bodies''', example_a(), -1.5, 1.5, -1.5, 1.5)





from __future__ import annotations

import random
import string



class       lowercase_		:



						def __init__( self  :      str				,       snake_case__  :      str | None = None     ):

								"""simple docstring"""

								SCREAMING_SNAKE_CASE_							=       passcode or self.__passcode_creator()
								SCREAMING_SNAKE_CASE_							=       self.__make_key_list()
								SCREAMING_SNAKE_CASE_							=       self.__make_shift_key()



						def __str__( self  :      List[Any]     ):

								"""simple docstring"""

								return "".join(self.__passcode     )



						def   __a				( self  :      Union[str, Any]				,       snake_case__  :      list[int]     ):

								"""simple docstring"""

								for i in range(1				,       len(snake_case__     )				,       2     ):
										iterlist[i] *= -1
								return iterlist



						def   __a				( self  :      str     ):

								"""simple docstring"""

								SCREAMING_SNAKE_CASE_							=       string.ascii_letters + string.digits
								SCREAMING_SNAKE_CASE_							=       [random.choice(snake_case__     ) for _ in range(random.randint(10				,       20     )     )]
								return password



						def   __a				( self  :      str     ):

								"""simple docstring"""

								SCREAMING_SNAKE_CASE_							=       (
								    string.ascii_letters + string.digits + string.punctuation + ' \t\n'
								)

								SCREAMING_SNAKE_CASE_							=       []

								# creates points known as breakpoints to break the key_list_options at those
								# points and pivot each substring
								SCREAMING_SNAKE_CASE_							=       sorted(set(self.__passcode     )     )
								SCREAMING_SNAKE_CASE_							=       []

								# algorithm for creating a new shuffled list, keys_l, out of key_list_options
								for i in key_list_options:
										temp_list.extend(snake_case__     )

										# checking breakpoints at which to pivot temporary sublist and add it into
										# keys_l
										if i in breakpoints or i == key_list_options[-1]:
												keys_l.extend(temp_list[::-1]     )
												temp_list.clear()

        # returning a shuffled keys_l to prevent brute force guessing of shift key
								return keys_l



						def   __a				( self  :      Union[str, Any]     ):

								"""simple docstring"""

								SCREAMING_SNAKE_CASE_							=       sum(self.__neg_pos([ord(snake_case__     ) for x in self.__passcode]     )     )
								return num if num > 0 else len(self.__passcode     )



						def   __a				( self  :      str				,       snake_case__  :      str     ):

								"""simple docstring"""

								SCREAMING_SNAKE_CASE_							=       ''

								# decoding shift like Caesar cipher algorithm implementing negative shift or
								# reverse shift or left shift
								for i in encoded_message:
										SCREAMING_SNAKE_CASE_							=       self.__key_list.index(snake_case__     )
										decoded_message += self.__key_list[
										    (position - self.__shift_key) % -len(self.__key_list     )
										]

								return decoded_message






						def   __a				( self  :      Optional[int]				,       snake_case__  :      str     ):

								"""simple docstring"""

								SCREAMING_SNAKE_CASE_							=       ''

								# encoding shift like Caesar cipher algorithm implementing positive shift or
								# forward shift or right shift
								for i in plaintext:
										SCREAMING_SNAKE_CASE_							=       self.__key_list.index(snake_case__     )
										encoded_message += self.__key_list[
										    (position + self.__shift_key) % len(self.__key_list     )
										]

								return encoded_message


def 				_a       (				lowerCAmelCase = "Hello, this is a modified Caesar cipher"   )->  str:
		SCREAMING_SNAKE_CASE_							=       ShuffledShiftCipher()
		return cipa.decrypt(cipa.encrypt(lowerCAmelCase   )   )


if __name__ == "__main__":
						import doctest

						doctest.testmod()