0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

数字と文字リテラルを使わずFizzBuzz

Last updated at Posted at 2022-08-14

TL;DR

  • 第5回 KusoKoudoKaigi | KusoKoudoKaigi
  • こんなのやってたの知らなかった
  • 応募しそこねたので15分で書いた。むしろこのエントリ書くほうが時間かかった。
  • 以前書いたやつのリバイバル作品

動くやつ

コード

<?php
class FizzBuzz {
	const THREE = __LINE__;
	const FOUR = __LINE__;
	const FIVE = __LINE__;









	const FIFTEEN = __LINE__;

	public function main() {
		for($i = (int) true;$i <= self::FIFTEEN;$i++) {
			ob_start();
			$this->f($i);
			$this->b($i);
			if (ob_get_contents() == false) {
				echo $i;
			}
			echo PHP_EOL;
		}
	}

	private function f($i) {
		if ($i % self::THREE == false) {
			echo substr(__CLASS__, false, self::FOUR);
		}
	}

	private function b($i) {
		if ($i % self::FIVE == false) {
			echo substr(__CLASS__, self::FOUR, self::FOUR);
		}
	}
}

(new FizzBuzz())->main();

完走した感想

  • $i = true のままだと$i1になり続けて辛かった
  • もっとお題の「強盗に襲われた」シチュを深めてクソコード書きたかった
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?