Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange
The results are in! See what nearly 90,000 developers picked as their most loved, dreaded, and desired coding languages and more in the 2019 Developer Survey.

Questions tagged [simulation]

Simulation is the imitation of some real thing, state of affairs, or process. The act of simulating something generally entails representing certain key characteristics or behaviours of a selected physical or abstract system.

10
votes
5answers
2k views

Ising model simulation

I have written this code to simulate Ising Model at one particular temperature in presence of magnetic field to observe hysteresis effect using the metropolis algorithm. While the code runs and gave ...
8
votes
1answer
46 views

Python implementation of approximating the chance a particle is at a location after n steps in the cardinal directions

Recently, I became very interested in a probability practice problem in my textbook for my class. I decided to implement it in code and I think I got most of it implemented. Right now, I'm hoping to ...
4
votes
2answers
157 views

Tic Tac Toe program that includes reports

I'm working to use everything I'm learning in my reading and former code reviews to keep making this program better. I'm getting stuck on the following issue: the ...
1
vote
0answers
38 views

2-dimensional random walk simulator, draws the steps on a canvas

Here's what I came up with for a 2-dimensional random walk exercise. It takes a number of steps as input and iterates through them, while drawing every step as a line on the canvas. The direction is ...
1
vote
0answers
29 views

Blackjack simulator for Probability of a dealer bust for each starting card

I came up with this solution to another exercise out of John Zelle's Programming book. ...
2
votes
1answer
70 views

Craps Simulator Exercise

I did another exercise, this time it simulates n games of craps(dice game) and outputs the wins and win percentage! ...
2
votes
1answer
53 views

Incrementing time in a discrete-event simulation of a supermarket queue

A method has been written that increments time in minutes that simulates how much time it takes to process item in a supermarket queue and if there is an empty queue, skip it and loops around to find ...
3
votes
1answer
87 views

Design of a Tic Tac Toe program in Python

Here is a program I wrote to reproduce the known win proportions for random Tic Tac Toe games (X always moving first). It takes about a minute to play the one million random games that will be played ...
4
votes
2answers
102 views

Follow up Implementation on Monty Hall Simulation

I have taken your inputs on my original question and formed a new implementation of the Monty Hall Simulation: Again keep an eye on CleanCode and OOP The Price to be won: ...
3
votes
1answer
46 views

Reproducing the known results for random tic tac toe play using Python

I'm reading "Code Complete" by McConnel and I'm practicing using object oriented programming to "reduce complexity". (By that McConnel means, among other things, that it should be very easy to read ...
3
votes
1answer
105 views

Discrete event simulation for production defects

I have one machine, which produces parts. In machine_failure_rate% it produces faulty parts which need to be produced again. Thus, we end up with a simple queuing ...
5
votes
2answers
347 views

Counting consecutive selections of a given number when sampling integers in a range

This script counts consecutive number strikes of a number that you determine in a number-sequence that you also determine. I would be very pleased if this script can be reviewed in terms of ...
2
votes
2answers
66 views

Pygame simulation of a production line

So my code works as intended, but suffers major performance issues every time I add a new object to the screen. The speed of my objects basically gets cut in half. All you have to do to observe this ...
13
votes
2answers
654 views

Simulating a two-body collision problem to find digits of Pi

I came across a nice video on 3Blue1Brown's channel that highlights a very indirect way to find the digits in Pi. I'd suggest watching the whole video, but briefly: The setup is as above. A "small" ...
1
vote
1answer
57 views

DM::OJ Slot Machines challenge in Python 3

I have written a solution to the Slot Machines challenge on DM::OJ: Martha takes a jar of quarters to the casino with the intention of becoming rich. She plays three machines in turn. Unknown to ...
2
votes
1answer
87 views

Langton's Ant simulation

I created a simple program to simulate the Ant's path. The Ant moves north, west, east and south. Each time the Anth moves to an "uncharted" location, I build a Square and give it a color. Each time ...
3
votes
1answer
79 views

Very slow frame rate in C++ N-body simulation using Barnes-Hutt and RK4

I am writing the code for my EPQ project and am aiming to produce a graphic showing the collapse of a particle cloud with around 10^5/6 particles. My current code will spawn a specified number of ...
1
vote
1answer
72 views

Simulating data generating process correctly

My aim is to simulate the following model by means of a Monte Carlo simulation. I wonder if my R code is correct for generating the data. Could somebody check? The model: $$Y = \sum_{j=1}^{100} (...
1
vote
0answers
29 views

Moderate return-low risk vs high returns-high risk investments

To quantify Buffet's #1 rule of investing, "Don't lose money", I take the assumption that % returns of an investment follow a Normal distribution. Now a high return high risk investment might follow ...
5
votes
2answers
133 views

Chess Simulation

Part of the program I wrote simulates a Chess game choosing random moves for each player until it's a draw or win for either player. It takes 3 seconds to complete 1 simulation and since it trains ...
3
votes
2answers
73 views

Simulation of an alien population

Background I've come across a puzzle (Problem 10 from this list of sample interview questions): One day, an alien comes to Earth. Every day, each alien does one of four things, each with equal ...
2
votes
1answer
87 views

Filling up a hand with random cards that are not yet drawn - Monte Carlo

I would like to know if there is a more efficient way to speed up below code. This function is meant to fill in a set of poker hand with the remaining cards using Mersenne Twister for a Monte Carlo ...
3
votes
2answers
80 views

Parallel processing simulation

Input n number of workers and m jobs to be scheduled, followed by m lines of time ...
2
votes
0answers
47 views

Excel VBA animation runs slowly after editing worksheet

My VBA macro displays an animation based on a row-by-row time step simulation in the worksheet. The user enters the desired inputs and the worksheet calculates the evolution of the simulation in a ...
3
votes
0answers
85 views

Designing a configurable Discrete Event Simulation class

A bit of context: I've had a fair share of programming in Java but want to refine my C++ skills with a college task. I've wanted to focus on C++11 and C++14, as they are recent but not latest, and C++...
2
votes
2answers
49 views

The importance of consistency in percentage returns when investing

It is said that Being consistent in percentage annual returns leads to larger amount over time. That is for any given principal, getting 20% successively for 2 years is better than 30% for first ...
1
vote
1answer
44 views

Counting results of die rolls

The algorithm bellow is meant to allow a user to roll a die as many times as he would like, then print how many times each side was rolled and how many rolls there were total. ...
2
votes
1answer
71 views

NAQ 2018 Problem D Froggie

Successful attempt at the ICPC North America Qualifier 2018 Problem D "Froggie." Any advice and all topical comments on code optimization and performance enhancement is appreciated! Problem Summary ...
3
votes
2answers
115 views

Extending Combo from Food in FoodOrder Simulator

This is an assignment and I'm trying to improve upon the design factor. Honestly the task seems very trivial to use inheritance so I kind of did it for the sake of doing it. The problem description ...
16
votes
3answers
2k views

Newton-Pepys, common birthdays and other probability simulations in Python 3

I have been learning Probability from Statistics 110 and trying to simulate problems that have an unintuitive answer ...
0
votes
1answer
163 views

Yet another vending machine

I recently got a homework assignment from my C++ teacher. The verbatim assignment was this: Write a program that simulates a vending machine. A customer selects and item for purchase and inserts a ...
4
votes
3answers
926 views

Discrete Event Simulator

I'm an undergraduate student and I have this assignment on a Discrete Event simulator. Currently I have completed to the end of v1.2 here. Attached also, is an algorithmic overview. I have wrote my ...
1
vote
2answers
326 views

Matching socks from a bag of socks

I was reading the book Algortihms to Live By and was inspired by it to take a shot at simulating How to pair socks from a pile? (sans the efficiently part at the moment). ...
2
votes
1answer
65 views

Iteratively simulate a parasite population

I'm trying to build a simulation in R to model the effects of different parasite egg laying behaviors on how many offspring the parasite has, given a limited amount of resources. In brief, this ...
1
vote
2answers
71 views

Classic “100 doors” simulation in Clojure

I read this question about the "100 Doors" puzzle, and thought that it would make for a good quick exercise. I ended up with two implementations. The first is more straightforward and uses a vector ...
3
votes
1answer
166 views

Classic Hundred Doors Simulation

I am doing the 100 Doors problem as an exercise to practice user input and loops. I do understand the problem can be solved by outputting every square number up to the maximum number, but it defeats ...
4
votes
0answers
138 views

Fast Hardy-Weinberg equilibrium simulation

I was very bored over one of my breaks this year, so I built a Hardy-Weinberg equilibrium simulator for two unrelated alleles of the same gene. Hardy-Weinberg equilibrium is when there is no evolution,...
1
vote
1answer
62 views

k-armed bandit problem in Python

I implemented k-armed bandit problem in C#, MATLAB and Python. C# and Matlab code run fairly fast (With same settings of T = 2000 and nRun = 1000 the elapsed time is about 6sec). However, the Python ...
0
votes
2answers
370 views

Blackjack strategy simulation

I'm very new to python (been coding for about two days) and have created a programme that simulates blackjack games so that I can work out optimal strategy over many iterations. The problem is that ...
4
votes
1answer
176 views

Packet process time simulation using queue

Here is my code for the below packet time simulation problem using queue. My code works correctly but it's slow, please help with suggestions to improve run time and other suggestions for performance ...
7
votes
2answers
95 views

A game of automated tag

This game has 4 people moving randomly, one unit in one of the four directions (up, down, left, right), with a fifth person as a designated tagger. If this fifth person tags someone, the person is out....
4
votes
2answers
584 views

Java Conway's Game Game of Life

I have implemented Conway's Game of Life simulation. What can I improve? How could I structure my programme better? All suggestions would be appreciated. World.java: ...
1
vote
1answer
64 views

ROW (Race of work) simulation

I wrote a ROW (Race of work) simulation, the idea contains a mathematical bug and, I asked a question about it here. I would also like to make this code more readable and, this is why I am sharing it ...
1
vote
1answer
144 views

Galton Board Simulation

This program is written for Windows 7 under MinGW using gcc. I'm seeking recommendations for improving the program's portability. ...
10
votes
4answers
1k views

Make a Deal program - using sets in Python

Mostly because I didn't believe the outcome of the classic game play Make-a-Deal (see https://math.stackexchange.com/questions/608957/monty-hall-problem-extended) I made this little program... and ...
5
votes
1answer
97 views

Beginnings of a neuron simulation

I have 2 classes that do extremely similar things. The only differences are that they draw using different colors, and that one draws in the back. The classes ...
5
votes
2answers
522 views

Java Langton's Ant simulation

I have implemented a simulation which is called "Langton's Ant" with Java. Here is a short summary of basic rules: A ant is placed in a 2D matrix and looks to north, west, east or south. First, all ...
5
votes
1answer
132 views

Simulating coin flips and plotting a histogram

I started playing around recently with F# and I find it quite elegant and succinct language. A common problem I like to solve in every language I start to learn is the coin flip problem, with the ...
3
votes
0answers
53 views

Work environment simulator

This code attempts to solve a suggested challenge by myself a while back on meta, transcribed here for simplicity. Allocate resources efficiently on a work environment The company Code42Review ...
6
votes
3answers
1k views

Python Conway's Game of life

One of my first serious Python programs, realized Conway's Game of Life in Python. Not sure that get_cell_state and update_table functions are good as they might be. Would be glad to see any ...