LoginSignup
2
0

More than 5 years have passed since last update.

(a == 1 && a == 2 && a == 3)を常にtrueにする系コードゴルフのようなもの(Python2: 37byte or 32byte)

Last updated at Posted at 2018-01-22

(a == 1 && a == 2 && a == 3) を常に真にできますか?という記事に対して、いくつか記事を書いたので、最後の仕上げとしてコードゴルフのようなことをします。

基本的には、Python2で(a == 1 and a == 2 and a == 3) を常にTrueと等しくする魔法の一文(演算子はいじらない系)(ソース4行)これの変形です。

ソースコード

True=a=0;print(a==1&a==2&a==3)==True

いつの間にかandがbit演算子(&)になっていますが、bool型同士の演算ならandと一緒だから……。

ちなみにインタラクティブ実行環境なら、

True=a=0;(a==1&a==2&a==3)==True

32byteまでいけます。

制約条件が分かりづらいので競技としては成立しませんが、まあ、なんか短くなったよってことで。

2
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
2
0