Guest User

steemit number extract

a guest
Jun 29th, 2017
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.24 KB | None | 0 0
  1. #!/usr/local/bin/python
  2. import re
  3.  
  4. '''
  5. Copyright 2017 profitgenerator
  6.  
  7. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
  8.  
  9. The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
  10.  
  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  12. '''
  13.  
  14. #------------------------------------------------------------------------------------------------
  15.  
  16. file_name="test"      # the name of the file containing the all the comments in one large text
  17. winner_number=4661     # the number that is the winner of the lottery
  18.  
  19.  
  20. f=open(file_name,"r") # read all the contents of the file into 1 string
  21. content = f.read()
  22. f.close()
  23.  
  24.  
  25. number_array=(re.findall('\d+', content )) # extract all numbers from the big text
  26. size=len(number_array)
  27. diffarray=[]
  28.  
  29.  
  30. for i in range(size):  # calculate the difference between the winner number and their guess
  31.  diffarray.append(abs(int(number_array[i])-winner_number))
  32.  
  33.  
  34. small_error= min(diffarray) # returns the smallest error guess
  35.  
  36.  
  37. for i in range(size):    # return the number from the player's guess that match that small error
  38.  if(diffarray[i]==small_error):
  39.   winner_guess=number_array[i]
  40.   break
  41.  
  42.  
  43. print "The winner guess is: "+winner_guess  # return the guess closest to the winner number
  44. print "---------------------------------------------------------------------"
  45. print "Now search for this number in your comment box and see who wrote it, that person is the winner"
Advertisement
Add Comment
Please, Sign In to add comment