ninetynine

package ninetynine

ninetynine implements the solution to the very famous 99 language problems.

Attributes

Members list

Type members

Classlikes

object P00

P00 - Template for new implementation files.

P00 - Template for new implementation files.

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
P00.type
object P01

P01 - find last element of a list.

P01 - find last element of a list.

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
P01.type
object P02

P02 - find last but one element of a list.

P02 - find last but one element of a list.

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
P02.type
object P03

P03 - find Nth element of a list.

P03 - find Nth element of a list.

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
P03.type
object P04

P04 - find the number of elements in a list.

P04 - find the number of elements in a list.

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
P04.type
object P05

P05 - reverse a list.

P05 - reverse a list.

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
P05.type
object P06

P06 - find out if a list is a palindrome.

P06 - find out if a list is a palindrome.

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
P06.type
object P07

P07 - flatten a nested list structure.

P07 - flatten a nested list structure.

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
P07.type
object P08

P08 - eliminate consecutive duplicates of list elements.

P08 - eliminate consecutive duplicates of list elements.

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
P08.type
object P09

P09 - pack consecutive duplicates of list elements into sublists.

P09 - pack consecutive duplicates of list elements into sublists.

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
P09.type
object P10

P10 - run-length encoding of a list.

P10 - run-length encoding of a list.

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
P10.type
object P11

P11 - modified run-length encoding.

P11 - modified run-length encoding.

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
P11.type
object P12

P12 - decode a run-length encoded list.

P12 - decode a run-length encoded list.

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
P12.type
object P13

P13 - run-length encoding of a list (direct solution).

P13 - run-length encoding of a list (direct solution).

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
P13.type
object P14

P14 - duplicate the elements of a list.

P14 - duplicate the elements of a list.

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
P14.type
object P15

P15 - duplicate the elements of a list a given number of times.

P15 - duplicate the elements of a list a given number of times.

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
P15.type
object P16

P16 - drop every nth element from a list.

P16 - drop every nth element from a list.

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
P16.type
object P17

P17 - split a list into two parts.

P17 - split a list into two parts.

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
P17.type
object P18

P18 - extract a slice from a list.

P18 - extract a slice from a list.

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
P18.type
object P19

P19 - rotate a list n places to the left.

P19 - rotate a list n places to the left.

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
P19.type
object P20

P20 - remove the kth element from a list.

P20 - remove the kth element from a list.

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
P20.type
object P21

P21 - insert an element at a given position into a list.

P21 - insert an element at a given position into a list.

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
P21.type
object P22

P22 - create a list containing all integers within a given range.

P22 - create a list containing all integers within a given range.

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
P22.type
object P23

P23 - extract a given number of randomly selected elements from a list.

P23 - extract a given number of randomly selected elements from a list.

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
P23.type
object P24

P24 - draw n different random numbers from the set 1..m.

P24 - draw n different random numbers from the set 1..m.

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
P24.type
object P25

P25 - generate a random permutation of the elements of a list.

P25 - generate a random permutation of the elements of a list.

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
P25.type
object P26

P26 - generate the combinations of k distinct objects chosen from the n elements of a list.

P26 - generate the combinations of k distinct objects chosen from the n elements of a list.

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
P26.type
object P27

P27 - group the elements of a set into disjoint subsets.

P27 - group the elements of a set into disjoint subsets.

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
P27.type
object P28

P28 - sorting a list of lists according to length of sublists.

P28 - sorting a list of lists according to length of sublists.

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
P28.type
object P31

P31 - determine whether a given integer number is prime.

P31 - determine whether a given integer number is prime.

Attributes

Note

This implements the Trial division algorithm.

Supertypes
class Object
trait Matchable
class Any
Self type
P31.type
object P32

P32 - determine the greatest common divisor of two positive integer numbers.

P32 - determine the greatest common divisor of two positive integer numbers.

Attributes

Note

This implements the Euclidean algorithm.

Supertypes
class Object
trait Matchable
class Any
Self type
P32.type
object P33

P33 - determine whether two positive integer numbers are coprime.

P33 - determine whether two positive integer numbers are coprime.

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
P33.type
object P34

P34 - calculate Euler's totient function phi(m).

P34 - calculate Euler's totient function phi(m).

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
P34.type
object P35

P35 - determine the prime factors of a given positive integer.

P35 - determine the prime factors of a given positive integer.

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
P35.type
object P36

P36 - determine the prime factors of a given positive integer (2).

P36 - determine the prime factors of a given positive integer (2).

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
P36.type
object P37

P37 - calculate Euler's totient function phi(m) (improved).

P37 - calculate Euler's totient function phi(m) (improved).

Euler's so-called totient function phi(m) is defined as the number of positive integers r (1 <= r < m) that are coprime to m. We let phi(1) = 1.

From the definition of P34, we can see that phi(m) is equal to m * (1 - 1/p1) * (1 - 1/p2) * (1 - 1/p3) * ... where p1, p2, p3, ... are the prime factors of m.

Note that we need to use the primeFactors function from P36.

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
P37.type
object P38

P38 - Compare the two methods of calculating Euler's totient function.

P38 - Compare the two methods of calculating Euler's totient function.

Use the solutions of problems P34 and P37 to compare the algorithms. Try to calculate phi(10090) as an example.

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
P38.type
object P39

P39 - a list of prime numbers.

P39 - a list of prime numbers.

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
P39.type
object P40

P40 - Goldbach's conjecture.

P40 - Goldbach's conjecture.

Goldbach’s conjecture says that every positive even number greater than 2 is the sum of two prime numbers. E.g. 28 = 5 + 23. It is one of the most famous facts in number theory that has not been proved to be correct in the general case. It has been numerically confirmed up to very large numbers (much larger than Scala’s Int can represent).

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
P40.type
object P41

P41 - a list of Goldbach compositions.

P41 - a list of Goldbach compositions.

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
P41.type
object P46

P46 - truth tables for logical expressions.

P46 - truth tables for logical expressions.

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
P46.type
object P47

P47 - Truth tables for logical expressions (2).

P47 - Truth tables for logical expressions (2).

Continue problem P46 by redefining and, or, etc as operators. (i.e. make them methods of a new class with an implicit conversion from Boolean.) not will have to be left as a object method.

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
P47.type
object P49

P49 - Gray code.

P49 - Gray code.

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
P49.type
object P50

P50 - Huffman code.

P50 - Huffman code.

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
P50.type
object P55

P55 - Construct completely balanced binary trees.

P55 - Construct completely balanced binary trees.

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
P55.type
object P56

P56 - Symmetric binary trees.

P56 - Symmetric binary trees.

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
P56.type
object P57

P57 - Binary search trees (dictionaries).

P57 - Binary search trees (dictionaries).

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
P57.type
object P58

P58 - Generate-and-test paradigm.

P58 - Generate-and-test paradigm.

Apply the generate-and-test paradigm to construct all symmetric, completely balanced binary trees with a given number of nodes.

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
P58.type
object P59

P59 - Construct height-balanced binary trees.

P59 - Construct height-balanced binary trees.

Attributes

Supertypes
class Object
trait Matchable
class Any
Self type
P59.type