javax_slr (javax_slr) wrote,
javax_slr
javax_slr

Скрипт генерирующий задания по простым дробям


Скрипт на груви, генерирует LaTex.

int n = 60 
def f1 = new File("d:\\temp\\ex.tex") 

///////////////////////////////////////////////////// 
 
def r = new Random(System.currentTimeMillis()) 
 
f1.delete(); 

 
def header = """ 
\\documentclass[a4paper,12pt,twocolumn]{article} 
\\begin{document} \n""" 
 
f1<< header 
f2<< header 
 
n.times { 
 
 def divisor1, divisor2, dividend1, dividend2, intPart1, intPart2;
  boolean sameOrNo = r.nextBoolean()
  if (sameOrNo) {
    divisor1 = r.nextInt(5) + 2 // 2..7
    int kefel =  r.nextInt(2) + 1 // 1..3
    divisor2 = kefel * divisor1 // 2 .. 21
  }
  else {
     divisor1 = r.nextInt(7) + 2 // 2..9   
     divisor2 = r.nextInt(7) + 2 // 2..9
  }
  
  dividend1 =  r.nextInt(14) + 1 // 1..15
  dividend2 =  r.nextInt(14) + 1 // 1..15
  
  intPart1 =  r.nextInt(6)  // 0..5
  intPart2 =  r.nextInt(6)  // 0..5
  
  boolean plus = r.nextBoolean() 
  
  def res1 = intPart1* (double) dividend1/divisor1
  def res2 = intPart2* (double) dividend2/divisor2
  
  if (res1<res2) {
   def t = intPart1; intPart1 = intPart2; intPart2 = t
   t =dividend1; dividend1 = dividend2; dividend2 = t
   t =divisor1; divisor1 = divisor2; divisor2 = t
   } 


  if (intPart1 == 0) { intPart1=' '}   
  if (intPart2 == 0) { intPart2=' '}   
 
  def sign = plus?"+":"-" 
 
  def s =  """\$\$ $intPart1 \\frac{$dividend1}{$divisor1} $sign $intPart2 \\frac{$dividend2}{$divisor2}  \$\$\n\n\n""" 
 println s;
 f1 <<s;
}  
def footer =  """ 
\\end{document} \n""" 
 
f1<<footer 

 


Tags: programming
Subscribe

  • Post a new comment

    Error

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.
  • 0 comments