CSci 1113: Introduction to C/C++ Programming for Scientists and Engineers Homework 2 Spring 2018

Similar documents
Statistics Laboratory 7

Name Class Date. Introducing Probability Distributions

Math 147 Lecture Notes: Lecture 21

Spring 06 Assignment 2: Constraint Satisfaction Problems

Math 8 Homework TRIMESTER 2 November March 2019

HW4: The Game of Pig Due date: Thursday, Oct. 29 th at 9pm. Late turn-in deadline is Tuesday, Nov. 3 rd at 9pm.

EE 126 Fall 2006 Midterm #1 Thursday October 6, 7 8:30pm DO NOT TURN THIS PAGE OVER UNTIL YOU ARE TOLD TO DO SO

Introduction to Counting and Probability

HW4: The Game of Pig Due date: Tuesday, Mar 15 th at 9pm. Late turn-in deadline is Thursday, Mar 17th at 9pm.

Programming Languages and Techniques Homework 3

Homework 7: Subsets Due: 10:00 PM, Oct 24, 2017

Spring 06 Assignment 2: Constraint Satisfaction Problems

Cycle Roulette The World s Best Roulette System By Mike Goodman

The Ultimate Money Making System *** Earn a Living Stealing From the Casino ***

Math Spring 2014 Proof Portfolio Instructions And Assessment

CSSE220 BomberMan programming assignment Team Project

CSC242 Intro to AI Spring 2012 Project 2: Knowledge and Reasoning Handed out: Thu Mar 1 Due: Wed Mar 21 11:59pm

1)After you click the Join Big Cash button you will be here:

Lesson 11: Linear and Exponential Investigations

Deriving the General Equation of a Circle

Compound Probability. Set Theory. Basic Definitions

Lesson 1 Area of Parallelograms

Resistive Circuits. Lab 2: Resistive Circuits ELECTRICAL ENGINEERING 42/43/100 INTRODUCTION TO MICROELECTRONIC CIRCUITS

How to Start a Blog & Use It To Squash Writer s Block

GMAT Timing Strategy Guide

CSE 312 Midterm Exam May 7, 2014

Game Engine Programming

First Lab - Sept 1st Ivan Babic CS484

Year 7A Mathematics Homework Autumn Term

Randomness Exercises

Maxima and Minima. Terminology note: Do not confuse the maximum f(a, b) (a number) with the point (a, b) where the maximum occurs.

Video Transcript. Hi, this is Don Crowther with a video about Adding Closed Captioning to Your YouTube Videos.

Composition Allsop Research Paper Checklist NOTECARDS

Ex 1: A coin is flipped. Heads, you win $1. Tails, you lose $1. What is the expected value of this game?

BIEB 143 Spring 2018 Weeks 8-10 Game Theory Lab

Week 6: Advance applications of the PIE. 17 and 19 of October, 2018

GUIDE PROSPECTING CALL CENTER SCRIPTS INCLUDED! The O2 Worldwide Call Center Prospecting Guide

Traffic Tsunami. Your Ultimate Source For GUARANTEED FREE VIRAL Traffic PRICE: $49.95

Description: PUP Math World Series Location: David Brearley High School Kenilworth, NJ Researcher: Professor Carolyn Maher

Math 65A Elementary Algebra A Exam II STUDY GUIDE and REVIEW Chapter 2, Sections 3 5, and Chapter 3, Sections 1-3

Using Google Analytics to Make Better Decisions

Math 60. : Elementary Algebra : Beginning Algebra, 12 th edition, by Lial

ENH 110: Introduction to Literature

School Based Projects

Assignment 4: Permutations and Combinations

Bernoulli Trials, Binomial and Hypergeometric Distrubutions

Math 210: 1, 2 Calculus III Spring 2008

Organizational Skills. 10 Organizational Tips:

BONUS LESSON How To Set Goals With Kindle

Lesson Plans for Christy Dempsey, Tippit Middle School Week of Monday, November 07, 2016 Monday, November 07, 2016 Day 52

Functions: Transformations and Graphs

The CENTRE for EDUCATION in MATHEMATICS and COMPUTING cemc.uwaterloo.ca Fryer Contest. Thursday, April 18, 2013

This is simply, customers looking for businesses that service their local area. Businesses like yours.

1. More on Binomial Distributions

HOW TO SUCCEED ON FIVERR: A GUIDE FOR BUYERS 1 VERSION 1.0

Design Cycle Project Example

Finite Mathematics MAT 141: Chapter 8 Notes

Congratulations, you ve just earned 5 Experience Points!

Programming Assignment 4

Objective: Determine empirical probability based on specific sample data. (AA21)

How to Make Money Selling On Amazon & Ebay! By Leon Tran

6.003: Signal Processing. Synthetic Aperture Optics

To Get You From Crayons to College.

Grade 7/8 Math Circles February 9-10, Modular Arithmetic

Discrete probability and the laws of chance

COACH DEVELOPMENT QUESTIONS & SMART GOALS

PREFACE. Money, Money, Money! The success and paradigm shift that brought forth modern Western Capitalism has

How You Can Save Hundreds Of Dollars, Make Better Use Of Your Time, And Remain Goal Oriented When Buying And Using The Right Mindmap Software Tool

CS151 - Assignment 2 Mancala Due: Tuesday March 5 at the beginning of class

What You Need to Learn

If a fair coin is tossed 10 times, what will we see? 24.61% 20.51% 20.51% 11.72% 11.72% 4.39% 4.39% 0.98% 0.98% 0.098% 0.098%

Introduction. So, let's get this moving forward, first things first, some things you will need to get up and running...

1. How many subsets are there for the set of cards in a standard playing card deck? How many subsets are there of size 8?

which all children and young people have the skills, knowledge and confidence to manage their money well, now and in the future.

Answer key to select Section 1.2 textbook exercises (If you believe I made a mistake, then please let me know ASAP) x x 50.

Expected Value, continued

Kenken For Teachers. Tom Davis January 8, Abstract

November 6, Chapter 8: Probability: The Mathematics of Chance

Free Sneak Preview From Marlon Sanders' "Action Grid System" Reveals...

November 8, Chapter 8: Probability: The Mathematics of Chance

Designing Information Devices and Systems I Fall 2016 Babak Ayazifar, Vladimir Stojanovic Homework 11

The Odds Calculators: Partial simulations vs. compact formulas By Catalin Barboianu

Homework Assignment #1

Mathematics Behind Game Shows The Best Way to Play

Chapter 9 Miscellaneous Examples

satspapers.org Year 7 mathematics test

Ch. 6 Linear Functions Notes

We're excited to announce that the next JAFX Trading Competition will soon be live!

28 content upgrades that will boost your list

Game playtesting, Gameplay metrics (Based on slides by Michael Mateas, and Chapter 9 (Playtesting) of Game Design Workshop, Tracy Fullerton)

November 11, Chapter 8: Probability: The Mathematics of Chance

Kansas City Area Teachers of Mathematics 2005 KCATM Contest PROBLEM SOLVING TEST GRADE 6

Math Matters: Why Do I Need To Know This?

Skills 360 Handling Technical Interviews (Part 1)

Intermediate report. Host University University of Massachusetts, Amherst

YEAR 9 (13+) ENTRANCE EXAMINATION. April 2016 for entry in September 2017 MATHEMATICS. Your Name: Your School:

LESSON 8. Putting It All Together. General Concepts. General Introduction. Group Activities. Sample Deals

Paid Surveys Secret. The Most Guarded Secret Top Survey Takers Cash In and Will Never Tell You! Top Secret Report. Published by Surveys & Friends

Videos get people excited, they get people educated and of course, they build trust that words on a page cannot do alone.

Creating Projects for Practical Skills

Transcription:

CSci 1113: Introduction to C/C++ Programming for Scientists and Engineers Homework 2 Spring 2018 Due Date: Thursday, Feb. 15, 2018 before 11:55pm. Instructions: This is an individual homework assignment. There are two problems worth 20 points each. Solve the problem below by yourself (unlike the labs, where you work collaboratively), and submit the solution as a C++ source code file. Here are a few more important details: 1. Unlike the computer lab exercises, this is not a collaborative assignment. 2. Because all homework assignments are submitted and tested electronically, the following are important: You follow any naming conventions mentioned in the homework instructions. You submit the correct file(s) through Moodle by the due deadline. You follow the example input and output formats exactly given in each problem description. Regardless of how or where you develop your solutions, your programs compile and execute on cselabs computers running the Linux operating system. 3. You should test your program on other test cases (that you make up) as well. Making up good test cases is a valuable programming skill, and is part of ensuring your code solution is correct. Problem A: Triangle (20 points) Draw a triangle (like shown below) with dots in the box where the triangle is not and plus symbols where the triangle is. Ask the user the size of the triangle (you can assume the number entered will be odd). Note: the height of the triangle is not the variable that the user entered. Example 1 (user input is underlined): 1 + 3.+. +++

Example 3 (user input is underlined): 13...+......+++......+++++......+++++++.....+++++++++...+++++++++++. +++++++++++++ When you are done, name the source code file <username>_2a.cpp. Here you replace smithx1234@umn.edu, your file should be named smithx1234_2a.cpp. Then submit your program using the HW 2 Problem A submission link in Moodle. Problem B: Upgrading gear (20 points) Suppose you are playing an MMO where you can upgrade your weapons and armor by spending some money. However, the system for upgrading involves both randomness and is a bit convoluted (it is not easy to mathematically find the answer to this problem... but possible). The system is as follows: There is a base chance of 20% for a successful equipment upgrade. If you fail to upgrade, however, it will cost you some money to be able to try again. To make things more complicated, each time you fail, you get a progressively higher chance of success on the next try (5% increase per each consecutive fail). For example, let the cost to upgrade be 700 coins. The first time you try to upgrade you have a 20% chance. If you fail to upgrade you have to spend 700 coins, but now you have a 25% chance of successfully upgrading. If you fail a second time, you would pay an additional 700 coins (total of 1,400 now) but your chance of success is now 30%. If you succeed in upgrading, you do not need to pay anything. Some equipment costs more or less to fix. You can take advantage of this system by building up failures on cheap equipment, then once you have a few successive failures you can try upgrading more expensive equipment (that you actually want to upgrade). Write a program to figure out how many successive fails you should receive on cheap equipment before trying to upgrade more expensive equipment. For this program you can assume, with cheap equipment, the cost of x cumulative fails is:

What your program needs to do: 1. The retry cost: Ask the user how much it costs to try again on the expensive equipment. 2. The simulation: To figure out what the best strategy is, use a simulation of one million different tries at making upgrades. For each try: Start with a fixed x value. Let the equation above determine the cost of failing to upgrade x times. Keep attempting to upgrade again (and again) until you succeed. Keep track of the costs that you are accumulating. 3. The comparison: Calculate the average costs associated with each x value. 4. The conclusion: Compare these averages and determine the most effective x value. Remember: 1. getting 0 successive failures means starting immediately with the more expensive equipment (i.e. starting with f(0) = 0 as in the first example in red below) 2. getting 16 successive failures will give you a 100% chance to succeed on the first try (but is quite expensive to get). 5. Output the minimum average cost and the corresponding x For the best strategy, show both the average cost (including how much it takes to get the original successive failures) to upgrade and how many successive failures to get before starting with the expensive equipment. Note: with one million trials, it will take your computer a bit to compute this (a few seconds). Also since these are random, the numbers won't be exact, but the first couple digits should be the same. Note2: I have added zerotoone.cpp to show how to generate a random number between zero and one (though this is pretty easily google-able). As some people are still confused, I will give a better example. Let f(x) = 500*x*1.05^x, which is the formula above. Here x represents how many consecutive fails you start out with and f(x) the cost. So, if you started trying to upgrade immediately, you would pay: Success on first attempt (20% chance to succeed) pay = 0 Success on second attempt (25% chance to succeed) pay = 1 * retry cost Success on third attempt (30% chance to succeed) pay = 2 * retry cost Success on fourth attempt (35% chance to succeed) pay = 3 * retry cost If the retry cost is high, it makes sense to build up cumulative failures using f(x) instead. Suppose you wanted to start with 3 cumulative failures to upgrade cheap equipment (f(3) = 1736.44). Then you would have the following simulation: (note the starting at 35% chance since we ve failed 3 times) Success on first attempt (35% chance to succeed) pay = 1736.44 Success on second attempt (40% chance to succeed) pay = 1736.44 + (1 * retry cost) Success on third attempt (45% chance to succeed) pay = 1736.44 + (2 * retry cost) Success on fourth attempt (50% chance to succeed) pay = 1736.44 + (3 * retry cost) TL;DR: First you need to average the cost if you start with x=0 (and 20% initial success), then average another million trials with x=1 (start at 25% success), then x=2... all the way to x=16. You then need to determine which of these x values produced the minimum average. (The first number output is the average, the second is x value associated with the minimum average.)

Example 1, fixed (user input is underlined): What is retry cost? 2000 Average cost: 4517.44 Should get successive failures: 2 What is retry cost? 100 Average cost: 242.668 Should get successive failures: 0 When you are done, name the source code file <username>_2b.cpp. Here you replace smithx1234@umn.edu, your file should be named smithx1234_2b.cpp. Then submit your program using the HW 2 Problem B submission link in Moodle. Problem C: Triangle of Power (5 points, extra credit) Modify your code from part A to make a triforce (each part of the triforce should be the triangles you made from part A). Example 1 (user input is underlined): 1.+. +.+ 3...+.....+++...+...+. +++.+++

Example 3 (user input is underlined): 13...+......+++......+++++......+++++++......+++++++++......+++++++++++......+++++++++++++......+...+......+++...+++......+++++...+++++......+++++++...+++++++.....+++++++++...+++++++++...+++++++++++...+++++++++++. +++++++++++++.+++++++++++++ When you are done, name the source code file <username>_2c.cpp. Here you replace smithx1234@umn.edu, your file should be named smithx1234_2c.cpp. Then submit your program using the HW 2 Problem C submission link in Moodle.