Homework1 5100379002. What we have learnt Variable binding: val x = e; Conditionals: if e1 then e2 else e3 Function binding:fun x0 (x1 : t1,..., xn :

Slides:



Advertisements
Similar presentations
Months of the year December January November October February
Advertisements

Learn all about the year.
ML Lists.1 Standard ML Lists. ML Lists.2 Lists  A list is a finite sequence of elements. [3,5,9] ["a", "list" ] []  Elements may appear more than once.
WALT: Know the months of the year poem. Answer questions about the months.
Programming Languages Section 1 1 Programming Languages Section 1. SML Fundamentals Xiaojuan Cai Spring 2015.
DOT 1 January , 1990 DOT 2 July 23 - August 3, 1990.
Chubaka Producciones Presenta :.
2012 JANUARY Sun Mon Tue Wed Thu Fri Sat
January 2012 Monday Tuesday Wednesday Thursday Friday Sat/ Sun / /8 14/15 21/22 28/
P Pathophysiology Calendar. SundayMondayTuesdayWednesdayThursdayFridaySaturday January 2012.
Chicas, este calendario si es pa' nosotras !!!!!.
MONDAYTUESDAYWEDNESDAYTHURSDAYFRIDAYSAT/SUN Note: You can print this template to use as a wall calendar. You can also copy the slide for any month to add.
School Year Calendar You can print this template to use it as a wall calendar, or you can copy the page for any month to add it to your own presentation.
School Year Calendar You can print this template to use it as a wall calendar, or you can copy the page for any month to add it to your own presentation.
You can print this template to use it as a wall calendar, or you can copy the page for any month to add it to your own presentation. If you’d like to change.
2007 Monthly Calendar You can print this template to use it as a wall calendar, or you can copy the page for any month to add it to your own presentation.
MONDAYTUESDAYWEDNESDAYTHURSDAYFRIDAYSAT/SUN Note: You can print this template to use as a wall calendar. You can also copy the slide for any month to add.

You can print this template to use it as a wall calendar, or you can copy the page for any month to add it to your own presentation. If you’d like to change.
WORD JUMBLE. Months of the year Word in jumbled form e r r f b u y a Word in jumbled form e r r f b u y a february Click for the answer Next Question.
Months of the Year Macarena song.
DATE POWER 2 INCOME JANUARY 100member X 25.00P2, FEBRUARY 200member X 25.00P5, MARCH 400member X 25.00P10, APRIL 800member.
Months of the year. jANUARY New year’s day fEBRUARY Valentine’s day.
Calendar for 2011 Months of the Year with Holidays.
2011 Calendar Important Dates/Events/Homework. SunSatFriThursWedTuesMon January
TEMPORAL VISUALIZATION OF DATA FROM THE FRENCH SENTINEL NETWORK.
July 2007 SundayMondayTuesdayWednesdayThursdayFridaySaturday
Programming Languages Dan Grossman 2013
Dictation practice 2nd Form Ms. Micaela-Ms. Verónica.
TIMELINES PHOTOS This is an example text
TIMELINES PHOTOS This is an example text
McDonald’s Kalender 2009.
McDonald’s Kalender 2009.
JANUARY 2018 SUNDAY MONDAY TUESDAY WEDNESDAY THURSDAY FRIDAY SATURDAY
13-block rotation schedule
1   1.テキストの入れ替え テキストを自由に入れ替えることができます。 フチなし全面印刷がおすすめです。 印刷のポイント.
January MON TUE WED THU FRI SAT SUN
January MON TUE WED THU FRI SAT SUN
2017/18 Payment Calendar Due Date Cut-off Day 1st of every month
The SAT will be given at ECHS on the dates below!
McDonald’s Kalender 2009.
January Sun Mon Tue Wed Thu Fri Sat
January MON TUE WED THU FRI SAT SUN
January MON TUE WED THU FRI SAT SUN
Problem Gambling Clicks to Opgr.org
2300 (11PM) September 21 Blue line is meridian..
January MON TUE WED THU FRI SAT SUN
McDonald’s calendar 2007.
1 - January - Sun Mon The Wed Thu Fri Sat
Proud As A Peacock! We are very proud of__________________
Teacher name August phone: Enter text here.
January MON TUE WED THU FRI SAT SUN
JANUARY 1 Sun Mon Tue Wed Thu Fri Sat
January MON TUE WED THU FRI SAT SUN
JANUARY 1 Sun Mon Tue Wed Thu Fri Sat
February 2007 Note: Source:.
| January Sunday Monday Tuesday Wednesday Thursday Friday
Who Wants to be a Millionaire?
January MON TUE WED THU FRI SAT SUN
MONTHS OF THE YEAR January February April March June May July August
S M T W F S M T W F
JANUARY 1 Sun Mon Tue Wed Thu Fri Sat
McDonald’s calendar 2007.
1 January 2018 Sun Mon Tue Wed Thu Fri Sat
Production Month Sun Hours K Monthly Kwh Tou Peak Value After Kwh
Habitat Changes and Fish Migration
January Monday Tuesday Wednesday Thursday Friday Saturday Sunday 30 31
2015 January February March April May June July August September
Habitat Changes and Fish Migration
Presentation transcript:

Homework

What we have learnt Variable binding: val x = e; Conditionals: if e1 then e2 else e3 Function binding:fun x0 (x1 : t1,..., xn : tn) = e Tuples: – val tuple = (1, bool, a) – #1 tuple

What we have learnt Lists: – val xs = [e1, e2, …, en] – e1 :: xs – null xs – hd xs – tl xs

What we have learnt Let expressions: – let b1 b2... bn in e end Options: – NONE / SOME e – isSome – valOf Others: – andalso / orelse – e1 = e2 / e1 <> e2 / ~1

Problem1 fun is_older (pr1 : int * int * int, pr2: int * int * int) : bool fun is_older (pr1 : int * int * int, pr2: int * int * int) = (#1 pr1 < #1 pr2) orelse ( (#1 pr1 = #1 pr2) andalso (#2 pr1 < #2 pr2) ) orelse ( (#1 pr1 = #1 pr2) andalso (#2 pr1 = #2 pr2) andalso (#3 pr1 < #3 pr2))

Problem2 fun number_in_month (dates: (int * int * int) list,month: int ): int fun number_in_month(dates: (int*int*int) list, month: int) = if null dates then 0 else if #2 (hd dates) = month then 1 + number_in_month(tl dates, month) else number_in_month(tl dates, month)

Problem3 fun number_in_months (dates : ( int * int * int ) list, months : int list) : int fun number_in_months(dates: (int*int*int) list, months: int list) = if null months then 0 else number_in_month(dates, hd months) + number_in_months(dates, tl months)

Problem4 fun dates_in_month(dates: (int*int*int) list, month: int): (int*int*int) list fun dates_in_month (dates : ( int * int * int ) list, month : int) = if null dates then [] else if #2 (hd dates) = month then (hd dates) :: dates_in_month ( (tl dates), month) else dates_in_month ( (tl dates), month)

Problem5 fun dates_in_months (dates : ( int * int * int ) list, months : int list) : ( int * int * int ) list fun dates_in_months (dates : ( int * int * int ) list, months : int list) = if null months then [] else dates_in_month (dates, hd dates_in_months (dates, tl months)

Problem6 fun get_nth(strings: string list, n: int):string fun get_nth(strings: string list, n: int) = if n = 1 then hd strings else get_nth(tl strings, n-1)

Problem7 fun date_to_string ( date : int * int * int): string fun date_to_string ( date : int * int * int) = let val months_name = ["January", "February", "March", "April", "May", "June, "July", "August", "September", "October", "November", "December"] in get_nth (months_name, #2 date) ^ ^ Int.toString (#3 date) ^ ", " ^ Int.toString (#1 date) end

Problem8 fun number_before_reaching_sum(sum: int, numbers: int list):int fun number_before_reaching_sum(sum: int, numbers: int list) = let fun count(numbers: int list, acc: int, n: int) = if hd numbers + acc >= sum then n else count(tl numbers, acc + hd numbers, n + 1) in count(numbers, 0, 0) end

Promblem9 fun what_month (day_of_year : int): int fun what_month(day_of_year: int) = let val days_in_month = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] in number_before_reaching_sum(day, days_in_month) + 1 end

Problem10 fun month_range(day1: int, day2: int): int list fun month_range(day1: int, day2: int) = if day1 > day2 then [] else what_month(day1) :: month_range(day1 + 1, day2)

Problem11 fun oldest(dates: (int*int*int) list):(int*int*int) option fun oldest(dates: (int*int*int) list) = if null dates then NONE else let val tl_ans = oldest(tl dates) in if isSome tl_ans andalso is_older(valOf tl_ans, hd dates) then tl_ans else SOME (hd dates) end

Challenge Problem 1 fun number_in_months_challenge (dates : ( int * int * int ) list, months : int list) : int fun number_in_months_challenge (dates : ( int * int * int ) list, months : int list) = if null months then 0 else number_in_months (dates, remove_duplicates(months))

fun remove_duplicates (months : int list) = let fun exists (n : int, ls : int list) = if null ls then false else (n = (hd ls) orelse exists(n, tl ls)) in if null months then [] else if exists(hd months, tl months) then remove_duplicates (tl months) else (hd months) :: remove_duplicates(tl months) end

fun dates_in_months_challenge (dates : ( int * int * int ) list, months : int list) = if null months then [] else dates_in_months (dates, remove_duplicates(months))

Challenge Problem2

fun reasonable_date (date : int * int * int) = let val year = #1 date val month = #2 date val day = #3 date val valid_year = year > 0 val valid_month = (month >= 1) andalso (month <= 12) val is_leap_year = (year mod 400 = 0) orelse ((year mod 4 = 0) andalso (year mod 100) <> 0) ……

val val_for_Feb = if is_leap_year then 29 else 28 val days = [31, val_for_Feb, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] fun get_nth_int (ls : int list, n : int) = if n = 1 then hd ls else get_nth_int (tl ls, (n-1)) val valid_day = valid_month andalso ((#3 date) <= get_nth_int(days, #2 date)) andalso ((#3 date) >= 1); in ……

in valid_year andalso valid_month andalso valid_day end

Q & A