• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Scala BigInt类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Scala中scala.math.BigInt的典型用法代码示例。如果您正苦于以下问题:Scala BigInt类的具体用法?Scala BigInt怎么用?Scala BigInt使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了BigInt类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。

示例1: Problem015

//设置package包名称以及导入依赖的类
// ??? ?? ???. 40C20 ?? ?? ??. ??? ????? ??? ????? ??.

import scala.math.BigInt
object Problem015 {
  def main(args: Array[String]) {

    def combination(n: Int, k: Int): BigInt = {
      require(n > 0 && k >= 0)

      if (n < k || n < 1 || k < 0)
        0
      else if (n == k || k == 0)
        1
      else {
        val kk = if (n - k < k) n - k else k
        val nList = ((n to (1, -1)).toList take kk).map(BigInt(_)) // ??
        val kList = (kk to (1, -1)).toList // ??
        val up = (BigInt(1) /: nList)(_ * _) // ???? ?? BigInt ? ??
        (up /: kList)(_ / _);
      }
    }

    val start = System.currentTimeMillis();
    val result = combination(40, 20);
    println("????", System.currentTimeMillis() - start, "??", result)
  }
} 
开发者ID:johngrib,项目名称:project_euler,代码行数:28,代码来源:Problem015.scala


示例2: GCDEuclidian

//设置package包名称以及导入依赖的类
package com.example.gcd

import java.util.Scanner

import com.example.util.BenchmarkHelper._

import scala.math.BigInt


object GCDEuclidian extends App{

  def calculateGCDfor(a: BigInt, b: BigInt): BigInt = {
    if (b == BigInt(0)) a
    else {
      if(a > b) calculateGCDfor(b, a - b * (a / b))
      else calculateGCDfor(a, b - a * (b / a))
    }
  }

  val  s = new Scanner(System.in)
  val a = s.nextBigInteger()
  val b = s.nextBigInteger()

  //Test for example for a = 74356764380* 13   &   b = 74356764380 * 5
  time {
    println{
      s"GCD for numbers $a and $b is: \t" + calculateGCDfor(a, b)
    }
  }
} 
开发者ID:deil87,项目名称:code-challenges,代码行数:31,代码来源:GCDEuclidian.scala


示例3: MultipartPostResponses200

//设置package包名称以及导入依赖的类
package form_data


    import java.io.File
    import scala.math.BigInt

    import de.zalando.play.controllers.PlayPathBindables


//noinspection ScalaStyle
package yaml {


    case class MultipartPostResponses200(name: BothPostResponses200Name, year: BothPostYear, fileSize: BothPostYear, fileName: BothPostResponses200Name) 
    case class BothPostResponses200(name: BothPostResponses200Name, year: BothPostYear, avatarSize: BothPostYear, ringtoneSize: BothPostYear) 


    import play.api.libs.json._
    import play.api.libs.functional.syntax._
    import de.zalando.play.controllers.MissingDefaultWrites
    object ResponseWrites extends MissingDefaultWrites {
    implicit val BothPostResponses200Writes: Writes[BothPostResponses200] = new Writes[BothPostResponses200] {
        def writes(ss: BothPostResponses200) =
          Json.obj(
            "name" -> ss.name, 
            "year" -> ss.year, 
            "avatarSize" -> ss.avatarSize, 
            "ringtoneSize" -> ss.ringtoneSize
          )
        }
    implicit val MultipartPostResponses200Writes: Writes[MultipartPostResponses200] = new Writes[MultipartPostResponses200] {
        def writes(ss: MultipartPostResponses200) =
          Json.obj(
            "name" -> ss.name, 
            "year" -> ss.year, 
            "fileSize" -> ss.fileSize, 
            "fileName" -> ss.fileName
          )
        }
    }
}

// should be defined after the package because of the https://issues.scala-lang.org/browse/SI-9922

//noinspection ScalaStyle
package object yaml {

    type MultipartPostAvatar = Option[File]
    type BothPostResponses200Name = Option[String]
    type BothPostYear = Option[BigInt]


import play.api.mvc.{QueryStringBindable, PathBindable}

    implicit val bindable_FileQuery = PlayPathBindables.queryBindableFile
    implicit val bindable_BigIntQuery = PlayPathBindables.queryBindableBigInt
    implicit val bindable_OptionFileQuery: QueryStringBindable[Option[File]] = PlayPathBindables.createOptionQueryBindable[File]
    implicit val bindable_OptionBigIntQuery: QueryStringBindable[Option[BigInt]] = PlayPathBindables.createOptionQueryBindable[BigInt]

} 
开发者ID:LappleApple,项目名称:api-first-hand,代码行数:61,代码来源:form_data_yaml.scala


示例4: NetworkTotalsMarshaller

//设置package包名称以及导入依赖的类
package org.bitcoins.rpc.marshallers.networking

import org.bitcoins.rpc.bitcoincore.networking.{NetworkTotals, NetworkTotalsImpl}
import scala.math.BigInt
import spray.json._


object NetworkTotalsMarshaller extends DefaultJsonProtocol {
  val totalBytesRecvKey = "totalbytesrecv"
  val totalBytesSentKey = "totalbytessent"
  val timeInMilliSecondsKey = "timemillis"

  implicit object NetworkTotalFormatter extends RootJsonFormat[NetworkTotals] {
    override def read (value: JsValue) : NetworkTotals = {
      val obj = value.asJsObject
      val totalBytesRecv = obj.fields(totalBytesRecvKey).convertTo[Int]
      val totalBytesSent = obj.fields(totalBytesSentKey).convertTo[Int]
      val timeInMilliSeconds = obj.fields(timeInMilliSecondsKey).convertTo[BigInt]
      NetworkTotalsImpl(totalBytesRecv, totalBytesSent, timeInMilliSeconds)
    }

    override def write (NetworkDetail : NetworkTotals) : JsValue = {
      val m : Map[String, JsValue] = Map (
        totalBytesRecvKey -> JsNumber(NetworkDetail.totalBytesRecv),
        totalBytesSentKey -> JsNumber(NetworkDetail.totalBytesSent),
        timeInMilliSecondsKey -> JsNumber(NetworkDetail.timeInMilliSeconds)
      )
      JsObject(m)
    }
  }
} 
开发者ID:bitcoin-s,项目名称:bitcoin-s-rpc-client,代码行数:32,代码来源:NetworkTotalsMarshaller.scala


示例5: NetworkTotalsMarshallerTest

//设置package包名称以及导入依赖的类
package org.bitcoins.rpc.marshallers.networking

import org.bitcoins.rpc.bitcoincore.networking.NetworkTotals
import org.scalatest.{FlatSpec, MustMatchers}
import spray.json._

import scala.math.BigInt


class NetworkTotalsMarshallerTest extends FlatSpec with MustMatchers {
  val str =
    """
      |{
      |    "totalbytesrecv" : 1972832211,
      |    "totalbytessent" : 71483458,
      |    "timemillis" : 1452264952971
      |}
    """.stripMargin

  val json = str.parseJson
  val NetworkDetail : NetworkTotals = NetworkTotalsMarshaller.NetworkTotalFormatter.read(json)

  "NetworkTotals" must "parse network total infos" in {
    NetworkDetail.totalBytesRecv must be (1972832211)
    NetworkDetail.totalBytesSent must be (71483458)
    NetworkDetail.timeInMilliSeconds must be (BigInt("1452264952971"))
  }

  it must "write network total info" in {
    val writtenNetworkTotal = NetworkTotalsMarshaller.NetworkTotalFormatter.write(NetworkDetail)
    writtenNetworkTotal.asJsObject.fields("totalbytesrecv") must be (JsNumber(1972832211))
    writtenNetworkTotal.asJsObject.fields("totalbytessent") must be (JsNumber(71483458))
    writtenNetworkTotal.asJsObject.fields("timemillis") must be (JsNumber(BigInt("1452264952971")))

  }
} 
开发者ID:bitcoin-s,项目名称:bitcoin-s-rpc-client,代码行数:37,代码来源:NetworkTotalsMarshallerTest.scala



注:本文中的scala.math.BigInt类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Scala HandlerList类代码示例发布时间:2022-05-23
下一篇:
Scala TaskAttemptID类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap