Code Signal_练习题_chessBoardCellColor
Given two cells on the standard chess board, determine whether they have the same color or not.
Example
For
cell1 = "A1"
andcell2 = "C3"
, the output should bechessBoardCellColor(cell1, cell2) = true
.For
cell1 = "A1"
andcell2 = "H3"
, the output should bechessBoardCellColor(cell1, cell2) = false
.
我的解答:
def chessBoardCellColor(cell1, cell2):
return abs(int(cell1[1])-int(cell2[1])) % 2 == 0 if abs(ord(cell1[0]) - ord(cell2[0])) % 2 == 0 else abs(int(cell1[1])-int(cell2[1])) % 2 == 1
def chessBoardCellColor(cell1, cell2):
return (ord(cell1[0]) + int(cell1[1]) + ord(cell2[0]) + int(cell2[1])) % 2 == 0
膜拜大佬
Code Signal_练习题_chessBoardCellColor的更多相关文章
- Code Signal_练习题_digitDegree
Let's define digit degree of some positive integer as the number of times we need to replace this nu ...
- Code Signal_练习题_Knapsack Light
You found two items in a treasure chest! The first item weighs weight1 and is worth value1, and the ...
- Code Signal_练习题_growingPlant
Each day a plant is growing by upSpeed meters. Each night that plant's height decreases by downSpeed ...
- Code Signal_练习题_arrayMaxConsecutiveSum
Given array of integers, find the maximal possible sum of some of its k consecutive elements. Exampl ...
- Code Signal_练习题_differentSymbolsNaive
Given a string, find the number of different characters in it. Example For s = "cabca", th ...
- Code Signal_练习题_firstDigit
Find the leftmost digit that occurs in a given string. Example For inputString = "var_1__Int&qu ...
- Code Signal_练习题_extractEachKth
Given array of integers, remove each kth element from it. Example For inputArray = [1, 2, 3, 4, 5, 6 ...
- Code Signal_练习题_stringsRearrangement
Given an array of equal-length strings, check if it is possible to rearrange the strings in such a w ...
- Code Signal_练习题_absoluteValuesSumMinimization
Given a sorted array of integers a, find an integer x from a such that the value of abs(a[0] - x) + ...
随机推荐
- git fetch 、git pull 与 git pull --rebase
1. git fetch 与 git pull 都是从远程拉取代码到本地,git fetch只是拉取到本地,git pull不仅拉取到本地还merge到本地分支中.所以git pull是git fet ...
- Linux - APT包管理
dpkg与apt dpkg用来安装本地deb格式软件包,但不会解决软件包的依赖关系. APT(Advanced Packaging Tool)是从更新源获取并安装软件包,而且会解决依赖关系, 但不会安 ...
- javascript之快速排序
快速排序思想其实还是挺简单的,分三步走: 1.在数组中找到基准点,其他数与之比较. 2.建立两个数组,小于基准点的数存储在左边数组,大于基准点的数存储在右边数组. 3.拼接数组,然后左边数组与右边数组 ...
- D17——C语言基础学PYTHON
C语言基础学习PYTHON——基础学习D17 20181014内容纲要: 1.jQuery介绍 2.jQuery功能介绍 (1)jQuery的引入方式 (2)选择器 (3)筛选 (4)文本操作 (5) ...
- python 生成器 迭代器
阅读目录 一 递归和迭代 二 什么是迭代器协议 三 python中强大的for循环机制 四 为何要有for循环 五 生成器初探 六 生成器函数 七 生成器表达式和列表解析 八 生成器总结 一 递归和迭 ...
- javascript保留字趣史
转载自[https://mathiasbynens.be/notes/reserved-keywords](https://mathiasbynens.be/notes/reserved-keywor ...
- 全网最详细的HBase启动以后,HMaster进程启动了,几秒钟以后自动关闭问题的解决办法(图文详解)
不多说,直接上干货! 问题详情 情况描述如题所示,hbase启动以后,HMaster进程启动了,几秒钟以后自动关闭,但是HRegionServer进程正常运行: 解决办法: 1.检查下每台机器的时间是 ...
- tomcat 配置文件server.xml 详解 Connector Engine Host Context
目录 一 server.xml 1.1 server 配置 1.2 service 配置 1.3 Executor 1.4 Connector 配置 1.5 Engine 其他tocmat 文章 一 ...
- java监听器、定时器的使用
1.监听器 在web.xml配置 <!-- 时间任务 --> <listener> <listener-class> com.hk.common.timer.Tim ...
- Entity Framework 6.x 学习之 - 创建带连接表的实体模型 with Database First
一.Modeling a Many-to-Many Relationship with No Payload 1. 创建数据库表 CREATE TABLE [Album] ( , ), ) COLLA ...