
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Question
![Problem 1
Write a function
count 123 : int list -> int * int * int
that takes in an int list 1 and returns a 3-tuple of integers counting the number of 1's, 2's and 3's respectively in 1. For example, count123 [3; 4;2;1;3]
= (1,1,2), and
count123 [4; 4; 1; 2; 1]
(2,1,0).
In [] let count 123 1 =
(* YOUR CODE HERE *)
In [ ]: assert (count123 [3; 4; 2; 1;3]
=
=
(1,1,2))](https://content.bartleby.com/qna-images/question/95a918cc-648a-4ba1-8333-a4ee16085cbc/f7e42b44-577f-480d-abb2-9d48c7bdfa2e/6tc8cs9_thumbnail.png)
Transcribed Image Text:Problem 1
Write a function
count 123 : int list -> int * int * int
that takes in an int list 1 and returns a 3-tuple of integers counting the number of 1's, 2's and 3's respectively in 1. For example, count123 [3; 4;2;1;3]
= (1,1,2), and
count123 [4; 4; 1; 2; 1]
(2,1,0).
In [] let count 123 1 =
(* YOUR CODE HERE *)
In [ ]: assert (count123 [3; 4; 2; 1;3]
=
=
(1,1,2))
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 3 steps with 2 images

Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question
Could you implement this in OCAML:
Here's the question again:
Write a function: count123:intlist->int*int*int
that takes in an int list l and returns a 3-tuple of integers counting the number of 1's, 2's and 3's respectively in l. For example, count123 [3;4;2;1;3] = (1,1,2), and count123 [4;4;1;2;1] = (2,1,0).
In [ ]:
letcount123l=(* YOUR CODE HERE *)
In [ ]:
assert (count123 [3;4;2;1;3] = (1,1,2)).
The code in Python is in the attached image, which needs to be implemented in OCAML.
Thanks!
![count123.py > ...
1 def count123(1st):
NP
2
3
4
5
6
7
8
9
10
11
SE
one_count = 0
two_count = 0
three_count
for i in 1st:
if i == 1:
elif i
= 0
one_count += 1
2:
two_count += 1
elif i
12
13
14
15
16
17
print(count123([3,4,2,1,3]))
18
19 print(count123([4,4,1,2,1]))
20
3:
three_count += 1
return (one_count, two_count, three_count)
86 A 90 Live Share
==
Ln 20, Col 1 Spaces: 4 UTF-8 CRLF {Python
3.10.4 64-bit
B.
M
N
Go Live Q](https://content.bartleby.com/qna-images/question/eb3095d4-472d-42c8-847a-ae9732c32b9b/46804436-b912-4636-bfbb-283c81268325/xiw4zfa_thumbnail.png)
Transcribed Image Text:count123.py > ...
1 def count123(1st):
NP
2
3
4
5
6
7
8
9
10
11
SE
one_count = 0
two_count = 0
three_count
for i in 1st:
if i == 1:
elif i
= 0
one_count += 1
2:
two_count += 1
elif i
12
13
14
15
16
17
print(count123([3,4,2,1,3]))
18
19 print(count123([4,4,1,2,1]))
20
3:
three_count += 1
return (one_count, two_count, three_count)
86 A 90 Live Share
==
Ln 20, Col 1 Spaces: 4 UTF-8 CRLF {Python
3.10.4 64-bit
B.
M
N
Go Live Q
Solution
by Bartleby Expert
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question
Could you implement this in OCAML:
Here's the question again:
Write a function: count123:intlist->int*int*int
that takes in an int list l and returns a 3-tuple of integers counting the number of 1's, 2's and 3's respectively in l. For example, count123 [3;4;2;1;3] = (1,1,2), and count123 [4;4;1;2;1] = (2,1,0).
In [ ]:
letcount123l=(* YOUR CODE HERE *)
In [ ]:
assert (count123 [3;4;2;1;3] = (1,1,2)).
The code in Python is in the attached image, which needs to be implemented in OCAML.
Thanks!
![count123.py > ...
1 def count123(1st):
NP
2
3
4
5
6
7
8
9
10
11
SE
one_count = 0
two_count = 0
three_count
for i in 1st:
if i == 1:
elif i
= 0
one_count += 1
2:
two_count += 1
elif i
12
13
14
15
16
17
print(count123([3,4,2,1,3]))
18
19 print(count123([4,4,1,2,1]))
20
3:
three_count += 1
return (one_count, two_count, three_count)
86 A 90 Live Share
==
Ln 20, Col 1 Spaces: 4 UTF-8 CRLF {Python
3.10.4 64-bit
B.
M
N
Go Live Q](https://content.bartleby.com/qna-images/question/eb3095d4-472d-42c8-847a-ae9732c32b9b/46804436-b912-4636-bfbb-283c81268325/xiw4zfa_thumbnail.png)
Transcribed Image Text:count123.py > ...
1 def count123(1st):
NP
2
3
4
5
6
7
8
9
10
11
SE
one_count = 0
two_count = 0
three_count
for i in 1st:
if i == 1:
elif i
= 0
one_count += 1
2:
two_count += 1
elif i
12
13
14
15
16
17
print(count123([3,4,2,1,3]))
18
19 print(count123([4,4,1,2,1]))
20
3:
three_count += 1
return (one_count, two_count, three_count)
86 A 90 Live Share
==
Ln 20, Col 1 Spaces: 4 UTF-8 CRLF {Python
3.10.4 64-bit
B.
M
N
Go Live Q
Solution
by Bartleby Expert
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- Write a function called find_duplicates which accepts one list as a parameter. This function needs to sort through the list passed to it and find values that are duplicated in the list. The duplicated values should be compiled into another list which the function will return. No matter how many times a word is duplicated, it should only be added once to the duplicates list. NB: Only write the function. Do not call it. For example: Test Result random_words = ("remember","snakes","nappy","rough","dusty","judicious","brainy","shop","light","straw","quickest", "adventurous","yielding","grandiose","replace","fat","wipe","happy","brainy","shop","light","straw", "quickest","adventurous","yielding","grandiose","motion","gaudy","precede","medical","park","flowers", "noiseless","blade","hanging","whistle","event","slip") print(find_duplicates(sorted(random_words))) ['adventurous', 'brainy', 'grandiose', 'light', 'quickest', 'shop', 'straw', 'yielding']…arrow_forwardExercise 3 Write a function called middle that takes a list and returns a new list that contains all but the first and last elements. For example: >>> t = [1, 2, 3, 4] >>> middle(t) [2, 3]arrow_forwardUsing c++ Contact list: Binary Search A contact list is a place where you can store a specific contact with other associated information such as a phone number, email address, birthday, etc. Write a program that first takes as input an integer N that represents the number of word pairs in the list to follow. Word pairs consist of a name and a phone number (both strings). That list is followed by a name, and your program should output the phone number associated with that name. Define and call the following function. The return value of FindContact is the index of the contact with the provided contact name. If the name is not found, the function should return -1 This function should use binary search. Modify the algorithm to output the count of how many comparisons using == with the contactName were performed during the search, before it returns the index (or -1). int FindContact(ContactInfo contacts[], int size, string contactName) Ex: If the input is: 3 Frank 867-5309 Joe…arrow_forward
- Python data structures: write a function that takes in a list (L) as input, and returns the number of inversions. An inversion in L is a pair of elements x and y such that x appears before y in L, but x > y. Your function must run in -place and implement the best possible algoritm of time complexity. def inversions(L: List) -> int:'''finds and returns number of inversions'''arrow_forwardrite a function numPairs that accepts two arguments, a target number and a list of numbers. The function then returns the count of pairs of numbers from the list that sum to the target number. In the first example the answer is 2 because the pairs (0,3) and (1,2) both sum to 3. The pair can be two of the same number, e.g. (2,2) but only if the two 2’s are separate twos in the list.In the last example below, there are three 2’s, so there are three different pairs (2,2) so there are 5 pairs total that sum to 4. Sample usage: >> numPairs( 3, [0,1,2,3] )2arrow_forwardIn pythonarrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education

Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON

Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education