RSSAmplifier

Tom Stuart · Mar 14, 2024

(untitled)

0
Sign in to vote or save

This site does not allow itself to be embedded. You can still read it on the original site — the toolbar below keeps your place in the directory.

Happy π day! How accurate an estimate of the value of π does your commit history produce? ``` MAX = (1 << 64) - 1 hits = 0 `git log --pretty=format:%H`.each_line(chomp: true).with_index do |sha, index| x, y = [sha].pack('H*').unpack('Q*').map { (_1.to_f / MAX) * 2 - 1 } hits += 1 if Math.sqrt(x*x + y*y) <= 1 puts hits.to_f / (index + 1) * 4 end ```

Happy π day! How accurate an estimate of the value of π does your commit history produce?

```
MAX = (1 << 64) - 1
hits = 0
`git log --pretty=format:%H`.each_line(chomp: true).with_index do |sha, index|
x, y = [sha].pack('H*').unpack('Q*').map { (_1.to_f / MAX) * 2 - 1 }
hits += 1 if Math.sqrt(x*x + y*y) <= 1
puts hits.to_f / (index + 1) * 4
end
```

Read on ruby.social

Comments

Nothing yet. Say the first thing.

    Sign in to join the conversation.