Stack Exchange Network

Stack Exchange network consists of 174 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

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.

1
vote
1answer
25 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 ...
1
vote
0answers
51 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
61 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
64 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
24 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
91 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
59 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
72 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
46 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
47 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
36 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
67 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
88 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
105 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 ...
2
votes
2answers
147 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
168 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
63 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
66 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
123 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
134 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
57 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
230 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
116 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
93 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
419 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
63 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
89 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
96 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
339 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
123 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
49 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
910 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 ...
0
votes
1answer
175 views

Java agent-based model

I've been working on an agent-based model as part of my PhD and I've hit a roadblock. I started learning Java by doing this project and I definitely started to run before I could walk. The problem is ...
1
vote
1answer
93 views

Rock Climbing Simulation Game

I am a rock climber so I made a rock climbing game. I have two conceptual objects; the climber and the route. I ended up putting them both into a single Climber ...
7
votes
2answers
108 views

Simulating surname convergence in a population

I was curious a few weeks ago about how surnames come and go (mostly on the go). I wanted to know how quickly surnames die out, because (in my simplified simulation world) once the last person with a ...
11
votes
3answers
361 views

Coding exercise to simulate animal population

(This is all available in a github repo if that's easier: https://github.com/paulnicholsen27/SpeciesSimulator) I am submitting this as a code sample for a possible job, so I'm just looking for any ...
4
votes
1answer
111 views

Concise Proof of the Monty Hall Problem in R

This is an attempt at a concise proof of the Monty Hall problem in probability and statistics in R. For those unfamiliar, the scenario is this: There exists a contestant on a game show. This ...
4
votes
1answer
132 views

C++ Grid gravity simulation opzimization (Kattis Falling Apples)

I have a solution for the Kattis Falling Apples problem (link). The input is a grid of R rows (up to 50000) by C columns (up to 10). At each timestep, apples (indicated by ...
6
votes
2answers
377 views

The performance of the simulation for an ant's random walk on a 5x5 grid

I have written a simulation in order to solve the 280th problem in Project Euler, and the simulation basically repeat the given experiment 5m times, and for each experiment, writes the ExpNo - #...
1
vote
2answers
55 views

Calculating the connectance of a matrix iteratively

I have a performance issue in R. I have a function that iterates over a dataframe for different levels of "site" and "method". The function samples 1:1000 interactions (rows), converts these to ...
1
vote
1answer
348 views

A 3D Random walk simulation

I was referring to the book Computational Physics by Nicholas J. Giordano and was studying the simple Random Walk model. (Pg. 169 - 173) I consider a 3D Random Walk where the probability of moving in ...
5
votes
1answer
396 views

CPU scheduling simulator

Recently I completed my first assignment at the university. The assignment is : Write a CPU scheduling simulator that uses the Shortest Job First and Priority scheduling methods. Both of these ...
4
votes
2answers
418 views

Rolling 100-sided “dice” until they are the same number

I've just begun my journey into python (1 week now) and I've written couple of lines incorporating everything I've learned so far. It would be greatly appreciated if anyone could guide me in writing a ...
3
votes
1answer
135 views

Simulated race among three robots making random steps

At a job interview, I was asked to code the following algorithm: Given are three robots which advance across a 1km lane at a different pace respectively. Each pace made by a robot is of a random ...
3
votes
2answers
324 views

Simulating a system of moving points

This is an update of the code from my previous question. I'm simulating a system of particles which interact with each other and move and rotate due to the interaction. There are 2000 particles in ...
2
votes
0answers
278 views

Lotto simulator in Python

I wrote a rather inapt lotto simulator in Python, showing how long it would take to win the jackpot. I ran a similar application implemented in C and it is so much faster. I know you can't compare the ...