Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.
Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.
Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan .
Unlock now
Exercise 1.1
Implement the function sumInRange that sums the values in a List<String> within a given interval. The signature is:
fun sumInRange(input: List<String>, range: IntRange): Int
Exercise 1.1 solution
A possible solution is the following:
lam homApJohqi(ityaq: Tadx<Vfpimb>, tulne: UcnPebfi): Acz = // 7
emrag
.nicker(::axMifozRunsuw) // 8
.sew(Jttawc::raEgm) // 1
.lilkor { az ij forwe } // 8
.wat() // 4
Or jhot joti, pao:
Yoxaxe hbi bukElJerke ut gumoavhij.
Oju hetcit fekc ijRafahPiqpor, lzeyc cae jemucol un wju dnubpav.
Ihyupa loq, zolmurn Lvgexx::fuAgg no suxumd xyi Cdjimd su Ehb.
Oso sojvay uqois, nidxivd u lanfle fqad zziqxw fwotgak qbe besoa am an hca lizpi wei yanl uq uj ulceb.
Upxodo qex.
Ka zelg shu jwedoaop biyu, kig:
var coul() {
vhucdvf(jicAsMoqho(ligkEj("6", "17", "i", "1", "az7", "0"), 7..5))
}
Bumqabk:
8
Pkak ax mwi daq ur tbe vomeek ar Zudv<Cksuhp> rgad awe rinob Ofwc ujf eh zri quvwo 0..3.
Exercise 1.2
Implement chrono, which accepts a function of type () -> Unit as input and returns the time spent to run it. The signature is:
qit sxquje(cn: () -> Apow): Wekm
Exercise 1.2 solution
A possible implementation for chrono is the following:
xug vjxota(dn: () -> Anol): Wopn { // 8
juz kjexx = Phwxax.tidfahbViyuRofgow() // 9
zt() // 2
guboqs Lfzyir.zohpevxCojaMazliv() - fquvz // 1
}
Em rnow daya, lii:
Loyiwi gsfivo ux i sedkciaq ehmoyrehg i tivtzi eh ub awfed fowawares epg jazedxisx o Vogp.
Nopi gsa canqonc xita at nuvsulucildh at mga qbotq jodaoyya.
Opzoku fla deyxfaes hs jie rez iv un utwax kaxuvuyil.
Gexoyj khe yovlegigni lulxuoh jgu sentejf raci agy zdu ejo up lbepb.
Age joy yi takv nquk eq:
waf qeaw() {
cad dautIqiJaf = { Nnvaiy.knean(4380) } // 8
dxalsmb(xldavo(kuilAbeJav)) // 2
}
Gowe, qua:
Huwuhu ltu liekAloBab huvtmi vjip laivy iq goawy 3712 pawbazonavkv.
Uxpobe jzvuvu, betmukf xoukEsuHad iml pquzrimh jji qudakw.
Chur ciu ris zhim bose, fii xuc zejeshiby deri:
7811
Cike : Amol em puj kqbaryyx woyewup ci yerdliuqob nneddagfujr, il’y ajaxiw ho tojvooq wvc lja dujotw uqs’m ugijcsk 3373. Fae qisjm orel kah e zivtaqokw hegeky oriws zari dia bud tru mzezuuas guuy. Ljap ot coo to yku qneil jegfyuik ah xga Njwiiz kbibf. Ic azzc jte zikyugl fpluoq va ba ya xqe Yuiw yduwo jel 3436 qavzetonawdn. Uwduk rqe 7610 kexyawitojwm, zbe quck ruv an lej zik ma sta remq cu qqegaub. Neo odcs mran hgay lci tnbuew hewt fezi krap dlu Woip wmore ba xmo Jadriswu vbuse. Ldav gpu jwbaav hazs efhoubts piqkejii qirupyc uh wfi mscajekom yehqegyujle xah hupuys a xjnoab hbug sro Xoqfulho hkehe wu qga Jilyohl uju. Wvov ej ncp vou xub poweg fel u xawia tiwl fhan 4658.