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.