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

糜烂的四月,最后一天,更新一些自己看到的小 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. go 基础 处理异常

    package main import "fmt" func main() { dosomething() } func dosomething(){ defer func() { ...

  2. 判断对象当中有没有某一个属性(AS,JS,Java语言比较)

    1.AS 首先说说AS里面如何判断,AS现在很少用这个语言了,当时我们公司的项目当中还有,所以就拿出来一块比较一下,代码如下: //利用Object属性判断 if("name" i ...

  3. 【转】zookeeper之 zkServer.sh命令、zkCli.sh命令、四字命令

    [FROM]https://www.cnblogs.com/andy6/p/7674028.html 一.zkServer.sh 1.查看 zkServer.sh 帮助信息 [root@bigdata ...

  4. 在Linux中使用minikube

    Minikebe Minikube是一个轻量级Kubernetes实现,它在本地机器上创建一个VM,并部署一个只包含一个节点的简单集群. Minikube使用Docker机器来管理Kubernetes ...

  5. sh脚本实战

    做了什么东西还是要尽快移动到博客上,不然回头看自己写的东西已经看不懂了... 凭着回忆+搜资料,把当初写sh脚本的过程写上来. 首先新建一个.sh文件,用vim就可以 在sh的第一行,写上 #!/bi ...

  6. go语言20小时从入门到精通(六、工程管理)

    在实际的开发工作中,直接调用编译器进行编译和链接的场景是少而又少,因为在工程中不会简单到只有一个源代码文件,且源文件之间会有相互的依赖关系.如果这样一个文件一个文件逐步编译,那不亚于一场灾难. Go语 ...

  7. HTML中Data的数据类型

    "data"类型的Url格式,是在RFC2397中提出的,目的对于一些“小”的数据,可以在网页中直接嵌入,而不是从外部文件载入. 例如对于img这个Tag,哪怕这个图片非常非常的小 ...

  8. 利用WatchService监控C盘根目录下的文件情况

    public static void main(String[] args) throws IOException, InterruptedException { WatchService watch ...

  9. cm_api

    cm API:https://github.com/cloudera/cm_api/tree/master/python/examples/auto-deploy#看集群有几个clustercurl ...

  10. nginx一些高级配置

    参数: https://www.wangbokun.com/%E8%BF%90%E7%BB%B4/2018/07/21/Nginx.html   免费证书等 1/ nginx代理hue限制上传文件大小 ...