Prime Number Generator (6n + 1 or 6n – 1)

Prime Number Generator (6n + 1 or 6n - 1) This generator is like most where it brute forces an integer: it see whether the integer is divisible by any of the primes; if so, then it's not a prime and vice versa. This though only compares values 6n + 1 and 6n - 1 starting with n as 1 as … Continue reading Prime Number Generator (6n + 1 or 6n – 1)

Advertisements

Collatz Conjecture Meet of 2 Numbers in python

def first_collatz(n, visited): counter = 0 while n > 1: counter += 1 n = 3 * n + 1 if n & 1 else n >> 1 if n not in visited: visited[n] = counter def secondd_collatz(n, other): counter = 0 if n not in other: while n > 1: counter += 1 n … Continue reading Collatz Conjecture Meet of 2 Numbers in python

Simple budget program in python

I've decided to start working on a budget application for the purposes of enhancing my Python skills. In its current form this program takes given expenses and income and tells the user whether they have a surplus, a deficit, or if they are breaking even. Example: import os import sys class Application(): def __init__(self): self.income … Continue reading Simple budget program in python

Asynchronous programming in Scala with Future

What is Future? A future object is an object whose value will be removed at some point in the future. This value is usually the result of a calculation process. This calculation returns the result value, we say that the Future object has completed that value, and vice versa. If an Exception is returned, the … Continue reading Asynchronous programming in Scala with Future

Array in scala enter form keyboard

This is function scala programer enter N element Interger form keyboard. Example: import scala.io._ object InputArray { def main(args: Array[String]): Unit = { println("Please enter n all element?") val n = StdIn.readInt() println("---------begin--------") val IntArr = Array.fill(n.toInt) { StdIn.readInt() } println("---------result--------") for (x <- IntArr) { println("x:" + x) } } } Reuslt:

Type Parameter is Scala

Class in Scala can receive a special parameter type, called Type Parameter. This type of parameter is not the same as normal variables as other parameters, but a parameter that specifies the type. That's why it's called Type Parameter. While Class is defined, it is entirely possible to manipulate an unknown type (specified when calling … Continue reading Type Parameter is Scala

bubble sort scala

/** blue sort*/ def Bluesort(array : Array[Int]): Array[Int] = { var flag = false for(i<- 0 until array.length -1) if(array(i+1) > array(i)){ //tang dan,giam dan > val tmp = array(i) array(i) = array(i+1) array(i+1) = tmp flag = true } // Repeat until we don't have anymore swaps if(flag) Bluesort(array) else array } def main(args: … Continue reading bubble sort scala

Scala Data Type – Description

Sr.No Data Type & Description 1 Byte 8 bit signed value. Range from -128 to 127 2 Short 16 bit signed value. Range -32768 to 32767 3 Int 32 bit signed value. Range -2147483648 to 2147483647 4 Long 64 bit signed value. -9223372036854775808 to 9223372036854775807 5 Float 32 bit IEEE 754 single-precision float 6 Double … Continue reading Scala Data Type – Description

lập trình hàm trong Scala – functional programming

Scala là một ngôn ngữ dị nhất mà tôi từng làm việc. Để học nó tôi phải mất nhiều thời gian hơn C++ (phần generic programming khá khó), hay C# (dễ), Java (quá thân quen) hay Objective-C (khá giống với C). Lập trình hàm ~ Functional Programming Hướng đối tượng rất mềm dẻo (trait) Cú … Continue reading lập trình hàm trong Scala – functional programming