def write_analogy(pars, description, file):
  """
  Write analogies to file
  :param pars: list of elements necessary to generate analogies
  :param description: string describing the analogy category
  :param file: file to print to
  :return: number of printed analogies
  """
  # Helper variables for printing format
  line = "{}\n{}\n{}\n{}\n\n"

  # Get analogy parameters
  var_a, var_b, var_x, var_y, num_ops, template = pars

  # Print to file
  with open(file, "a") as f:
    f.write("\n\n# " + description + ": " + str(num_ops) + "\n\n")
    for i in range(num_ops):
      f.write(
        line.format(
          template.render(var_a[i]),
          template.render(var_b[i]),
          template.render(var_x[i]),
          template.render(var_y[i]),
        )
      )

  # Free memory
  del var_a, var_b, var_x, var_y, template, pars

  # Return number of generated analogies
  return num_ops