100-doors

command module
v0.0.0-...-cc2c25f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 23, 2019 License: Apache-2.0 Imports: 1 Imported by: 0

README

100道门

描述

  • 100道门在一排上,全是关闭的
  • 每个门都有一个门牌号1-100
  • 每访问一次,就改变一次门状态(关的打开,打开的关闭)
  • 第1次访问,只访问门牌号是1的倍数的门
  • 第2次访问,只访问门牌号是2的倍数的门
  • 第3次访问,只访问门牌号是3的倍数的门
  • ...
  • 第100次访问,只访问门牌号是100的倍数的门

问题

第100次访问后,哪些门是关闭的,哪些门是打开的

解决过程

  • 只测试5个门的情况
  • 输出改为已打开的门牌号
  • 用自定义类型来封装
  • 针对扩展,指定哪些方法可以暴露

未优化

可用数学的优化去将两层循环替换层单层循环

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL