Write a script to check an interesting game 6174
# -*- coding: utf-8 -*-
#from ftplib import FTP
import os
def sort_reverse(x,y):
if x>y:
return -1
if x<y:
return 1
else:
return 0
def play6174(num):
a=num/1000
b=(num-a*1000)/100
c=(num-a*1000-b*100)/10
d=(num-a*1000-b*100-c*10)
a=num/1000
b=(num-a*1000)/100
c=(num-a*1000-b*100)/10
d=(num-a*1000-b*100-c*10)
list1=[a,b,c,d]
listmin=sorted(list1)
listmax=sorted(list1,sort_reverse)
max=listmax[0]*1000+listmax[1]*100+listmax[2]*10+listmax[3]
min=listmin[0]*1000+listmin[1]*100+listmin[2]*10+listmin[3]
str1=str(max)+'-'+str(min)+'='+str(max-min)
print str1
f.write(str1+'\n')
return max-min
if __name__=='__main__':
#num=int(raw_input('Just put in a number (1000~9999):'))
f=open(r'C:\Users\cchen\Desktop\result.txt','w')
for j in range(1000,10000):
print j
f.write(str(j)+'\n')
if j%1111!=0:
loop=j
i=0
while(loop!=6174):
loop=play6174(loop)
i+=1
str2='Caculate for '+str(i)+'times.'
f.write(str2+'\n')
f.write('+++++++++++++++++++++++++++++++\n')
print str2
print '+++++++++++++++++++++++++++++++\n'
f.close()
Write a script to check an interesting game 6174的更多相关文章
- (copy) Shell Script to Check Linux System Health
source: http://linoxide.com/linux-shell-script/shell-script-check-linux-system-health/ This article ...
- A python script to check NE syncfail and get log from CIPS
#! /usr/bin/env python # -*- coding: UTF-8 -*- """The script is to check whether NE i ...
- An enhance script to check partition tables under all schemas in sqlserver
Simple step for EMC NW & NMM (1) disable WINDOWS UAC (reboot)(2) SET windows domain user AS sysa ...
- 课上练习 script
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- sqlserver check running process 1
check process script 1, check which is current running: use master SELECTspid,ER.percent_complete,CA ...
- DTrace to Troubleshoot Java Native Memory Problems
How to Use DTrace to Troubleshoot Java Native Memory Problems on Oracle Solaris 11 Hands-On Labs of ...
- Git详解之四:服务器上的Git
服务器上的 Git 到目前为止,你应该已经学会了使用 Git 来完成日常工作.然而,如果想与他人合作,还需要一个远程的 Git 仓库.尽管技术上可以从个人的仓库里推送和拉取修改内容,但我们不鼓励这样做 ...
- Git详解之四 服务器上的Git
以下内容转载自:http://www.open-open.com/lib/view/open1328069988843.html 服务器上的 Git 到目前为止,你应该已经学会了使用 Git 来完成日 ...
- [转]Git详解之四 服务器上的Git
服务器上的 Git 到目前为止,你应该已经学会了使用 Git 来完成日常工作.然而,如果想与他人合作,还需要一个远程的 Git 仓库.尽管技术上可以从个人的仓库里推送和拉取修改内容,但我们不鼓励这样做 ...
随机推荐
- c 头文件<ctype.h>(二)
测试<ctype.h>函数 #include <stdio.h> #include <ctype.h> int main(){ ; ; i < ; ++i){ ...
- 把汉字转换为html实体编码
背景:工作中需要把汉字转换为html实体编码实现方式:import org.apache.commons.lang.StringEscapeUtils;public static void main( ...
- html5 webDatabase 存储中sql语句执行可嵌套使用
html5 webDatabase 存储中sql语句执行可嵌套使用,代码如下: *); data.transaction(function(tx){ tx.executeSql("creat ...
- Python多重装饰器
多重装饰器,即多个装饰器修饰同一个对象[实际上并非完全如此,且看下文详解] 1.装饰器无参数: >>> def first(func): print '%s() was post t ...
- 几个js函数
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...
- mvc api 返回json
GlobalConfiguration.Configuration.Formatters.XmlFormatter.SupportedMediaTypes.Clear(); }
- 求android ble 解决方案!
智能医疗的产品,求ble解决方案:整体结构如下: 名词定义: 盒子:基于android4.3或以上版本的硬件,需支持wifi.ble 手机:android/ios 手机,用户使用 服务器:云服务器,盒 ...
- java第二次作业
这次通过学习,我掌握了下拉菜单和单选按钮的使用下拉菜单构造方法:JComboBox() 创建具有默认数据模型的 JComboBox.JComboBox(ComboBoxModel aModel) 创建 ...
- SVN Client
https://ctf.open.collab.net/svn/repos/ankhsvn/trunk/src/ https://ctf.open.collab.net/svn/repos/sharp ...
- 突袭HTML5之WebGL 3D概述
WebGL开启了网页3D渲染的新时代,它允许在canvas中直接渲染3D的内容,而不借助任何插件.WebGL同canvas 2D的API一样,都是通过脚本操纵对象,所以步骤也是基本相似:准备工作上下文 ...