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
Write a function in Ocaml.
count123 : int list -> 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).
let count123 l = (* YOUR CODE HERE *)
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 2 steps with 2 images
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
- OCAML Programming Write down the functionval nextpascalrow: int list -> int list = <fun>which receives as input a list of numbers representing the current row of the Pascal triangle, and returns as an output a list representing the next row of Pascal's triangle.# nextpascalrow [1; 6; 15; 20; 15; 6; 1] ;;-: int list = [1; 7; 21; 35; 35; 21; 7; 1]arrow_forwardF# Explain in detail what this function does and what the result is. let ip L1 L2 = List.map2 (*) L1 L2 |> List.sum printfn "%A" (ip [1;2;3][4;5;6]) %3D whnarrow_forwardWrite the implementations of functionscopy1 and copy2 for copying strings. copy1 uses array index notation. copy2 uses Pointers andPointer Arithmetic.#include <stdio.h>#define SIZE 10void copy1(char* s1, const char* s2); // prototypevoid copy2(char* s1, const char* s2); // prototypeint main(void){char string1[SIZE]; // create array string1char *string2 = "Hello"; // create a pointer to a stringcopy1(string1, string2);printf("string1 = %s\n", string1);char string3[SIZE]; // create array string3char string4[] = "Good Bye"; // create an array containing a stringcopy2(string3, string4);printf("string3 = %s\n", string3);}void copy1(char* s1, const char* s2){//Implement copying string using array index notation}void copy2(char* s1, const char* s2){//Implement copying string using Pointers and Pointer Arithmetic }arrow_forward
- Language: Python 3 Autocomplete Ready O 4. Pair Of Elements having Smallest Absolute Difference 1 v import ast lst = input() 2 3 lst = ast.literal_eval (lst) 4 Given a list of unsorted integers. Find the pair of elements that have the smallest absolute difference between them. If there are multiple pairs, find them all. 5 6 print(smallest_absdiff_pairs(lst)) Implement a function smallest_absdiff_pairs that take a list of numbers and returns a list of pair of elements that have the smallest absolute difference between them. >>> smallest_absdiff_pairs([5, 4, 3, 2]) [(2, 3), (3, 4), (4, 5)] >>> smallest_absdiff_pairs([-20, -3916237, -357920, -3620601, 7374819, -7330761, 30, 6246457, -6461594, 266854, -520, -470]) [(-520, -470), (-20, 30)] >>> smallest_absdiff_pairs([-20, -3916237, -357920, -3620601, 7374819, -7330761, 30, 6246457, -6461594, 266854]) [(-20, 30)]arrow_forwardWrite a function val nextpascalrow : int list -> int list = <fun> that given a list of integers that correspond to a row of the pascal triangle, it calculates the next row of the pascal triangle. # nextpascalrow [1; 6; 15; 20; 15; 6; 1];; - : int list = [1; 7; 21; 35; 35; 21; 7; 1]arrow_forwardOCAML Problemarrow_forward
- Write a function in Ocaml oddfirst : int list -> int list = that takes a int list and returns the same list, but where all odd numbers come before the even numbersarrow_forward# viewGame(G, i) takes a game description G (a dictionary of the type# produced by newGame()) and an integer player index i and returns a# string that, when printed, describes the state of the game from# player i's perspective.## Example:# >>> viewGame(G, 1)# '\nPlayer2 to play (score=0):\n 1[ ] 2[ ] 3[ ]'## Note the spacing and explicit newlines, and the fact that the player# numbers use 1-based indexing even though internally the game data# structures use Pythonic 0-based indexing.arrow_forwardProblem 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))arrow_forward
- Write a function with the signature below that returns the sum of the last k elements of a singly linked list that contains integers. int returnSumOfLastKNodes(Node* head, int k) Example: 10 -> 5->8->15->11->9->23 10 represents the head node, returnSumOfLastKNodes(Node* head, 4) will return 58.arrow_forwardCode in Python:arrow_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