prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Generating invalid cpf (brazillian ssn)
  Faker is generating invalid checksum digits for cpf (brazillian ssn).
  
  ### Steps to reproduce
  
  1. Create fake instance using localization "pt_BR"
  1. Call fake.cpf()
  
  ### Expected behavior
  
  It should generate a valid CPF.
  
  ### Actual behavior
  
  It is generating a CPF with invalid checksum digits, in some cases.
  
  
  </issue>
  <code>
  [start of faker/providers/ssn/pt_BR/__init__.py]
  1 #  -*- coding: utf-8 -*-
  2 
  3 from __future__ import unicode_literals
  4 from .. import Provider as SsnProvider
  5 
  6 
  7 def checksum(digits):
  8     s = 0
  9     p = len(digits) + 1
  10     for i in range(0, len(digits)):
  11         s += digits[i] * p
  12         p -= 1
  13 
  14     reminder = s % 11
  15     if reminder == 0 or reminder == 1:
  16         return 1
  17     else:
  18         return 11 - reminder
  19 
  20 
  21 class Provider(SsnProvider):
  22     """
  23     Provider for Brazilian SSN also known in Brazil as CPF.
  24     There are two methods Provider.ssn and Provider.cpf
  25     The snn returns a valid number with numbers only
  26     The cpf return a valid number formatted with brazilian mask. eg nnn.nnn.nnn-nn
  27     """
  28 
  29     def ssn(self):
  30         digits = self.generator.random.sample(range(10), 9)
  31 
  32         dv = checksum(digits)
  33         digits.append(dv)
  34         digits.append(checksum(digits))
  35 
  36         return ''.join(map(str, digits))
  37 
  38     def cpf(self):
  39         c = self.ssn()
  40         return c[:3] + '.' + c[3:6] + '.' + c[6:9] + '-' + c[9:]
  41
  [end of faker/providers/ssn/pt_BR/__init__.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/faker/providers/ssn/pt_BR/__init__.py b/faker/providers/ssn/pt_BR/__init__.py
  --- a/faker/providers/ssn/pt_BR/__init__.py
  +++ b/faker/providers/ssn/pt_BR/__init__.py
  @@ -5,6 +5,12 @@
   
   
   def checksum(digits):
  +    """
  +    Returns the checksum of CPF digits.
  +    References to the algorithm:
  +    https://pt.wikipedia.org/wiki/Cadastro_de_pessoas_f%C3%ADsicas#Algoritmo
  +    https://metacpan.org/source/MAMAWE/Algorithm-CheckDigits-v1.3.0/lib/Algorithm/CheckDigits/M11_004.pm
  +    """
       s = 0
       p = len(digits) + 1
       for i in range(0, len(digits)):
  @@ -13,7 +19,7 @@
   
       reminder = s % 11
       if reminder == 0 or reminder == 1:
  -        return 1
  +        return 0
       else:
           return 11 - reminder
  
verification_info: {"golden_diff": "diff --git a/faker/providers/ssn/pt_BR/__init__.py b/faker/providers/ssn/pt_BR/__init__.py\n--- a/faker/providers/ssn/pt_BR/__init__.py\n+++ b/faker/providers/ssn/pt_BR/__init__.py\n@@ -5,6 +5,12 @@\n \n \n def checksum(digits):\n+    \"\"\"\n+    Returns the checksum of CPF digits.\n+    References to the algorithm:\n+    https://pt.wikipedia.org/wiki/Cadastro_de_pessoas_f%C3%ADsicas#Algoritmo\n+    https://metacpan.org/source/MAMAWE/Algorithm-CheckDigits-v1.3.0/lib/Algorithm/CheckDigits/M11_004.pm\n+    \"\"\"\n     s = 0\n     p = len(digits) + 1\n     for i in range(0, len(digits)):\n@@ -13,7 +19,7 @@\n \n     reminder = s % 11\n     if reminder == 0 or reminder == 1:\n-        return 1\n+        return 0\n     else:\n         return 11 - reminder\n", "issue": "Generating invalid cpf (brazillian ssn)\nFaker is generating invalid checksum digits for cpf (brazillian ssn).\r\n\r\n### Steps to reproduce\r\n\r\n1. Create fake instance using localization \"pt_BR\"\r\n1. Call fake.cpf()\r\n\r\n### Expected behavior\r\n\r\nIt should generate a valid CPF.\r\n\r\n### Actual behavior\r\n\r\nIt is generating a CPF with invalid checksum digits, in some cases.\r\n\n", "before_files": [{"content": "#  -*- coding: utf-8 -*-\n\nfrom __future__ import unicode_literals\nfrom .. import Provider as SsnProvider\n\n\ndef checksum(digits):\n    s = 0\n    p = len(digits) + 1\n    for i in range(0, len(digits)):\n        s += digits[i] * p\n        p -= 1\n\n    reminder = s % 11\n    if reminder == 0 or reminder == 1:\n        return 1\n    else:\n        return 11 - reminder\n\n\nclass Provider(SsnProvider):\n    \"\"\"\n    Provider for Brazilian SSN also known in Brazil as CPF.\n    There are two methods Provider.ssn and Provider.cpf\n    The snn returns a valid number with numbers only\n    The cpf return a valid number formatted with brazilian mask. eg nnn.nnn.nnn-nn\n    \"\"\"\n\n    def ssn(self):\n        digits = self.generator.random.sample(range(10), 9)\n\n        dv = checksum(digits)\n        digits.append(dv)\n        digits.append(checksum(digits))\n\n        return ''.join(map(str, digits))\n\n    def cpf(self):\n        c = self.ssn()\n        return c[:3] + '.' + c[3:6] + '.' + c[6:9] + '-' + c[9:]\n", "path": "faker/providers/ssn/pt_BR/__init__.py"}]}