Coder Social home page Coder Social logo

garakuta's People

Contributors

yuji96 avatar

Watchers

 avatar

garakuta's Issues

4. 語呂合わせ

pi_string

それぞれの英単語のアルファベットの数を数えて並べると円周率になる。

例)
英文 : May I have a large container of coffee
円周率: 3.1415926

TODO

quiz/circle_digits.txtを読み込んで語呂合わせの文字列を取得し、
この文字列を用いて円周率を402桁まで求めよ。
以下、入力方法と出力方法の規則。

  • ピリオド.は無視する。
  • ピリオド以外の記号:,—!="()が独立して存在している位置は0とする。
    • つまり、" 3 "は記号が独立しているから010だが、"3"は記号が文字と隣接しているので3というふうに語呂を数字に変換する。
  • float型は402桁も扱えないので、str型で出力する。

Comment

ユーザーは開発者の想定通りに入力してくれない。例えば電話番号だと人によって0120-aaa-aaa0120(aaa)aaaだったりする。
これはwebアプリの入力フォームだけの問題ではなく、どの分野のエンジニアも対応できるようになる必要がある。
ちなみに正規表現を使うとトリッキーな文字列操作ができたりする。

関連

1. 答えをカンニング

TODO

Pythonの標準ライブラリが持っている円周率piの近似値を出力する。
また、ライブラリで定義された値をimportする書き方は3通りほどあるので、全部書けるようになる。

提出は不要。

Comment

関連

  • pythonで数学(ほぼ答えだから、解き終わってから見たほうが良い)

3. ライプニッツ級数(Leibniz formula)

TODO

数式
ライプニッツ級数を用いて円周率の近似値を求めよ。
関数が実装できたら、

python -m doctest file-name

と入力する。すると"""で囲まれたExampleコードが実行され、想定と出力が一致しなかった場合、テスト失敗の文が出力される。

Comment

項数を大量に増やしてもコンピュータに計算させれば一瞬でできるってことがプログラミングの利点。
符号の反転は(-1)のn乗で数学的に表すことができる。

関連

2. 互いに素な確率

TODO

  1. 1000以下の自然数をランダムに2つ選び、互いに素であるか判定する。
  2. この試行を1000回反復する。
  3. この反復試行から、自然数の乱数が互いに素である確率を求めよ。
  4. さらに、この操作を1000回行い確率の平均pを求めよ。
  5. 6/p の平方根を求めよ。

Comment

いわゆるシミュレーションをする問題。標準ライブラリは何を使ってもOK。
数学-basicではなくあくまでpython-basicなので、a, bが互いに素とはa, bの最大公約数が1ということは書いておく。最大公約数の求める関数は標準ライブラリのmathに入ってる。同じく乱数も標準ライブラリで生成できる。ヒントはここまで。

関連

5. コーディング規約

Pythonの「善い」の定義

>>> import this
The Zen of Python, by Tim Peters

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!

↑ここは別に読まなくてもいいけど

TODO

pip install hacking
flake8 quiz05.py

とターミナルに入力した時に表示されたコーディング違反を全て直せ。

Comment

PythonにはPEP8などのコーディング規約、つまりコードを書く時の約束事がある。この共通した約束事を守ると、コードの可読性が上がり、開発チームのメンバーからレビューをもらいやすくなるなど利点は大きい。
しかし、規約をいちいち確認するのは面倒だし、日本語のドキュメントは少ない。ここでflake8というライブラリをインストールして実行すると自動でコードチェックをしてくれる。(hackingが付属したflake8はさらに厳しくコードチェックをする。)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.