Little Tricks
一直都计划好好学算法,一直都计划好好看书刷题,却几乎从来没更新过(算法)博客,几乎从来没有花苦功夫学过。
糜烂的四月,最后一天,更新一些自己看到的小 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的更多相关文章
- testng 教程之使用参数的一些tricks配合使用reportng
前两次的总结:testng annotation生命周期 http://www.cnblogs.com/tobecrazy/p/4579414.html testng.xml的使用和基本配置http: ...
- (转) 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 ...
- Matlab tips and tricks
matlab tips and tricks and ... page overview: I created this page as a vectorization helper but it g ...
- LoadRunner AJAX TruClient协议Tips and Tricks
LoadRunner AJAX TruClient协议Tips and Trickshttp://automationqa.com/forum.php?mod=viewthread&tid=2 ...
- 【翻译】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 ...
- 神经网络训练中的Tricks之高效BP(反向传播算法)
神经网络训练中的Tricks之高效BP(反向传播算法) 神经网络训练中的Tricks之高效BP(反向传播算法) zouxy09@qq.com http://blog.csdn.net/zouxy09 ...
- Hex-Rays Decompiler Tips and tricks Volatile memory
https://www.hex-rays.com/products/decompiler/manual/tricks.shtml First of all, read the troubleshoot ...
- hdu 5276 YJC tricks time 数学
YJC tricks time Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?p ...
- 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( ...
- Git tricks: Unstaging files
NOTE: Following content is directly reprinted from http://andrewberls.com/blog/post/git-tricks-unsta ...
随机推荐
- iOS实现渐变颜色
下面是我的两种实现: 1.直接图片展示,注意图片的变形问题; 2.用CAGradientLayer渐变颜色实现; 代码如下: // // ViewController.m // ImageStrenc ...
- Tensorflow 从文件中载入训练数据
本节包含: 用纯文本文件准备训练数据 加载文件中的训练数据 一.用纯文本文件准备训练数据 1.数据的数字化 比如,“是” —— “1”,“否” —— “0” “优”,“中”,“差” —— 1 2 3 ...
- CentOS配置java环境,mysql数据库等文章链接
配置jdk 配置jdk 安装mysql8 yum install -y mysql-community-server 安装mysql8 安装redi 安装redis 安装docker 安装docker
- Flash-aware Page Replacement Algorithm
1.Abstract:(1)字体太乱,单词中有空格(2) FAPRA此名词第一出现时应有“ FAPRA(Flash-aware Page Replacement Algorithm)”说明. 2.in ...
- Shell初学(七)linux账户管理/群组管理
[1]新建用户 用户相关文件:/etc/passwd /etc/shadow useradd useradd的默认预设 [2]设置密码 passwd 常见修改密码使用技巧: echo "1 ...
- mysql语法难点
select * from emp where comm is null or comm=0;/*没有提成的员工*/ 查询有提成的员工所有信息 select * from emp where comm ...
- 【Vue高级知识】细谈Vue 中三要素(响应式+模板+render函数)
[Vue高级知识]细谈Vue 中三要素(响应式+模板+render函数):https://blog.csdn.net/m0_37981569/article/details/93304809
- 在Docker中部署ASP.NET Core 2.2
⒈新建一个ASP.NET Core2.2 Web程序 因为Windows的Docker和Linux的Docker有所不同,本次测试采用的是Linux的Docker,因此没有勾选启用Docker支持. ...
- Luogu P4902 乘积
题目 我们要求的是 \[ \prod\limits_{i=a}^b\prod\limits_{j=1}^i(\frac ij)^{\lfloor\frac ij\rfloor} \] 先把它拆开 \[ ...
- Python 入门 之 类的三大关系(依赖 / 组合/ 继承关系)
Python 入门 之 类的三大关系(依赖 / 组合/ 继承关系) 在面向对象的中,类与类之间存在三种关系:依赖关系.组合关系.继承关系. 1.依赖关系:将一个类的类名或对象当做参数传递给另一个函数被 ...