一直都计划好好学算法,一直都计划好好看书刷题,却几乎从来没更新过(算法)博客,几乎从来没有花苦功夫学过。

糜烂的四月,最后一天,更新一些自己看到的小 trick 吧,以后一定要多多更新算法博客。

1. 一道小学三年级的数学题:

【题目】:5□5□5□5□5=1
每个方框中都可选择填入+-×÷,不能添加括号,使得上式成立。

>>> from itertools import product
>>> [x for x in product(['', '+', '-', '*', '/'], repeat = 4) if eval('5%s5%s5%s5%s5' % x) == 1]
[('', '/', '-', '-')]

2. 不用 loop or library funtion 实现 list 的求和。

sum_t = 0
L = range(10)
def plus(x):
global sum_t
sum_t += x
return sum_t
print(list(map(plus, L))[-1])
from functools import reduce
L = range(20)
reduce(lambda x, y : x + [x[-1] + y], L, [0])[-1]
def cumsum(L):
if L[ : -1] == []:
return L
ret = cumsum(L[ : -1])
ret.append(ret[-1] + L[-1])
return ret

3. C++ 10行内实现八皇后。

Little Tricks的更多相关文章

  1. testng 教程之使用参数的一些tricks配合使用reportng

    前两次的总结:testng annotation生命周期 http://www.cnblogs.com/tobecrazy/p/4579414.html testng.xml的使用和基本配置http: ...

  2. (转) How to Train a GAN? Tips and tricks to make GANs work

    How to Train a GAN? Tips and tricks to make GANs work 转自:https://github.com/soumith/ganhacks While r ...

  3. Matlab tips and tricks

    matlab tips and tricks and ... page overview: I created this page as a vectorization helper but it g ...

  4. LoadRunner AJAX TruClient协议Tips and Tricks

    LoadRunner AJAX TruClient协议Tips and Trickshttp://automationqa.com/forum.php?mod=viewthread&tid=2 ...

  5. 【翻译】C# Tips & Tricks: Weak References - When and How to Use Them

    原文:C# Tips & Tricks: Weak References - When and How to Use Them Sometimes you have an object whi ...

  6. 神经网络训练中的Tricks之高效BP(反向传播算法)

    神经网络训练中的Tricks之高效BP(反向传播算法) 神经网络训练中的Tricks之高效BP(反向传播算法) zouxy09@qq.com http://blog.csdn.net/zouxy09 ...

  7. Hex-Rays Decompiler Tips and tricks Volatile memory

    https://www.hex-rays.com/products/decompiler/manual/tricks.shtml First of all, read the troubleshoot ...

  8. hdu 5276 YJC tricks time 数学

    YJC tricks time Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?p ...

  9. 10 Interesting Linux Command Line Tricks and Tips Worth Knowing

    I passionately enjoy working with commands as they offer more control over a Linux system than GUIs( ...

  10. Git tricks: Unstaging files

    NOTE: Following content is directly reprinted from http://andrewberls.com/blog/post/git-tricks-unsta ...

随机推荐

  1. Eclipse 设置护眼背景色

    Eclipse 设置护眼背景色 1.设置字体大小 Window --> Preferences --> General --> Apprearance --> Colors a ...

  2. Mac搭建学习PHP环境

    在sublime text 3中学习PHP,编写PHP代码: 使用的xampp开发环境: 第一步,就是安装xampp,这个没啥可说的,根据自己的系统下载安装就好,我的是OSX;第二步,就是用XAMPP ...

  3. vs2008,windows mobile 6 搭建PDA开发环境相关软件下载

    1.Windows Mobile 6.5 Professional Developer Tool Kit (CHS).msi 下载地址:https://download.microsoft.com/d ...

  4. 刷新页面后,让控制台的js代码继续执行

    在各种限时,秒杀活动中,有个自动循环的点击的工具是很重要的. 为了方便起见,我们把Js代码放在浏览器的控制台执行,但是刷新页面后,js代码就清空了,也就无法执行. 可以用js代码实现一个不受页面刷新影 ...

  5. C#编程 socket编程之TcpClient,TcpListener,UdpClient

    应用程序可以通过 TCPClient.TCPListener 和 UDPClient 类使用传输控制协议 (TCP) 和用户数据文报协议 (UDP) 服务.这些协议类建立在 System.Net.So ...

  6. Java通过字节分割字符串

    一.题目描述: 一道Java笔试题.将字符串按给定的字节数进行分割,输出分割后的字符串.要求汉字不能进行拆分,如“a中国”不能拆分成“a+中的一半”. 二.解题思路: 首先利用String类的subs ...

  7. 【miscellaneous】最新HEVC/H.265 4K视频,显卡解码测试

    转载自:http://bbs.zol.com.cn/diybbs/d34441_76103.html 4K这个概念也在最近几年开始流行了起来,无论是4K显示器.4K电视盒子,还是4K游戏对硬件的要求也 ...

  8. 【Linux开发】linux设备驱动归纳总结(三):7.异步通知fasync

    linux设备驱动归纳总结(三):7.异步通知fasync xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ...

  9. 用vs2008打开sln项目总是说没有对应的,打不开vs2008的工程文件提示不支持项目类型(.csproj)

    找了很多解决办法都搞不定,最后找了个老司机问了一下,原来是组件没有安装完整!!!只是安装了个vs2008的外壳...下次先检查开发工具是否完整!下载安装包安装vs再说吧!

  10. Linux里添加用户的一些简单命令

    普通用户---------普通用户对应提示符$ 超级用户-----------超级用户对应提示符# 1.添加用户:useradd diqi 2.查看用户:tail -1 /etc/passwd 3.设 ...