请选择 进入手机版 | 继续访问电脑版
楼主: Lisrelchen
2984 23

【Question & Answer】Functional Programming in Scala [推广有奖]

  • 0关注
  • 62粉丝

VIP

院士

67%

还不是VIP/贵宾

-

TA的文库  其他...

Bayesian NewOccidental

Spatial Data Analysis

东西方数据挖掘

威望
0
论坛币
49955 个
通用积分
79.3687
学术水平
253 点
热心指数
300 点
信用等级
208 点
经验
41518 点
帖子
3256
精华
14
在线时间
766 小时
注册时间
2006-5-4
最后登录
2022-11-6

Lisrelchen 发表于 2017-2-21 10:36:32 |显示全部楼层 |坛友微信交流群
相似文件 换一批

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
  1. Functional Programming in Scala

  2. This book is written to document the solutions attempted to solve the exercises in the book
复制代码

本帖隐藏的内容

Functional Programming in Scala.pdf (380.78 KB, 需要: 1 个论坛币)


二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:Programming Functional function question Program exercises document written

本帖被以下文库推荐

Lisrelchen 发表于 2017-2-21 10:38:09 |显示全部楼层 |坛友微信交流群
  1. 2.1

  2. Write a recursive function to get the nth Fibonacci number (http://mng.bz/C29s). The first two Fibonacci numbers are 0 and 1. The nth number is always the sum of the previous two—the sequence begins 0, 1, 1, 2, 3, 5. Your definition should use a local tail-recursive function. def fib(n: Int): Int
  3. Solution

  4. def fib(n: Int): Int = {
  5.     def go(n: Int, first: Int, second: Int): Int =
  6.       if(n == 1) first
  7.       else if (n == 2) second
  8.       else go(n-1, second, first + second)
  9.     go(n, 0, 1)
  10.   }
复制代码

使用道具

Lisrelchen 发表于 2017-2-21 10:39:03 |显示全部楼层 |坛友微信交流群
  1. 2.2

  2. Implement isSorted, which checks whether an Array[A] is sorted according to a given comparison function: def isSortedA => Boolean): Boolean
  3. Solution

  4. def isSorted[A](as: Array[A], ordered: (A, A) => Boolean): Boolean = {
  5.     @annotation.tailrec
  6.     def go(n: Int): Boolean =
  7.       if (n == as.length - 1) ordered(as(n-1), as(n))
  8.       else if (! ordered(as(n-1), as(n))) false
  9.       else go(n + 1)
  10.     if (as.size == 0 || as.size == 1) true
  11.     else go(1)
  12.   }
复制代码

使用道具

Nicolle 学生认证  发表于 2017-2-21 10:41:33 |显示全部楼层 |坛友微信交流群
提示: 作者被禁止或删除 内容自动屏蔽

使用道具

Nicolle 学生认证  发表于 2017-2-21 10:43:01 |显示全部楼层 |坛友微信交流群
提示: 作者被禁止或删除 内容自动屏蔽

使用道具

Nicolle 学生认证  发表于 2017-2-21 10:43:59 |显示全部楼层 |坛友微信交流群
提示: 作者被禁止或删除 内容自动屏蔽

使用道具

西门高 发表于 2017-2-21 10:45:08 |显示全部楼层 |坛友微信交流群
谢谢分享
已有 1 人评分论坛币 收起 理由
Nicolle + 20 鼓励积极发帖讨论

总评分: 论坛币 + 20   查看全部评分

使用道具

Nicolle 学生认证  发表于 2017-2-21 10:45:09 |显示全部楼层 |坛友微信交流群
提示: 作者被禁止或删除 内容自动屏蔽

使用道具

fin-qq 发表于 2017-2-21 10:47:58 |显示全部楼层 |坛友微信交流群
743旅行社运行与管理6版2429-2PPT梁智
已有 1 人评分论坛币 收起 理由
Nicolle + 20 鼓励积极发帖讨论

总评分: 论坛币 + 20   查看全部评分

使用道具

zgs3721 发表于 2017-2-21 10:53:12 |显示全部楼层 |坛友微信交流群
谢谢楼主
已有 1 人评分论坛币 收起 理由
Nicolle + 20 鼓励积极发帖讨论

总评分: 论坛币 + 20   查看全部评分

使用道具

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加JingGuanBbs
拉您进交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-3-28 23:50