斑马难题Step by Step
在exercism.io被这个 Zebra Puzzle 难住了。这里一步一步的解决。。。
1.There are five houses.
2.The Englishman lives in the red house.
3.The Spaniard owns the dog.
4.offee is drunk in the green house.
5.The Ukrainian drinks tea.
6.The green house is immediately to the right of the ivory house.
7.The Old Gold smoker owns snails.
8.Kools are smoked in the yellow house.
9.Milk is drunk in the middle house.
10.The Norwegian lives in the first house.
11.The man who smokes Chesterfields lives in the house next to the man with the fox.
12.Kools are smoked in the house next to the house where the horse is kept.
13.The Lucky Strike smoker drinks orange juice.
14.The Japanese smokes Parliaments.
15.The Norwegian lives next to the blue house.
fang
求 Water 的房间和 Zebra 的房间
分析
首先,每个房间有 5 个属性,加上上面的若干条件限制。
属性
color -- $red, $green, $ivory, $yellow, $blue
Nationality (国家) -- $Englishman, $Spaniard, $Ukrainian, $Norwegian, $Japanese
Drink -- $coffee, $tea, $milk, $oj, $WATER
Smoke -- $OldGold, $Kools, $Chesterfields, $LuckyStrike, $Parl 大专栏 斑马难题Step by Stepiaments
Pet -- $dog, $snail, $fox, $horse, $ZEBRA
需要在满足所有条件的情况下讲这五个属性分给五个房间,大概就是这么一个思路。
那么我们一共有 5! ** 5 种情况。
先将房间和这些属性都抽象成 1,2,3,4,5
这里拿第二个条件说,就是 Englishman == red,因为他们都属于一个房间的属性,所以值必然相等。
当然,还有 6 , 11 这种条件,我们只需要加上两个方法即可。
/**
* Determinate the right of relation.
*
* @param int $n
* @param int $m
*
* @return boolean
*/
function rightOf($n, $m) {
return $n == $m + 1;
}
/**
* Determinate the neighbouring relations
*
* @param int $n
* @param int $m
*
* @return boolean
*/
function nextTo($n, $m) {
return abs($n - $m) == 1;
}
代码
斑马难题Step by Step的更多相关文章
- WPF Step By Step 系列 - 开篇 ·
WPF Step By Step 系列 - 开篇 公司最近要去我去整理出一个完整的WPF培训的教程,我刚好将自己学习WPF的过程和经验总结整理成笔记的方式来讲述,这里就不按照书上面的东西来说了,书本上 ...
- enode框架step by step之框架的物理部署思路
enode框架step by step之框架的物理部署思路 enode框架系列step by step文章系列索引: enode框架step by step之开篇 enode框架step by s ...
- Step by step Dynamics CRM 2011升级到Dynamics CRM 2013
原创地址:http://www.cnblogs.com/jfzhu/p/4018153.html 转载请注明出处 (一)检查Customizations 从2011升级到2013有一些legacy f ...
- Step by Step 创建一个新的Dynamics CRM Organization
原创地址:http://www.cnblogs.com/jfzhu/p/4012833.html 转载请注明出处 前面演示过如何安装Dynamics CRM 2013,参见<Step by st ...
- Step by step Install a Local Report Server and Remote Report Server Database
原创地址:http://www.cnblogs.com/jfzhu/p/4012097.html 转载请注明出处 前面的文章<Step by step SQL Server 2012的安装 &g ...
- Step by step Dynamics CRM 2013安装
原创地址:http://www.cnblogs.com/jfzhu/p/4008391.html 转载请注明出处 SQL Server可以与CRM装在同一台计算机上,也可安装在不同的计算机上.演示 ...
- Step by step 活动目录中添加一个子域
原创地址:http://www.cnblogs.com/jfzhu/p/4006545.html 转载请注明出处 前面介绍过如何创建一个域,下面再介绍一下如何在该父域中添加一个子域. 活动目录中的森林 ...
- SQL Server 维护计划实现数据库备份(Step by Step)(转)
SQL Server 维护计划实现数据库备份(Step by Step) 一.前言 SQL Server 备份和还原全攻略,里面包括了通过SSMS操作还原各种备份文件的图形指导,SQL Server ...
- 转:eclipse以及step into step over step return的区别
首先来讲一下step into step over step return的区别: step into就是单步执行,遇到子函数就进入并且继续单步执行:(F5) step over是在单步执行时,在函数 ...
随机推荐
- 4.windows-oracle实战第四课 -表的查询
所有语句均为安装oracle数据库后scott的默认表emp,dept等表 1.自己插入自己:insert into 表名 (字段)select *from 表名 2.去除重复行: select di ...
- ruoyi IpUtils
package com.ruoyi.common.utils; import java.net.InetAddress; import java.net.UnknownHostException; i ...
- Java任务调度框架之分布式调度框架XXL-Job介绍
Java任务调度框架之分布式调度框架XXL-Job介绍及快速入门 调度器使用场景: Java开发中经常会使用到定时任务:比如每月1号凌晨生成上个月的账单.比如每天凌晨1点对上一天的数据进行对账操作 ...
- Qt的窗口如何显示在spi屏幕上
问题:我们可以将qt移植到H3上,但是如果要将窗口通过spi屏进行显示应该怎么做呢,和framebuffer又有什么关系? 这里只说一下qt在spi屏上显示的技术原理,具体的实现还需要自己努力. 一. ...
- 利用face_recognition,dlib与OpenCV调用摄像头进行人脸识别
用已经搭建好 face_recognition,dlib 环境来进行人脸识别 未搭建好环境请参考:https://www.cnblogs.com/guihua-pingting/p/12201077. ...
- 五、linux-mysql 下mysql的管理(二)
1.插入语句: create table test( id int(4) not null auto_increment, name char(20) not null, primary ...
- 二十二、NFS服务深入讲解
一.查看nfs服务: [root@nfsserve ~]# ps -ef|grep -E "rpc|nfs"rpc 1565 1 0 17:29 ? ...
- 【DSP】TMS320F28335的GPIO
--> 关于TMS320F28335的GPIO的基础操作 TI的c2000系列DSP大多数的外设信号与通用输入/输出 (GPIO) 信号复用. 这使得用户能够在外设信号或者功能不使用时将一个引脚 ...
- RAM-Based Shift Register (ALTSHIFT_TAPS) IP Core-实现3X3像素阵列存储
最近想要实现CNN的FPGA加速处理,首先明确在CNN计算的过程中,因为卷积运算是最耗时间的,因此只要将卷积运算在FPGA上并行实现,即可完成部分运算的加速 那么对于卷积的FPGA实现首先要考虑的是卷 ...
- 2)#ifndef和#pragma once
#################################################################################################### ...