add tag
> This is part of the Summer of Code 2022 series, see for more information

Today's puzzle is a fun one: calculate pi

Top Answer
*no spoiler*

Today, I wanted to learn about random numbers in expl3, so I decided to go for a Monte Carlo approach to approximate pi:



Today’s puzzle is a fun one: calculate pi


\int_new:N \l_sam_a_int
\int_new:N \l_sam_b_int
\int_new:N \l_sam_count_int
\int_zero:N \l_sam_count_int
\int_new:N \l_sam_rep_int
\int_set:Nn \l_sam_rep_int { 1000000 }

\int_step_inline:nn {\l_sam_rep_int}

  \int_set:Nn \l_sam_a_int { \int_rand:n {10000} }
  \int_set:Nn \l_sam_b_int { \int_rand:n {10000} }
  \int_compare:nNnT { \l_sam_a_int * \l_sam_a_int + \l_sam_b_int * \l_sam_b_int } < { 10000 * 10000 } { \int_incr:N \l_sam_count_int } 

\par \fp_eval:n { \l_sam_count_int * 4.0 / \l_sam_rep_int }



This room is for discussion about this question.

Once logged in you can direct comments to any contributor here.

Enter question or answer id or url (and optionally further answer ids/urls from the same question) from

Separate each id/url with a space. No need to list your own answers; they will be imported automatically.