






from __future__ import annotations

from collections import Counter
from random import random







class 	_UpperCAmelCase  :




      """simple docstring"""



      def __init__(   self		):



          '''simple docstring'''
          lowerCAmelCase__   :int      							=				{}
      def 			snake_case_      (   self    ,	_lowerCAmelCase		):



          '''simple docstring'''
          lowerCAmelCase__   :Dict      							=				{}
      def 			snake_case_      (   self    ,	_lowerCAmelCase    ,	_lowerCAmelCase    ,	_lowerCAmelCase		):



          '''simple docstring'''
          if nodea not in self.connections:
              self.add_node(_lowerCAmelCase		)
          if nodea not in self.connections:
              self.add_node(_lowerCAmelCase		)
          lowerCAmelCase__   :str      							=				probability
      def 			snake_case_      (   self		):



          '''simple docstring'''
          return list(self.connections		)



      def 			snake_case_      (   self    ,	_lowerCAmelCase		):



          '''simple docstring'''
          lowerCAmelCase__   :Tuple      							=				0
          lowerCAmelCase__   :int      							=				random()

          for dest in self.connections[node]:
              current_probability += self.connections[node][dest]
              if current_probability > random_value:
                  return dest
          return ""





def 				snake_case__							(							UpperCAmelCase							:  str    ,			UpperCAmelCase							:  list[tuple[str, str, float]]    ,			UpperCAmelCase							:  int       ):
    lowerCAmelCase__   :List[Any]      							=				MarkovChainGraphUndirectedUnweighted()

    for nodea, nodea, probability in transitions:
        graph.add_transition_probability(UpperCAmelCase    ,			UpperCAmelCase    ,			UpperCAmelCase       )

    lowerCAmelCase__   :Optional[int]      							=				Counter(graph.get_nodes()       )
    lowerCAmelCase__   :Optional[Any]      							=				start

    for _ in range(UpperCAmelCase       ):
        lowerCAmelCase__   :List[str]      							=				graph.transition(UpperCAmelCase       )
        visited[node] += 1

    return visited


if __name__ == "__main__":
 import doctest

 doctest.testmod()











def 				snake_case__							(							UpperCAmelCase							:  float    ,			UpperCAmelCase							:  list[float]       ):
    if discount_rate < 0:
        raise ValueError("Discount rate cannot be negative"       )
    if not cash_flows:
        raise ValueError("Cash flows list cannot be empty"       )
    lowerCAmelCase__   :List[Any]      							=				sum(
        cash_flow / ((1 + discount_rate) ** i) for i, cash_flow in enumerate(UpperCAmelCase       )       )
    return round(UpperCAmelCase    ,			ndigits=2       )


if __name__ == "__main__":
 import doctest

 doctest.testmod()



