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

  What is a salt in the context of unix password managemet

What is a salt in the context of UNIX password management? List and briefly define four techniques used to avoid guessable passwords.

  Write the missing number game program

Write the Missing Number Game Program. You will write a program that will allow a user to play the missing number game.  The game will display a 4 (rows) x 3 (columns) board of numbers that will be predetermined

  Programming features for each individual language

A brief discussion document based on these programming features for each individual language accompanying each implementation is required.

  Write a pascal program cross-referencer which will produce

Write a Pascal program cross-referencer which will produce, for a given Pascal program, a list in alphabetical order, of all the identifiers used.

  Draw class diagram showing relationship among the classes

ou are required to develop program as below by applying OOP principles and constructs: Draw the class diagram showing the relationship among the classes

  Program that satisfies requirements of programming project

Write a program that satisfies the requirements of Programming Project 2 of Hanly, and that uses the following modifications and tips -Use the COLOR_CODES string array.

  Determines which numbers produce a happy sequence

Write a program that determines which numbers produce a happy sequence, within a series of test numbers

  Design program which models worms behavior

Design a program that models the worms behavior in the following scenario: A worm is moving toward an apple. Each time it moves, the worm cuts the distance between itself and the apple.

  Utilizes a good design process and incorporates sequential

Your final project will be to analyze, design, and document a simple program that utilizes a good design process and incorporates sequential, selection and repetitive programming statements.

  Assignment on the two-dimensional array sales

Use a two-dimensional array to solve the following problem: A company has four salespeople (1 to 4) who sell five different products (1 to 5). Once a day, each salesperson passesin a slip for each type of product sold. Each slip contains the follo..

  Create an application to calculate sales persons salary

a salesperson who grosses $5000 in sales in a week receives $150 plus 10% of $5000, a total of $650. Write an application that calculate each sales person's total salary per week.

  Write function template that accepts array

Write a function template arraySum () whihc accepts an array and number of values stored in it and returns sum of those values.

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