Define a function splithex which takes as input

Assignment Help Programming Languages
Reference no: EM133382929

Define the SplitHex function

Here we define a function SplitHex which takes as input a single positive integer input n. The function then calculates a positive integer output as follows:

(a)Convert n to hexadecimal form, call it H. You may use the hex( ) function.

Split H into two "halves", call them F and S, where if the length of H is odd, then include the extra digit in the first half. For example, if H = 1B5AC9, then the first half is F = 1B5 and the second half is S = AC9. As another example, if B = 6CB, then the first half is F = 6C and the second half is S = B. Note: If H has only one digit, then F will be that single digit and S = 0.
Convert F and S to decimal form, add 16 to the decimal form of F and 1 to the decimal form of S, and then return the product of these new values.
As a full example, consider n = 62.

(a)Converting n to hexadecimal form, we have H = 3E

(b)Then F = 3 and S = E

Converting them back to decimal form, we have the decimal values 3 and 14. Finally, we return the product (3+16)*(14+1) = 285.
Therefore SplitHex(62) should return 285. At the bottom, there are further examples of the

SplitHex function.

Define the SplitHexSequence function
The final step!
If the list created by SplitHexSequence has 20 elements in it, then the function will stop adding more elements and return the list with those 20 elements; or
If the last element added to the list is a duplicate of one of the previous terms in the list, then that duplicated element will be added to the list and the list will be returned in its current form.
ADD COMMENTS to clarify your choice of variables and to indicate what is happening at different steps of the program. A good rule of thumb is one line of comments for every four to five lines of code. Your comments will be checked to see that you understand how your code is structured and what it is doing in the big picture. Code lacking in comments will be penalized!
We can use SplitHex( ) to turn one integer into another. We can iterate this process over and over, generating a sequence of positive integers. For example, if we start with the positive inte- ger 62, then SplitHex(62) = 285. Then SplitHex(285) = 462, and SplitHex(462) = 660, and so on. This creates the sequence 62, 285, 462, 660,............................................ This sequence we will call

the Split Hex Sequence starting with 62.

In your project1.py script, you will create a function called SplitHexSequence which takes one positive integer input n. The function then returns a list of the elements in the Split Hex Sequence (defined above) with the following conditions:


Using the example above, the Split Hex Sequence for 62 begins as 62, 285, 462, 660, 285 and since the last element is a duplicate of a previous entry, then SplitHexSequence(62) would return the list [62, 285, 462, 660, 285]. Further examples of the SplitHexSequence func- tion are given below.

EXAMPLES To test that your SplitHex function is working properly, here are some examples of the output:

n

SplitHex(n)

4

20

16

17

22

119

29

238

62

285

67

80

79

320

80

21

100

110

To test that your SplitHexSequence function is working properly, here are some examples of the output:

n

SplitHexSequence(n)

4

[4, 20, 85, 126, 345, 370, 117, 138, 264, 288, 34, 54, 133, 144, 25, 170, 286, 495, 736, 62, 285]

16

[16, 17, 34, 54, 133, 144, 25, 170, 286, 495, 736, 62, 285, 462, 660, 285]

22

[22, 119, 184, 243, 124, 299, 408, 369, 78, 300, 442, 473, 450, 132, 120, 207, 448, 44, 234, 330]

29

[29, 238, 450, 132, 120, 207, 448, 44, 234, 330, 396, 520, 432, 43, 216, 261, 192, 28, 221, 406]

62

[62, 285, 462, 660, 285]

67

[67, 80, 21, 102, 154, 275, 132, 120, 207, 448, 44, 234, 330, 396, 520, 432, 43, 216, 261, 192]

79

[79, 320, 36, 90, 231, 240, 31, 272, 33, 36]

80

[80, 21, 102, 154, 275, 132, 120, 207, 448, 44, 234, 330, 396, 520, 432, 43, 216, 261, 192, 28]

100

[100, 110, 330, 396, 520, 432, 43, 216, 261, 192, 28, 221, 406, 287, 528, 49, 38, 126, 345, 370]

BONUS This part should only be completed after you have completed the project1.py file described above. You are going to alter the code for the SplitHexSequence function so it is advised that you create a separate Python file than project1.py so you don't mess up your code that you will submit to Gradescope.

In the project1.py file, the SplitHexSequence function halted after 20 elements were added to the list, but the sequence could continue past that until it found a duplicate.

Assume the SplitHexSequence function would keep adding elements to the list until a duplicate was found instead of stopping at 20 elements. If we adjust the SplitHexSequence function to account for this change, then it turns out that the first positive integer whose Split Hex Sequence contains exactly 20 elements is the input 11.

Here are the bonus questions:

(+2 points) What is the smallest positive integer where the length of the SplitHexSequence
(+5 points) What is the smallest positive integer where the length of the SplitHexSequence
(+5 points) If you create a list from the final element of each SplitHexSequence from 1 to 100,000, then you will get a list that contains 21 elements. What are those 21 elements (in increasing order)?
is exactly 30 elements?

is exactly 80 elements?

If you partake in the Bonus questions, you will re-submit to Gradescope your original project1.py file along with one text file called project1-bonus.txt. This new text file document should have an honesty statement at the top:

Reference no: EM133382929

Questions Cloud

Perform research and write a paper about cultural intellige : ITM-473: Global Information Technology Projects, Indiana Wesleyan University - perform research and write a paper about CQ; the focus will be on its application
What are the two purposes of sex, according to de young : What are the two purposes of sex, according to De Young? According to De Young, how does lust deform our sexual actions from the above purposes?
How data centers and networking works across time zones : How data centers and networking works across time zones. Think about having meetings across time zones or a zoom meeting. Think about outsourcing and how time
What would the susan isnaac philosophy presented in class : What would the susan Isnaac philosophy presented in class have to say about the play scenario of beloved everlasting memory What is the theorist's view
Define a function splithex which takes as input : define a function SplitHex which takes as input a single positive integer input n. The function then calculates a positive integer output
Reflecting on the differences between logical positivism : Reflecting on the differences between Logical Positivism to Logical Empiricism, as well as the logical empiricist's argument for "almost positivism,"
Define business problems that can be solved : Define business problems that can be solved by using basic programming concepts and standards. Perform arithmetic calculations using expressions in C
Perform arithmetic calculations using expressions in c : Write logical, syntactically correct C programs that use proper variables to perform arithmetic calculations. Interact with the user via text in the terminal
Explain how hume argues from this claim to the conclusion : What does Hume mean when he says that 'reason is the slave of the passions'? Explain how Hume argues from this claim to the conclusion we do not discover moral

Reviews

Write a Review

Programming Languages Questions & Answers

  Write a haskell program to calculates a balanced partition

Write a program in Haskell which calculates a balanced partition of N items where each item has a value between 0 and K such that the difference b/w the sum of the values of first partition,

  Create an application to run in the amazon ec2 service

In this project you will create an application to run in the Amazon EC2 service and you will also create a client that can run on local machine and access your application.

  Explain the process to develop a web page locally

Explain the process to develop a Web page locally

  Write functions

These 14 questions covers java class, Array, link list , generic class.

  Programming assignment

If the user wants to read the input from a file, then the output will also go into a different file . If the user wants to read the input interactively, then the output will go to the screen .

  Write a prolog program using swi proglog

Write a Prolog program using swi proglog

  Create a custom application using eclipse

Create a custom Application Using Eclipse Android Development

  Create a application using the mvc architecture

create a application using the MVC architecture. No scripting elements are allowed in JSP pages.

  Develops bespoke solutions for the rubber industry

Develops bespoke solutions for the rubber industry

  Design a program that models the worms behavior

Design a program that models the worm's behavior.

  Writing a class

Build a class for a type called Fraction

  Design a program that assigns seats on an airplane

Write a program that allows an instructor to keep a grade book and also design and implement a program that assigns seats on an airplane.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd