A PHP Error was encountered

Severity: 8192

Message: Function create_function() is deprecated

Filename: geshi/geshi.php

Line Number: 4698

Backtrace:

File: /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/application/libraries/geshi/geshi.php
Line: 4698
Function: _error_handler

File: /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/application/libraries/geshi/geshi.php
Line: 4621
Function: _optimize_regexp_list_tokens_to_string

File: /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/application/libraries/geshi/geshi.php
Line: 1655
Function: optimize_regexp_list

File: /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/application/libraries/geshi/geshi.php
Line: 2029
Function: optimize_keyword_group

File: /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/application/libraries/geshi/geshi.php
Line: 2168
Function: build_parse_cache

File: /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/application/libraries/Process.php
Line: 45
Function: parse_code

File: /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/application/models/Pastes.php
Line: 517
Function: syntax

File: /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/application/controllers/Main.php
Line: 693
Function: getPaste

File: /home/httpd/vhosts/scratchbook.ch/geopaste.scratchbook.ch/index.php
Line: 315
Function: require_once

Ruby - Stikked
From Bistre Motmot, 13 Years ago, written in Ruby.
This paste is a reply to Codemirror test from Gracious Treeshrew - view diff
Embed
  1. # Code from http://sandbox.mc.edu/~bennet/ruby/code/poly_rb.html
  2. #
  3. # This program evaluates polynomials.  It first asks for the coefficients
  4. # of a polynomial, which must be entered on one line, highest-order first.
  5. # It then requests values of x and will compute the value of the poly for
  6. # each x.  It will repeatly ask for x values, unless you the user enters
  7. # a blank line.  It that case, it will ask for another polynomial.  If the
  8. # user types quit for either input, the program immediately exits.
  9. #
  10.  
  11. #
  12. # Function to evaluate a polynomial at x.  The polynomial is given
  13. # as a list of coefficients, from the greatest to the least.
  14. def polyval(x, coef)
  15.     sum = 0
  16.     coef = coef.clone           # Don't want to destroy the original
  17.     while true
  18.         sum += coef.shift       # Add and remove the next coef
  19.         break if coef.empty?    # If no more, done entirely.
  20.         sum *= x                # This happens the right number of times.
  21.     end
  22.     return sum
  23. end
  24.  
  25. #
  26. # Function to read a line containing a list of integers and return
  27. # them as an array of integers.  If the string conversion fails, it
  28. # throws TypeError.  If the input line is the word 'quit', then it
  29. # converts it to an end-of-file exception
  30. def readints(prompt)
  31.     # Read a line
  32.     print prompt
  33.     line = readline.chomp
  34.     raise EOFError.new if line == 'quit' # You can also use a real EOF.
  35.            
  36.     # Go through each item on the line, converting each one and adding it
  37.     # to retval.
  38.     retval = [ ]
  39.     for str in line.split(/\s+/)
  40.         if str =~ /^\-?\d+$/
  41.             retval.push(str.to_i)
  42.         else
  43.             raise TypeError.new
  44.         end
  45.     end
  46.  
  47.     return retval
  48. end
  49.  
  50. #
  51. # Take a coeff and an exponent and return the string representation, ignoring
  52. # the sign of the coefficient.
  53. def term_to_str(coef, exp)
  54.     ret = ""
  55.  
  56.     # Show coeff, unless it's 1 or at the right
  57.     coef = coef.abs
  58.     ret = coef.to_s     unless coef == 1 && exp > 0
  59.     ret += "x" if exp > 0                               # x if exponent not 0
  60.     ret += "^" + exp.to_s if exp > 1                    # ^exponent, if > 1.
  61.  
  62.     return ret
  63. end
  64.  
  65. #
  66. # Create a string of the polynomial in sort-of-readable form.
  67. def polystr(p)
  68.     # Get the exponent of first coefficient, plus 1.
  69.     exp = p.length
  70.  
  71.     # Assign exponents to each term, making pairs of coeff and exponent,
  72.     # Then get rid of the zero terms.
  73.     p = (p.map { |c| exp -= 1; [ c, exp ] }).select { |p| p[0] != 0 }
  74.  
  75.     # If there's nothing left, it's a zero
  76.     return "0" if p.empty?
  77.  
  78.     # *** Now p is a non-empty list of [ coef, exponent ] pairs. ***
  79.  
  80.     # Convert the first term, preceded by a "-" if it's negative.
  81.     result = (if p[0][0] < 0 then "-" else "" end) + term_to_str(*p[0])
  82.  
  83.     # Convert the rest of the terms, in each case adding the appropriate
  84.     # + or - separating them.  
  85.     for term in p[1...p.length]
  86.         # Add the separator then the rep. of the term.
  87.         result += (if term[0] < 0 then " - " else " + " end) +
  88.                 term_to_str(*term)
  89.     end
  90.  
  91.     return result
  92. end
  93.        
  94. #
  95. # Run until some kind of endfile.
  96. begin
  97.     # Repeat until an exception or quit gets us out.
  98.     while true
  99.         # Read a poly until it works.  An EOF will except out of the
  100.         # program.
  101.         print "\n"
  102.         begin
  103.             poly = readints("Enter a polynomial coefficients: ")
  104.         rescue TypeError
  105.             print "Try again.\n"
  106.             retry
  107.         end
  108.         break if poly.empty?
  109.  
  110.         # Read and evaluate x values until the user types a blank line.
  111.         # Again, an EOF will except out of the pgm.
  112.         while true
  113.             # Request an integer.
  114.             print "Enter x value or blank line: "
  115.             x = readline.chomp
  116.             break if x == ''
  117.             raise EOFError.new if x == 'quit'
  118.  
  119.             # If it looks bad, let's try again.
  120.             if x !~ /^\-?\d+$/
  121.                 print "That doesn't look like an integer.  Please try again.\n"
  122.                 next
  123.             end
  124.  
  125.             # Convert to an integer and print the result.
  126.             x = x.to_i
  127.             print "p(x) = ", polystr(poly), "\n"
  128.             print "p(", x, ") = ", polyval(x, poly), "\n"
  129.         end
  130.     end
  131. rescue EOFError
  132.     print "\n=== EOF ===\n"
  133. rescue Interrupt, SignalException
  134.     print "\n=== Interrupted ===\n"
  135. else
  136.     print "--- Bye ---\n"
  137. end
  138.