## performance – Project Euler #645 — speed up Monte-Carlo simulation in Python

I am trying to solve Q645. While the logic used for my code seems to be appropriate, the code itself is way too slow for the large number required in this question. May I ask for suggestion(s) to improve my code’s performance?

The question is as in the link: https://projecteuler.net/problem=645

My Python code is as follow:

``````def Exp(D):
day_list = (0)*D
num_emperor = 0
while all((d == 1 for d in day_list)) == False:
#the birthday of the emperors are independent and uniformly distributed throughout the D days of the year
bday = np.random.randint(0,D)
day_list(bday) = 1
num_emperor+=1
#indices of d in day_list where d == 0
zero_ind = (i for i,v in enumerate(day_list) if v == 0)
for ind in zero_ind:
try:
if day_list(ind-1) and day_list(ind+1) == 1:
day_list(ind) = 1
except IndexError:
if ind == 0:
if day_list(-1) and day_list(1) == 1:
day_list(0) = 1
elif ind == len(day_list)-1:
if day_list(len(day_list)-2) and day_list(0) == 1:
day_list(len(day_list)-1) = 1
return num_emperor

def my_mean(values):
n = 0
summ = 0.0
for value in values:
summ += value
n += 1
return summ/n

def monte_carlo(iters, D):
iter = 0
n_emperor = 0
while iter < iters:
n_emperor = Exp(D)
yield n_emperor
iter += 1

avg_n_emperor = my_mean(monte_carlo(iters,D))
print(avg_n_emperor)
``````

And my logic is as follow:

For the day_list inside the Exp(D) function, where D is the number of days in a year, zeros mean no holiday, and ones mean holiday. Initially the day_list is all zeros since there is no holiday to begin with.

The rules of defining a random day (d) as a holiday is as follow:

1. At the beginning of the reign of the current Emperor, his birthday is declared a holiday from that year onwards.

2. If both the day before and after a day d are holidays, then d also becomes a holiday.

I then subsequently implement the rules stated for the question, to gradually add holidays (ones) into the day_list. After num_emperor number of emperors, all the days (d) in day_list will become 1, i.e. all days will become holiday. This is the point to quit the while_loop in Exp(D) function and count the number of emperors required. To get the average number of emperors required for all the days to become holidays (avg_n_emperor), I then apply the monte-carlo method.

For my current code, the time takes is as follow:

``````avg_n_emperor = my_mean(monte_carlo(iters=100000,D=5)) #6-7 seconds

avg_n_emperor = my_mean(monte_carlo(iters=1000000,D=5)) #about 62 seconds
``````

in which the time takes increase approx. linearly with the iters.

However,

``````avg_n_emperor = my_mean(monte_carlo(iters=1000,D=365)) #about 68 seconds
``````

already takes about 68 seconds, and the question is asking for D=10000. Not to mention that the iters required for the answer to be accurate within 4 digits after the decimal points (as required by the question) would be much larger than 1000000 too…

Any suggestion(s) to speed up my code would be appreciated! ðŸ™‚

## Color film recommendation for Mamiya 645 AFD, Landscapes

I recently bought a Mamiya 645 AFD with 80mm Æ’ / 2.8 and 45mm Æ’ / 2.8 lenses and am looking forward to dipping my toes in the medium format (only the little fingers could be in my current digital crop sensor fit).

Are there any rules of thumb that I should know when choosing the film? I mainly photograph landscapes and am used to the Fuji Provia look from my X-T2 and Lightroom or Capture One editing workflow. The shades of green always give me a headache.

I assume that the film will be completely different. I intend to have it developed by a professional laboratory and have it scanned to high-resolution Tiff (any tips on choosing a good one?). By editing videos I've seen online, color rendering can vary a lot depending on the lab. I therefore assume that I will have to go through a few iterations before I am familiar and confident with the output.

My main question at this stage is: What factors should I consider when choosing the film? I see different brands on sale because they have expired. Is this usually a risky hit-or-miss business that is best avoided for beginners like me? (The low price is attractive, but less, considering development + scan overhead, the scans should turn out to be terrible).

Availability and price will definitely be an issue, but apart from fAre there any known color rendering factors that I can examine? Is there a comparison page on which color rendering features / peculiarities of the various common brands are displayed side by side?

In addition, I switched an old Fuji X-pro1 to infrared and am enjoying the look of black and white infrared photography. I assume that this is also possible with this new Mamiya and a suitable film (black and white would be my preference) – tips are also welcome here!

## dslr – Why has not anyone made a CMOS sensor for digital cameras in 645 or 6×6 format?

I understand that the price of silicon does not always scale linearly with its size / number of components, but I'm really curious why we have not yet seen digital camera sensors in true medium format sizes. It appears that even the high-end camera manufacturers are exceeding a current sensor size limit because the camera with the largest sensor size I can find is the Phase One IQ4, a \$ 50,000 camera, that has a sensor size just under 645 film size.

I think the bigger the sensor, the better the picture quality, and so there is a market for professional photographers who want to stand out from the competition. One might therefore assume that there is a market incentive to produce sensors that match some of the larger film sizes.

Above all, are economies of scale that only make the production of certain sizes of sensors, which are currently not produced in series, expensive? Do factories need updating to facilitate the production of these larger sensors? Or are there existing limitations in existing manufacturing techniques that prevent companies from producing an arbitrarily large CMOS sensor?

## App Windows – GoldWave 6.45 (x64) | NulledTeam UnderGround

File size: 14 MB

GoldWave is a world-class, comprehensive digital audio editor. GoldWave is ideal for people who work with audio to edit CDs, restore archives, analyze language, radio and television, Java and websites, games or just for fun. It lets you create everything from lavish answering machine messages to professional, high-quality CD audio content.
In case you do not want to get any further

GoldWave can:

â€¢ Play, edit, mix and analyze audio
â€¢ Record audio from cassettes, records, radio, etc. via the line-in of your computer
â€¢ Record the dictation via a microphone or play it slower for transcription
â€¢ Record and edit audio for podcasts
â€¢ Apply special effects such as Fade, Equalizer, Doppler, Mechanize, Echo, Reverse, Flanger and more
â€¢ Digitally remaster and restore old recordings with noise reduction and pop / click filters
â€¢ Create perfect digital copies of audio CD tracks with the CD Reader tool and save them to WMA, MP3 and OGG files
â€¢ Edit music for dance programs, figure skating, gymnastics
â€¢ Analyze human speech, birdsong, whale song
â€¢ Demonstrate digital signal processing with filter effects and the Expression Evaluation Tool
â€¢ View a variety of real-time visualizations and VU displays
â€¢ Convert files to / from various formats such as WAV, WMA, MP3, OGG, AIFF, AU, VOX and even binary data

General characteristics:
â€¢ Multiple Document Interface for working with many files in one session
â€¢ Huge file processing: 4 GB and more (NTFS only)
â€¢ Configurable memory or hard disk processing
â€¢ High quality: 24 bits, 192 kHz
â€¢ Real-time visualizations: bars, waveform, spectrogram, spectrum, VU-meter, …
â€¢ Fast, non-destructive machining. Regardless of file size, cut, copy, delete, and undo take only a fraction of a second
â€¢ Multiple undo levels
â€¢ Many effects: Distortion, Doppler, Echo, Filter, Mechanize, Move, Pan, Volume shaping, Invert, Resampling, Equalizer, Time Warp, Pitch, Reverb, Volume Adjust, Channel Mixer, …
â€¢ Effect preview and presets
â€¢ Audio Recovery Filter: Noise Reduction, Pop / Plick, Smoothing
â€¢ Supported file formats (wav, mp3, ogg, aiff, au, vox, mat, snd, voc, binary raw data, text data and more)
â€¢ File format plug-ins for the next generation of audio compression. WMA, Ogg Vorbis and FLAC.
â€¢ DirectX audio plug-in hosting
â€¢ Effects chain editor
â€¢ Batch processing and conversion
â€¢ Drag and drop cue points with auto cue and file splitting capabilities.
â€¢ Direct waveform editing with the mouse
â€¢ Customizable toolbars
â€¢ Customizable waveform colors
â€¢ Multiple built-in accessibility and keyboard shortcuts

What's new?

START PAGE

In case you do not want to get any further

## Re: [Tisocks.net] – Socks5 Proxy Service Cheap Socks5

SOCKS proxy list from Tisocks.net
If you need socks5, please visit service and add funds via PM, BTC WMZ, WEX. Thank you all !!
Check socks5 online here: https://checksocks5.com
LIVE | 24.197.39.70:52859 | 0.218 | SOCKS5 | Alabama | 35503 | 24-197-39-70.static.leds.al.charter.com | United States | Reviewed at https://tisocks.net
LIVE | 50.62.35.107:35475 | 0,305 | SOCKS5 | Arizona | 85260 | ip-50-62-35-107.ip.secureserver.net | United States | Reviewed at https://tisocks.net
LIVE | 185.223.95.143:8406 | 0,279 | SOCKS5 | Unknown | Unknown | | Unknown | Reviewed at https://tisocks.net
LIVE | 185.223.95.143:8368 | 0.315 | SOCKS5 | Unknown | Unknown | | Unknown | Reviewed at https://tisocks.net
LIVE | 185.223.95.143:8170 | 0,301 | SOCKS5 | Unknown | Unknown | | Unknown | Reviewed at https://tisocks.net
LIVE | 192.169.197.122:4363 | 0,928 | SOCKS5 | Arizona | 85260 | ip-192-169-197-122.ip.secureserver.net | United States | Reviewed at https://tisocks.net
LIVE | 64.90.52.94:63960 | 1.324 | SOCKS5 | California | 92821 | millcity.dreamhost.com | United States | Reviewed at https://tisocks.net
LIVE | 185.223.95.143:8107 | 0.311 | SOCKS5 | Unknown | Unknown | | Unknown | Reviewed at https://tisocks.net
LIVE | 192.169.237.19:32988 | 0,303 | SOCKS5 | Arizona | 85260 | ip-208-109-52-52.ip.secureserver.net | United States | Reviewed at https://tisocks.net
LIVE | 50.62.35.107:4482 | 0,322 | SOCKS5 | Arizona | 85260 | ip-50-62-35-107.ip.secureserver.net | United States | Reviewed at https://tisocks.net
LIVE | 51.75.18.214:9050 | 0,922 | SOCKS5 | Unknown | Unknown | | Unknown | Reviewed at https://tisocks.net
LIVE | 64.90.50.36:63960 | 1,645 | SOCKS5 | California | 92821 | millcity.dreamhost.com | United States | Reviewed at https://tisocks.net
LIVE | 185.223.95.143:8166 | 0,281 | SOCKS5 | Unknown | Unknown | | Unknown | Reviewed at https://tisocks.net
LIVE | 75.119.209.93:1088 | 0,223 | SOCKS5 | California | 92821 | ps7189.dreamhostps.com | United States | Reviewed at https://tisocks.net
LIVE | 192.169.237.189:32988 | 0,283 | SOCKS5 | Arizona | 85260 | ip-208-109-52-52.ip.secureserver.net | United States | Reviewed at https://tisocks.net

Tisocks
Reviewed by Tisocks on
,
Re: [Tisocks.net] – Socks5 Proxy Service Cheap Socks5
SOCKS proxy list from Tisocks.net
If you need socks5, please visit service and add funds via PM, BTC WMZ, WEX. Thank you all !!
Check socks5 online here: https://checksocks5.com
LIVE | 24.197.39.70:52859 | 0.218 | SOCKS5 | Alabama | 35503 | 24-197-39-70.static.leds.al.charter.com | United States | Reviewed at https://tisocks.net
LIVE | 50.62.35.107:35475 | 0,305 | SOCKS5 | Arizona | 85260 | ip-50-62-35-107.ip.secureserver.net | United States | Checked for

Rating: 5

,

## PROXIES SOCKS PROXY LIST 12h03 PM FROM TISOCKS.NET

SOCKS proxy list from Tisocks.net
If you need Socks5, please visit the service and add money via PM, BTC WMZ, WEX. Thank you all !!
Check Socks5 Online here: https://checksocks5.com
LIVE | 104.238.97.215:30051 | 0,257 | SOCKS5 | Arizona | 85260 | ip-104-238-97-215.ip.secureserver.net | United States | Checked at https://tisocks.net
LIVE | 50.62.31.203:15469 | 0,251 | SOCKS5 | Arizona | 85260 | ip-104-238-125-119.ip.secureserver.net | United States | Checked at https://tisocks.net
LIVE | 132.148.13.47:45645 | 0.25 | SOCKS5 | Arizona | 85260 | ip-192-169-198-104.ip.secureserver.net | United States | Checked at https://tisocks.net
LIVE | 104.238.97.215:24783 | 0,249 | SOCKS5 | Arizona | 85260 | ip-104-238-97-215.ip.secureserver.net | United States | Checked at https://tisocks.net
LIVE | 104.238.97.215:1888 | 0,252 | SOCKS5 | Arizona | 85260 | ip-104-238-97-215.ip.secureserver.net | United States | Checked at https://tisocks.net
LIVE | 104.238.97.215:62325 | 0,252 | SOCKS5 | Arizona | 85260 | ip-104-238-97-215.ip.secureserver.net | United States | Checked at https://tisocks.net
LIVE | 104.238.97.215:3541 | 0.25 | SOCKS5 | Arizona | 85260 | ip-104-238-97-215.ip.secureserver.net | United States | Checked at https://tisocks.net
LIVE | 104.238.97.215:62454 | 0.518 | SOCKS5 | Arizona | 85260 | ip-104-238-97-215.ip.secureserver.net | United States | Checked at https://tisocks.net
LIVE | 132.148.153.23:5260 | 0.645 | SOCKS5 | Arizona | 85260 | ip-132-148-146-65.ip.secureserver.net | United States | Checked at https://tisocks.net
LIVE | 141.101.236.49:9999 | 0.72 | SOCKS5 | Unknown | Unknown | | Unknown | Checked at https://tisocks.net
LIVE | 50.62.31.218:52317 | 0.62 | SOCKS5 | Arizona | 85260 | ip-192-169-202-104.ip.secureserver.net | United States | Checked at https://tisocks.net
LIVE | 104.238.97.215:45448 | 0.25 | SOCKS5 | Arizona | 85260 | ip-104-238-97-215.ip.secureserver.net | United States | Checked at https://tisocks.net
LIVE | 104.238.97.215:14103 | 0.25 | SOCKS5 | Arizona | 85260 | ip-104-238-97-215.ip.secureserver.net | United States | Checked at https://tisocks.net
LIVE | 50.63.13.135:29808 | 0,249 | SOCKS5 | Arizona | 85260 | ip-50-63-13-135.ip.secureserver.net | United States | Checked at https://tisocks.net
LIVE | 104.238.97.215:60102 | 0.25 | SOCKS5 | Arizona | 85260 | ip-104-238-97-215.ip.secureserver.net | United States | Checked at https://tisocks.net

Tock socks
Reviewed by Tock socks on
,
PROXIES SOCKS PROXY LIST 12h03 PM FROM TISOCKS.NET
SOCKS proxy list from Tisocks.net
If you need Socks5, please visit the service and add money via PM, BTC WMZ, WEX. Thank you all !!