





import math_equivalence  # From: git+https://github.com/hendrycks/math.git

import datasets


__lowerCamelCase       :     Optional[Any]   =     '\\n@article{hendrycksmath2021,\n  title={Measuring Mathematical Problem Solving With the MATH Dataset},\n  author={Dan Hendrycks\n    and Collin Burns\n    and Saurav Kadavath\n    and Akul Arora\n    and Steven Basart\n    and Eric Tang\n    and Dawn Song\n    and Jacob Steinhardt},\n  journal={arXiv preprint arXiv:2103.03874},\n  year={2021}\n}\n'


__lowerCamelCase       :     Union[str, Any]   =     '\\nThis metric is used to assess performance on the Mathematics Aptitude Test of Heuristics (MATH) dataset.\nIt first canonicalizes the inputs (e.g., converting "1/2" to "\\frac{1}{2}") and then computes accuracy.\n'


__lowerCamelCase       :     List[Any]   =     r'\nCalculates accuracy after canonicalizing inputs.\n\nArgs:\n    predictions: list of predictions to score. Each prediction\n        is a string that contains natural language and LaTex.\n    references: list of reference for each prediction. Each\n        reference is a string that contains natural language\n        and LaTex.\nReturns:\n    accuracy: accuracy after canonicalizing inputs\n        (e.g., converting "1/2" to "\\frac{1}{2}")\n\nExamples:\n    >>> metric = datasets.load_metric("competition_math")\n    >>> results = metric.compute(references=["\\frac{1}{2}"], predictions=["1/2"])\n    >>> print(results)\n    {\'accuracy\': 1.0}\n'



@datasets.utils.file_utils.add_end_docstrings(_DESCRIPTION       ,   _KWARGS_DESCRIPTION			)
class 					A__   (       datasets.Metric			):





      def        __UpperCamelCase( self   ):
       '''simple docstring'''




       return datasets.MetricInfo(
           description=_DESCRIPTION       ,							citation=_CITATION       ,							inputs_description=_KWARGS_DESCRIPTION       ,							features=datasets.Features(
               {
                   "predictions": datasets.Value("string"   ),
                   "references": datasets.Value("string"   ),
               }   )       ,							homepage="https://github.com/hendrycks/math"       ,							codebase_urls=["https://github.com/hendrycks/math"]       ,							)





      def        __UpperCamelCase( self       ,							A_       ,							A_   ):
       '''simple docstring'''




       UpperCamelCase	:					int       	=   0.0
       for i, j in zip(__a       ,							__a   ):
        n_correct += 1.0 if math_equivalence.is_equiv(__a       ,							__a   ) else 0.0
       UpperCamelCase	:					Optional[Any]       	=   n_correct / len(__a   )
       return {
           "accuracy": accuracy,
       }

'''simple docstring'''





from multiprocessing import Lock, Pipe, Process

# lock used to ensure that two processes do not access a pipe at the same time
SCREAMING_SNAKE_CASE_:     Optional[int]  =Lock()





def 	lowerCAmelCase_				(					snake_case_       : Dict					,    snake_case_       : Dict					,    snake_case_       : Optional[int]					,    snake_case_       : Tuple					,    snake_case_       : Any					,    snake_case_       : Optional[Any]					,    snake_case_       : Union[str, Any]			)    ->      Optional[Any]:


     '''simple docstring'''




     global process_lock

     # we perform n swaps since after n swaps we know we are sorted
     # we *could* stop early if we are sorted already, but it takes as long to
     # find out we are sorted as it does to sort the list with this algorithm
     for i in range(0					,    10			):
          if (i + position) % 2 == 0 and r_send is not None:
               # send your value to your right neighbor
               process_lock.acquire()
               r_send[1].send(snake_case_			)
               process_lock.release()

               # receive your right neighbor's value
               process_lock.acquire()
               UpperCAmelCase_           =   rr_cv[0].recv()
               process_lock.release()

               # take the lower value since you are on the left
               UpperCAmelCase_           =   min(snake_case_					,    snake_case_			)
          elif (i + position) % 2 != 0 and l_send is not None:
               # send your value to your left neighbor
               process_lock.acquire()
               l_send[1].send(snake_case_			)
               process_lock.release()

               # receive your left neighbor's value
               process_lock.acquire()
               UpperCAmelCase_           =   lr_cv[0].recv()
               process_lock.release()

               # take the higher value since you are on the right
               UpperCAmelCase_           =   max(snake_case_					,    snake_case_			)
    # after all swaps are performed, send the values back to main
     result_pipe[1].send(snake_case_			)





def 	lowerCAmelCase_				(					snake_case_       : Optional[Any]			)    ->      Dict:


     '''simple docstring'''




     UpperCAmelCase_           =   []
     UpperCAmelCase_           =   []
     # initialize the list of pipes where the values will be retrieved
     for _ in arr:
          result_pipe.append(Pipe()			)
     # creates the processes
     # the first and last process only have one neighbor so they are made outside
     # of the loop
     UpperCAmelCase_           =   Pipe()
     UpperCAmelCase_           =   Pipe()
     process_array_.append(
         Process(
             target=snake_case_					,    args=(0, arr[0], None, temp_rs, None, temp_rr, result_pipe[0])					,    )			)
     UpperCAmelCase_           =   temp_rs
     UpperCAmelCase_           =   temp_rr

     for i in range(1					,    len(snake_case_			) - 1			):
          UpperCAmelCase_           =   Pipe()
          UpperCAmelCase_           =   Pipe()
          process_array_.append(
              Process(
                  target=snake_case_					,    args=(i, arr[i], temp_ls, temp_rs, temp_lr, temp_rr, result_pipe[i])					,    )			)
          UpperCAmelCase_           =   temp_rs
          UpperCAmelCase_           =   temp_rr

     process_array_.append(
         Process(
             target=snake_case_					,    args=(
                 len(snake_case_			) - 1,
                 arr[len(snake_case_			) - 1],
                 temp_ls,
                 None,
                 temp_lr,
                 None,
                 result_pipe[len(snake_case_			) - 1],
             )					,    )			)

     # start the processes
     for p in process_array_:
          p.start()

     # wait for the processes to end and write their values to the list
     for p in range(0					,    len(snake_case_			)			):
          UpperCAmelCase_           =   result_pipe[p][0].recv()
          process_array_[p].join()
     return arr





def 	lowerCAmelCase_				(					)    ->      str:


     '''simple docstring'''




     UpperCAmelCase_           =   list(range(10					,    0					,    -1			)			)
     print("Initial List"			)
     print(*snake_case_			)
     UpperCAmelCase_           =   odd_even_transposition(snake_case_			)
     print("Sorted List\n"			)
     print(*snake_case_			)


if __name__ == "__main__":
    main()




