SlideShare a Scribd company logo
1 of 2
Write an SML function groupdupes that takes a list of integers as its only argument. The
function takes runs of values (i.e., consectuive, duplicated values) in the list, copying those runs
into separate sublists, returning a list of those sublists. Examples:
groupdupes([4,4,4,2,3,3,7,7,7,7,2,3,4,4,4]) would return [[4,4,4],[2],[3,3],[7,7,7,7],[2],[3],[4,4,4]]
groupdupes([8,6,7,5]) would return [[8],[6],[7],[5]]
Solution
fun groupdupes_helper(L:int list, subL:int list, result:int list list) =
if (L = nil)
then
result @ [subL]
else if ( ( subL = nil ) orelse
( hd(subL) = hd(L) ) )
then
groupdupes_helper( tl(L), hd(L)::subL, result )
else
groupdupes_helper( tl(L), hd(L)::nil, result @ [subL] )
(* groupdupes Wrapper Function *)
fun groupdupes(L:int list) =
groupdupes_helper(L, nil, nil);
Write an SML function groupdupes that takes a list of integers as its.docx

More Related Content

More from karlynwih

You and another tech are discussing the relative merits of SCSI interf.docx
You and another tech are discussing the relative merits of SCSI interf.docxYou and another tech are discussing the relative merits of SCSI interf.docx
You and another tech are discussing the relative merits of SCSI interf.docxkarlynwih
 
Write an application class (ArrayListApplication) that contains a main.docx
Write an application class (ArrayListApplication) that contains a main.docxWrite an application class (ArrayListApplication) that contains a main.docx
Write an application class (ArrayListApplication) that contains a main.docxkarlynwih
 
Write an algorithm for a program that shows the use of all six math fu.docx
Write an algorithm for a program that shows the use of all six math fu.docxWrite an algorithm for a program that shows the use of all six math fu.docx
Write an algorithm for a program that shows the use of all six math fu.docxkarlynwih
 
write a topic about RFID in SCM and what you have learned about adopti.docx
write a topic about RFID in SCM and what you have learned about adopti.docxwrite a topic about RFID in SCM and what you have learned about adopti.docx
write a topic about RFID in SCM and what you have learned about adopti.docxkarlynwih
 
Write up a simple c-program to find the median of any array-Solution#i.docx
Write up a simple c-program to find the median of any array-Solution#i.docxWrite up a simple c-program to find the median of any array-Solution#i.docx
Write up a simple c-program to find the median of any array-Solution#i.docxkarlynwih
 
Write an assembly language program in the Pep-8 simulator that corresp.docx
Write an assembly language program in the Pep-8 simulator that corresp.docxWrite an assembly language program in the Pep-8 simulator that corresp.docx
Write an assembly language program in the Pep-8 simulator that corresp.docxkarlynwih
 
Write the for structure in JAVA coding to read and display all element.docx
Write the for structure in JAVA coding to read and display all element.docxWrite the for structure in JAVA coding to read and display all element.docx
Write the for structure in JAVA coding to read and display all element.docxkarlynwih
 
Write the formal description of the following state machine (M) What.docx
Write the formal description of the following state machine (M)  What.docxWrite the formal description of the following state machine (M)  What.docx
Write the formal description of the following state machine (M) What.docxkarlynwih
 
Write the C++ code for a function getInput which will read in an unkno.docx
Write the C++ code for a function getInput which will read in an unkno.docxWrite the C++ code for a function getInput which will read in an unkno.docx
Write the C++ code for a function getInput which will read in an unkno.docxkarlynwih
 
Write the balanced reaction where thiosulfate and protons are the only.docx
Write the balanced reaction where thiosulfate and protons are the only.docxWrite the balanced reaction where thiosulfate and protons are the only.docx
Write the balanced reaction where thiosulfate and protons are the only.docxkarlynwih
 
Write functions odd and even- which takes a list of symbols L- and pro.docx
Write functions odd and even- which takes a list of symbols L- and pro.docxWrite functions odd and even- which takes a list of symbols L- and pro.docx
Write functions odd and even- which takes a list of symbols L- and pro.docxkarlynwih
 
Write about the two sources of energy Write about the two sources of.docx
Write about the two sources of energy   Write about the two sources of.docxWrite about the two sources of energy   Write about the two sources of.docx
Write about the two sources of energy Write about the two sources of.docxkarlynwih
 

More from karlynwih (12)

You and another tech are discussing the relative merits of SCSI interf.docx
You and another tech are discussing the relative merits of SCSI interf.docxYou and another tech are discussing the relative merits of SCSI interf.docx
You and another tech are discussing the relative merits of SCSI interf.docx
 
Write an application class (ArrayListApplication) that contains a main.docx
Write an application class (ArrayListApplication) that contains a main.docxWrite an application class (ArrayListApplication) that contains a main.docx
Write an application class (ArrayListApplication) that contains a main.docx
 
Write an algorithm for a program that shows the use of all six math fu.docx
Write an algorithm for a program that shows the use of all six math fu.docxWrite an algorithm for a program that shows the use of all six math fu.docx
Write an algorithm for a program that shows the use of all six math fu.docx
 
write a topic about RFID in SCM and what you have learned about adopti.docx
write a topic about RFID in SCM and what you have learned about adopti.docxwrite a topic about RFID in SCM and what you have learned about adopti.docx
write a topic about RFID in SCM and what you have learned about adopti.docx
 
Write up a simple c-program to find the median of any array-Solution#i.docx
Write up a simple c-program to find the median of any array-Solution#i.docxWrite up a simple c-program to find the median of any array-Solution#i.docx
Write up a simple c-program to find the median of any array-Solution#i.docx
 
Write an assembly language program in the Pep-8 simulator that corresp.docx
Write an assembly language program in the Pep-8 simulator that corresp.docxWrite an assembly language program in the Pep-8 simulator that corresp.docx
Write an assembly language program in the Pep-8 simulator that corresp.docx
 
Write the for structure in JAVA coding to read and display all element.docx
Write the for structure in JAVA coding to read and display all element.docxWrite the for structure in JAVA coding to read and display all element.docx
Write the for structure in JAVA coding to read and display all element.docx
 
Write the formal description of the following state machine (M) What.docx
Write the formal description of the following state machine (M)  What.docxWrite the formal description of the following state machine (M)  What.docx
Write the formal description of the following state machine (M) What.docx
 
Write the C++ code for a function getInput which will read in an unkno.docx
Write the C++ code for a function getInput which will read in an unkno.docxWrite the C++ code for a function getInput which will read in an unkno.docx
Write the C++ code for a function getInput which will read in an unkno.docx
 
Write the balanced reaction where thiosulfate and protons are the only.docx
Write the balanced reaction where thiosulfate and protons are the only.docxWrite the balanced reaction where thiosulfate and protons are the only.docx
Write the balanced reaction where thiosulfate and protons are the only.docx
 
Write functions odd and even- which takes a list of symbols L- and pro.docx
Write functions odd and even- which takes a list of symbols L- and pro.docxWrite functions odd and even- which takes a list of symbols L- and pro.docx
Write functions odd and even- which takes a list of symbols L- and pro.docx
 
Write about the two sources of energy Write about the two sources of.docx
Write about the two sources of energy   Write about the two sources of.docxWrite about the two sources of energy   Write about the two sources of.docx
Write about the two sources of energy Write about the two sources of.docx
 

Recently uploaded

KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentInMediaRes1
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 

Recently uploaded (20)

KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media Component
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 

Write an SML function groupdupes that takes a list of integers as its.docx

  • 1. Write an SML function groupdupes that takes a list of integers as its only argument. The function takes runs of values (i.e., consectuive, duplicated values) in the list, copying those runs into separate sublists, returning a list of those sublists. Examples: groupdupes([4,4,4,2,3,3,7,7,7,7,2,3,4,4,4]) would return [[4,4,4],[2],[3,3],[7,7,7,7],[2],[3],[4,4,4]] groupdupes([8,6,7,5]) would return [[8],[6],[7],[5]] Solution fun groupdupes_helper(L:int list, subL:int list, result:int list list) = if (L = nil) then result @ [subL] else if ( ( subL = nil ) orelse ( hd(subL) = hd(L) ) ) then groupdupes_helper( tl(L), hd(L)::subL, result ) else groupdupes_helper( tl(L), hd(L)::nil, result @ [subL] ) (* groupdupes Wrapper Function *) fun groupdupes(L:int list) = groupdupes_helper(L, nil, nil);