Python hack string fault game implementation method

Source: Internet
Author: User
This article mainly introduces the implementation of the Python hack string fault game algorithm, a simple analysis of the principle of the game, and combined with specific examples of the implementation of Python to break the game of the relevant implementation skills, the need for friends can refer to the next

In this paper, we describe the algorithm of solving the puzzle of Python implementation. Share to everyone for your reference, as follows:

Recently found in a QQ group of that kind of robot, send a string to pick up the game:

Somewhat similar to:

No, no, no, no, no, no, no, no, no, no, no, no, no, no, no.
No, no, no, no, no, no, no, no, no, no, no, no, no, no, no.
No no no no no no no no no no no no no no no no no no no no no no no
No, no, no, no, no, no, no, no, no, no, no, no, no, no.
No, no, no, no, no, no, no, no, no, no, no, no, no, no, no.
No, no, no, no, no, no, no, no, no, no, no, no, no, no, no.

Play is the user sends messages to the group:


  #找茬

Then there was a robot with automatic chat, and after receiving the sentence, he would send a large pile of words to the group.

And then you can see that there's a "service" in it, and this time, you're sending


  #找茬 [Service]

This message to the group, the chat robot received your message will say: The answer is correct, or answer the error and so on.

Sometimes, looking for the word, the eyes looking at the flowers, the bother, I wrote a script in Python to deal with this:


#!/usr/bin/env python#-*-coding:utf-8-*-def char_diff (text):  text=text.replace (' \ n ', '). Replace (' \ R ', ')  Try:    text=text.decode (' gb18030 ', ' ignore ')  except:    try:      text=text.decode (' utf-8 ', ' ignore ')    except:      pass  d={} for  x in text:    d[x]=d.get (x,0) +1  lll= d.items ()  lll.sort (key = Lambda X:x[1])  return lll[0][0]if __name__ = = ' __main__ ': While  1:    text = raw_input (">"). Decode (' GB18030 ')    #print type (text)    if text in [' Q ', ' e ', ' exit ', ' Quit ', ' Bye ', U ' exit ']:      print ' bye! '      Break    print U ' #找茬 [%s] '% Char_diff (text)

The principle is simple, is to count the number of characters, return the least number of occurrences.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.