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 ...
随机推荐
- Java实现批量下载选中文件功能
1.在action中定义变量 ? 1 2 3 4 5 6 private List<String> downLoadPaths = new ArrayList<String>( ...
- SAP EXCEL OLE常用方法和属性
1.创建application: CREATE OBJECT excel 'EXCEL.APPLICATION'. 2.设置显示模式,为1前台运行,为0时表示为后台运行. . 3.设置为不弹消息框(在 ...
- 基于durid的JDBCUtils工具类
1.JDBCUtils类 package com.alphajuns.utils; import com.alibaba.druid.pool.DruidDataSourceFactory; impo ...
- java:JQuery(Ajax,JSON)
1.遍历ajax返回的json: 第一种: <%@ page language="java" import="java.util.*" pageEncod ...
- Swool的安装与使用
1.swoole的安装 //php最好用7.2以上的.直接去网站下载下来,然后与php一样编译安装. git下来后,因为没有config文件,故先在swool下载目录下执行: /.../php/bin ...
- 菜鸟系列Fabric——Fabric 1.2 单机部署(2)
Fabric 1.2单机部署 https://hyperledger-fabric.readthedocs.io/en/release-1.2/whatis.html 创建目录 sudo mkdir ...
- (已解决)Could not open '/var/lib/nova/mnt/*/volume-*': Permission denied
[问题描述] 创建boot_from_volume的虚机时,磁盘后端为NFS,创建失败. [错误日志] nova-compute模块 Could not open '/var/lib/nova/mnt ...
- luoguP3390(矩阵快速幂模板题)
链接:https://www.luogu.org/problemnew/show/P3390 题意:矩阵快速幂模板题,思路和快速幂一致,只需提供矩阵的乘法即可. AC代码: #include<c ...
- Unity VR-播放demo模型后无法移动视角
资源源于:小意思VR 唉..可怜一下自己,这个问题百度google也不知道怎么搜,没搜出来,在群里问出来的. 当时感觉自己Unity有问题..(就是因为自己啥也不会看不懂) 按右键.或者WASD视角都 ...
- MyBatis清空数据库表数据
<update id="truncateTable"> truncate table ${tableName} </update> <update i ...