首页
网站开发
桌面应用
管理软件
微信开发
App开发
嵌入式软件
工具软件
数据采集与分析
其他
首页
>
> 详细
代写program、代做c/c++语言编程
项目预算:
开发周期:
发布时间:
要求地区:
Computation and Programming
2024
Project – Playing with Hailstone Numbers
The project has two parts:
• Building a program that allows the user to explore some features of the number sequences
related to the Collatz Conjecture.
• The implementation of a simple game related to the Collatz conjecture.
The Collatz Conjecture
The Collatz Conjecture (named after Lothar Collatz, who introduced it in 1937), also known as the 3x+1
problem, states that, starting with any positive integer, x, and applying two simple operations (if the
number is even, divide it by 2; if the number is odd, multiply it by 3 and add 1), number 1 will eventually
be reached.
In a more rigorous way, we can define the Collatz function, C, as:
And so, the Collatz Conjecture states that “starting from any positive integer n, iterations of the function
C(x) will eventually reach the number 1”.
Some examples:
• Starting with 6, we get the sequence: 6 - 3 - 10 - 5 - 16 - 8 - 4 - 2 - 1
• Starting with 7: 7- 22 - 11 - 34 - 17 - 52 - 26 - 13 - 40 - 20 - 10 - 5 - 16 - 8 - 4 - 2 – 1
• Starting with 13: 13 – 40 – 20 – 10 – 5 – 16 – 8 – 4 – 2 – 1
• Starting with 15: 15 - 46 - 23 - 70 - 35 - 106 - 53 - 160 - 80 - 40 - 20 - 10 - 5 - 16 - 8 - 4 - 2 – 1
• Starting with 84: 84 – 42 – 21 – 64 – 32 – 16 – 8 – 4 – 2 – 1
Note that these sequences are infinite (looping 1-4-2-1-4-2-1-4-2-1-…), but we are only considering them
until number 1 is reached for the first time.
One of the interesting things about this conjecture is that, although very simple to characterize, it has
never been proved. But we can explore some of these sequences and try to discover some curious things
about these hailstone numbers (another name for the numbers in these sequences). CP 2024 - Project
CP 2024 – Project – Playing with hailstone numbers 2
1. Exploring [70 points]
In this first part, you must build a program that presents a Main Menu and allows the user to choose one
of the options. Each option corresponds to some experiment regarding the sequences of hailstone
numbers.
The presentation of the main menu may be similar to the following.
****** Main Menu ******
1 - Display a sequence
2 - Display a sequence + properties
3 - Display bar chart for a range of numbers
4 - Test Benford's law for one number
5 - Test Benford's law for a range
9 - Exit the program
Which option?
The description of what is the expected behavior for each option is detailed in the following sections.
After executing the chosen option, the menu should be presented again. The program should end when
the user chooses option 9 (exit).
Option 1 – Display a sequence
In this option the user should have the possibility of choosing a number and the program should present
its trajectory (the sequence until 1 is reached). For instance:
Which option? 1
Enter a number (<= 100000): 17
The trajectory for 17 is:
17 - 52 - 26 - 13 - 40 - 20 - 10 - 5 - 16 - 8 - 4 - 2 - 1
To accomplish this, you should start by defining a function next that, given a number, returns the next
number in the sequence. Consider this prototype:
long next(long number) ;
Then, you can define a function, printSequence, to print the trajectory generated for the given
number:
void printSequence(long number) ;
CP 2024 - Project
CP 2024 – Project – Playing with hailstone numbers 3
Option 2 – Display a sequence and its properties
Besides presenting the trajectory, like in the previous option, here the program should also present some
of its properties, namely:
• Its height (the number of elements in the trajectory, until it reaches 1).
• Its stopping time (the first step at which the number in the sequence gets smaller than the
original number).
• The maximum number in the trajectory.
• The number of odd numbers in the trajectory.
• The maximum number of consecutive even numbers.
Start by defining a function, buildSequence, that, given a number, generates a sequence, stores it in
an array and returns its size (height). Then, build a function, displaySequenceProperties, that
takes a sequence and its size and displays the sequence and all the above-mentioned properties.
Consider the following prototypes for these functions:
int buildSequence(long number, long seq[]);
void printSeqProperties(long sequence[], int size);
The expected behavior for this option is similar to the following:
Which option? 2
Enter a number (<= 100000): 19
The trajectory for 19 is:
19 - 58 - 29 - 88 - 44 - 22 - 11 - 34 - 17 - 52 - 26 - 13 - 40 - 20 - 10 - 5
- 16 - 8 - 4 - 2 – 1
Height: 21
Stopping time: 7
Maximum number in trajectory: 88
Number of odd numbers in trajectory: 7
Maximum consecutive even numbers: 4
Note that the trajectory has 21 elements, the first element smaller than 19 is the 7
th
(11), the maximum
number that occurs is 88, there are 7 odd numbers (19, 29, 11, 17, 13, 5, and 1) and the longest
sequence of consecutive even numbers has size 4 (16-8-4-2, near the end).
Option 3 – Display stats for a range of numbers
In this option, the user should be asked for two numbers that define a non-empty range (the second
must be greater or equal than the first).
Then, the program must present a horizontal bar chart that includes, for each line (each number in the
range):
• The number
• The height of its trajectory
• A bar with stars (‘*’) representing that height. CP 2024 - Project
CP 2024 – Project – Playing with hailstone numbers 4
Besides, as there is a great disparity between the lengths of different numbers, the bars should be
scaled, if necessary, so that they fit in 50 columns (or whatever other limit you define) maintaining their
relative proportionality.
An example of the expected behavior:
Which option? 3
Enter the two integer numbers that define the range: 235 250
Number | Height | Bar
Option 4 – Test the Benford’s Law
In many real-life sets of numbers, the distribution of the leading digit (most significant one) follows a
particular distribution:
According to this distribution, number 1 occurs as a leading digit 30.1% of the times, number 2, 17.6%,
and so on (exact definition bellow). This is called the Benford’s Law (named after Frank Benford, who
stated it in 1938). This law states that when a set of numbers follows it, the probability of a digit d (d
{1, 2, …, 9}) appearing as a leading one is given by
( ) = log10 (1 +
1
) CP 2024 - Project
CP 2024 – Project – Playing with hailstone numbers 5
In this option your program should apply the Goodness of Fit test to verify that the hailstone numbers
follow the Benford’s law.
The program should do the following:
• Ask for a number
• Present its trajectory
• Present the digits counting (how many times each digit appears in the first position)
• Verify if the
2
Goodness of fit test can be applied to verify if the observed distribution of digits
follows Benford’s Law.
o (refer to slide 28, part VII, of the Probability and Statistics course)
• If the test cannot be applied, just print a message.
• If the test can be applied, calculate the T statistics, and decide to reject (or not) the null
hypothesis (H0: the observations follow the distribution of the Benford’s Law) with a confidence
of 95%.
Let’s see two examples of the expected behavior. The first, for a number for which its trajectory does not
have enough elements to apply the test:
Which option? 4
Enter a number (<= 100000): 19
The trajectory for 19 is:
19 - 58 - 29 - 88 - 44 - 22 - 11 - 34 - 17 - 52 - 26 - 13 - 40 - 20 -
10 - 5 - 16 - 8 - 4 - 2 - 1
Digit counting and percentages
1 - 7 - 33.33
2 - 5 - 23.81
3 - 1 - 4.76
4 - 3 - 14.29
5 - 3 - 14.29
6 - 0 - 0.00
7 - 0 - 0.00
8 - 2 - 9.52
9 - 0 - 0.00
The sequence for number 19 does not satisfy the applicability
conditions.
CP 2024 - Project
CP 2024 – Project – Playing with hailstone numbers 6
Now an example for which the test can be applied:
Which option? 4
Enter a number (<= 100000): 31
The trajectory for 31 is:
31 - 94 - 47 - 142 - 71 - 214 - 107 - 322 - 161 - 484 - 242 - 121 - 364
- 182 - 91 - 274 - 137 - 412 - 206 - 103 - 310 - 155 - 466 - 233 - 700
- 350 - 175 - 526 - 263 - 790 - 395 - 1186 - 593 - 1780 - 890 - 445 -
1336 - 668 - 334 - 167 - 502 - 251 - 754 - 377 - 1132 - 566 - 283 - 850
- 425 - 1276 - 638 - 319 - 958 - 479 - 1438 - 719 - 2158 - 1079 - 3238
- 1619 - 4858 - 2429 - 7288 - 3644 - 1822 - 911 - 2734 - 1367 - 4102 -
2051 - 6154 - 3077 - 9232 - 4616 - 2308 - 1154 - 577 - 1732 - 866 - 433
- 1300 - 650 - 325 - 976 - 488 - 244 - 122 - 61 - 184 - 92 - 46 - 23 -
70 - 35 - 106 - 53 - 160 - 80 - 40 - 20 - 10 - 5 - 16 - 8 - 4 - 2 - 1
Digit counting and percentages:
1 - 30 - 28.04
2 - 17 - 15.89
3 - 14 - 13.08
4 - 15 - 14.02
5 - 7 - 6.54
6 - 5 - 4.67
7 - 7 - 6.54
8 - 5 - 4.67
9 - 7 - 6.54
Tstat = 4.385
H0 is not rejected.
According to the Chi-Squared distribution table, with 8 degrees of freedom, and a significance level (α) of
0.05, H0 is rejected when the value of the T statistics is greater than 15.507.
CP 2024 - Project
CP 2024 – Project – Playing with hailstone numbers 7
Option 5 – Test the Benford’s Law for a range
In this option, the program must present aggregate results regarding the applicability of the Goodness of
Fit test and its results for the digits distribution of the hailstone sequences for a range of numbers
provided by the user.
So, the program must:
• Ask the user for the two integers that define the range.
• Calculate the values to be presented.
• Display the following aggregate results:
o Number of values in the range for which the Goodness of fit test can be applied
o Number of values for which the value of the statistics means that the H0 is not rejected.
o Average value of the T statistics
An example:
Which option? 5
Enter two integer numbers: 1 100000
The test can be applied for 51873 numbers ( 51.8730%).
The null hypothesis is not rejected for 51871 of those numbers ( 99.9961%).
The average value of the statistics is 3.485.
Another example:
Which option? 5
Enter two integer numbers: 1000 2000
The test can be applied for 328 numbers ( 32.7672%).
The null hypothesis is not rejected for 328 of those numbers (100.0000%).
The average value of the statistics is 3.555.
2. Playing [30 points]
The second program of your project is the implementation of a very simple game.
The game consists of guessing the next number in the Collatz sequence, given a number randomly
generated by the computer. The game should have the following properties:
• The program must ask first for the range from which to generate the random numbers.
• Then, the program must ask for a limit in the number of plays.
• The game begins and in each play:
o The program presents to the user a randomly generated number .
o The user should guess the number that follows the number presented, according to the
Collatz function.
o The program presents the result (the guess was correct or not) and asks the user if
he/she wants to play another time or end the game. CP 2024 - Project
CP 2024 – Project – Playing with hailstone numbers 8
• When the game ends, either because the limit of plays was reached or because of the user
choice, the results should be presented. These include:
o The total number of guesses
o The number of correct guesses
o The score (percentage of correct guesses)
o The list of numbers for which the user failed to guess
An example:
Let's play a game!
*******************
Enter two integers representing the range of possible values
to be randomly generated by the program: 50 100
Enter the maximum number of plays: 3
(You can end before, by answering "no" when asked for another try.)
***** Let's START ****
The number is 82.
What is the next number? 41
CORRECT!
Another try (write "no" to stop)? y
The number is 97.
What is the next number? 292
CORRECT!
Another try (write "no" to stop)? y
The number is 71.
What is the next number? 214
CORRECT!
The maximum number of plays have been reached. Let's see your results!
Results
+++++++
Games Played: 3
Games Won: 3
Your Score: 100.00%
Congratulations!! You guessed all numbers correctly! CP 2024 - Project
CP 2024 – Project – Playing with hailstone numbers 9
Another example of execution:
Let's play a game!
*******************
Enter two integers representing the range of possible values
to be randomly generated by the program: 1 100000
Enter the maximum number of plays: 20
(You can end before, by answering "no" when asked for another try.)
***** Let's START ****
The number is 31496.
What is the next number? 15748
CORRECT!
Another try (write "no" to stop)? y
The number is 26593.
What is the next number? 79780
CORRECT!
Another try (write "no" to stop)? y
The number is 26711.
What is the next number? 80133
Incorrect! The number after 26711 is 80134.
Another try (write "no" to stop)? y
The number is 3297.
What is the next number? 9892
CORRECT!
Another try (write "no" to stop)? y
The number is 31926.
What is the next number? 15963
CORRECT!
Another try (write "no" to stop)? y
The number is 26449.
What is the next number? 78348
Incorrect! The number after 26449 is 79348.
Another try (write "no" to stop)? no
Results
+++++++
Games Played: 6
Games Won: 4
Your Score: 66.67%
You failed to guess the next for the following numbers:
26711 26449
CP 2024 - Project
CP 2024 – Project – Playing with hailstone numbers 10
Final Remarks
Submitting your work
Projects should be done in groups of 4 students.
You should submit a zip file containing:
• Your two programs (two files: collatz-main.c and collatz-game.c)
o These two files should include, as comments, the student numbers and names of the
elements of the group
• A document containing the identification of the group. For each member of the group, you
should identify:
o Student number
o Chinese name
o Name in English
• A document with a copy of the execution of the program (copy/paste of the output)
Submission is made through the elearning platform in a link that will be provided in a few days.
It is enough that one of the elements of the group submits the zip file.
Deadline for submission:
27 October 2024
软件开发、广告设计客服
QQ:99515681
邮箱:99515681@qq.com
工作时间:8:00-23:00
微信:codinghelp
热点项目
更多
代做 program、代写 c++设计程...
2024-12-23
comp2012j 代写、代做 java 设...
2024-12-23
代做 data 编程、代写 python/...
2024-12-23
代做en.553.413-613 applied s...
2024-12-23
代做steady-state analvsis代做...
2024-12-23
代写photo essay of a deciduo...
2024-12-23
代写gpa analyzer调试c/c++语言
2024-12-23
代做comp 330 (fall 2024): as...
2024-12-23
代写pstat 160a fall 2024 - a...
2024-12-23
代做pstat 160a: stochastic p...
2024-12-23
代做7ssgn110 environmental d...
2024-12-23
代做compsci 4039 programming...
2024-12-23
代做lab exercise 8: dictiona...
2024-12-23
热点标签
mktg2509
csci 2600
38170
lng302
csse3010
phas3226
77938
arch1162
engn4536/engn6536
acx5903
comp151101
phl245
cse12
comp9312
stat3016/6016
phas0038
comp2140
6qqmb312
xjco3011
rest0005
ematm0051
5qqmn219
lubs5062m
eee8155
cege0100
eap033
artd1109
mat246
etc3430
ecmm462
mis102
inft6800
ddes9903
comp6521
comp9517
comp3331/9331
comp4337
comp6008
comp9414
bu.231.790.81
man00150m
csb352h
math1041
eengm4100
isys1002
08
6057cem
mktg3504
mthm036
mtrx1701
mth3241
eeee3086
cmp-7038b
cmp-7000a
ints4010
econ2151
infs5710
fins5516
fin3309
fins5510
gsoe9340
math2007
math2036
soee5010
mark3088
infs3605
elec9714
comp2271
ma214
comp2211
infs3604
600426
sit254
acct3091
bbt405
msin0116
com107/com113
mark5826
sit120
comp9021
eco2101
eeen40700
cs253
ece3114
ecmm447
chns3000
math377
itd102
comp9444
comp(2041|9044)
econ0060
econ7230
mgt001371
ecs-323
cs6250
mgdi60012
mdia2012
comm221001
comm5000
ma1008
engl642
econ241
com333
math367
mis201
nbs-7041x
meek16104
econ2003
comm1190
mbas902
comp-1027
dpst1091
comp7315
eppd1033
m06
ee3025
msci231
bb113/bbs1063
fc709
comp3425
comp9417
econ42915
cb9101
math1102e
chme0017
fc307
mkt60104
5522usst
litr1-uc6201.200
ee1102
cosc2803
math39512
omp9727
int2067/int5051
bsb151
mgt253
fc021
babs2202
mis2002s
phya21
18-213
cege0012
mdia1002
math38032
mech5125
07
cisc102
mgx3110
cs240
11175
fin3020s
eco3420
ictten622
comp9727
cpt111
de114102d
mgm320h5s
bafi1019
math21112
efim20036
mn-3503
fins5568
110.807
bcpm000028
info6030
bma0092
bcpm0054
math20212
ce335
cs365
cenv6141
ftec5580
math2010
ec3450
comm1170
ecmt1010
csci-ua.0480-003
econ12-200
ib3960
ectb60h3f
cs247—assignment
tk3163
ics3u
ib3j80
comp20008
comp9334
eppd1063
acct2343
cct109
isys1055/3412
math350-real
math2014
eec180
stat141b
econ2101
msinm014/msing014/msing014b
fit2004
comp643
bu1002
cm2030
联系我们
- QQ: 9951568
© 2021
www.rj363.com
软件定制开发网!