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

糜烂的四月,最后一天,更新一些自己看到的小 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. js __proto__ 和prototype的联系

    1.Javascript中所有的对象都是Object的实例,并继承Object.prototype的属性和方法,也就是说,Object.prototype是所有对象的爸爸.(个人感觉搞清楚这一点很重要 ...

  2. Python之异常处理合集

    PermissionError: [Errno 13] Permission denied open(filePath)中的filePath是一目录路径,而非目录路径 先前打开的file文件对象未被关 ...

  3. 【D3D12学习手记】4.3.8 Create the Depth/Stencil Buffer and View

    我们现在需要创建深度/模板缓冲区. 如§4.1.5所述,深度缓冲区只是一个2D纹理,用于存储最近的可见对象的深度信息(如果使用模板(stencil),则也会存储模板信息). 纹理是一种GPU资源,因此 ...

  4. jmeter响应数据中文乱码处理

    1.在jmeter的bin目录下找到  jmeter.properties  文件并打开 2.搜索关键字 “default.encoding”,将1084行(以搜索到的位置为准)改成下图所示:samp ...

  5. uni-app编译配置

    Uni-app 编译配置 <!-- #ifdef H5 --> <view>只在H5编译</view> <!-- #endif --> <!-- ...

  6. Leetcode之广度优先搜索(BFS)专题-529. 扫雷游戏(Minesweeper)

    Leetcode之广度优先搜索(BFS)专题-529. 扫雷游戏(Minesweeper) BFS入门详解:Leetcode之广度优先搜索(BFS)专题-429. N叉树的层序遍历(N-ary Tre ...

  7. DFS(深度优先搜索)和BFS(广度优先搜索)

    深度优先搜索算法(Depth-First-Search) 深度优先搜索算法(Depth-First-Search),是搜索算法的一种. 它沿着树的深度遍历树的节点,尽可能深的搜索树的分支. 当节点v的 ...

  8. 纯css实现单选框样式

    html代码 <h2>你最喜欢的水果</h2> <div class="input-radio"> <!-- 选中状态添加 checked ...

  9. cp 命令

    cp - copy files and directories 用法: cp [OPTION] source dest DESCRIPTION Copy SOURCE to DEST, or mult ...

  10. SIFT图像配准 python3.6 + opencv3.3代码

    opencv3.x 中部分函数有改变: 1. SIFT:可以采用help(cv2.xfeatures2d)查询 2.drawKeypoints: 同样采用help()方法查询 opencv3 版本si ...