タグ

codeとperlに関するkiyo_hikoのブックマーク (1)

  • #1 Multiples of 3 or 5 - Project Euler

    Published on Friday, 5th October 2001, 06:00 pm; Solved by 1009580; Difficulty rating: 5% If we list all the natural numbers below $10$ that are multiples of $3$ or $5$, we get $3, 5, 6$ and $9$. The sum of these multiples is $23$. Find the sum of all the multiples of $3$ or $5$ below $1000$.

    kiyo_hiko
    kiyo_hiko 2011/10/09
    発想は30秒でコード化に4分ぐらい。最近ループとかが理解出来ないのでループはほとんどリスト処理で書いてるな。 use List::Util qw/sum/;print sum map {!($_%5)||!($_%3)?$_:0}1..1000-1
  • 1