Interview _python. General Algorithm. 0001. Fill in the 1~8 numbers in the circle and the Box.

Source: Internet
Author: User

Interview Topics:

650) this.width=650; "src=" http://s5.51cto.com/wyfs02/M02/8B/F7/wKioL1heDiqAAWRIAAC6xlnKOHo915.jpg "title=" tm.jpg "alt=" wkiol1hediqaawriaac6xlnkoho915.jpg "/>

Problem solving Ideas:

1. A total of 8 positions, as long as 2 circle difference is equal to the box, note that the last 3rd number and the 1th number is the end of the operation, so you can first generate permutations and then through the Shard offset to obtain the results of the matching CRITERIA.


Specific implementation:

#!/usr/bin/env python# -*- coding: utf-8 -*-#  @Date     :  2016-12-24 12:19:01#  @Author   :  li   ([email protected]) #  @Link     : http://xmdevops.blog.51cto.com/#  @Version  :  $Id $from __ future__ import absolute_import#  description:  Import Public module import pprintimport itertools#  description:  Import other modules def calculation (max_num):    result = []     combinations = itertools.permutations (        xrange (1 ,  max_num + 1),        max_num    )     for item in combinations:         flag = true        for index in range (0 ,  max_num, 2): &NBsp;           x = item[index]             y = item[index + 1]             z = item[0] if index  == max_num - 2 else item[index + 2]             if abs (z - x)  != y:                 flag = False                 break         if flag:             result.append (item)     return resultif __name__ ==  ' __main__ ':     result = calculation (8)     pprint.pprint (result) 


This article is from the "li-yun development road" blog, Please be sure to keep this source http://xmdevops.blog.51cto.com/11144840/1885736

Interview _python. General Algorithm. 0001. Fill in the 1~8 numbers in the circle and the Box.

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.