ninetynine
ninetynine implements the solution to the very famous 99 language problems.
Attributes
Members list
Type members
Classlikes
P00 - Template for new implementation files.
P00 - Template for new implementation files.
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
P00.type
P01 - find last element of a list.
P01 - find last element of a list.
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
P01.type
P02 - find last but one element of a list.
P02 - find last but one element of a list.
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
P02.type
P03 - find Nth element of a list.
P03 - find Nth element of a list.
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
P03.type
P04 - find the number of elements in a list.
P04 - find the number of elements in a list.
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
P04.type
P05 - reverse a list.
P05 - reverse a list.
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
P05.type
P06 - find out if a list is a palindrome.
P06 - find out if a list is a palindrome.
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
P06.type
P07 - flatten a nested list structure.
P07 - flatten a nested list structure.
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
P07.type
P08 - eliminate consecutive duplicates of list elements.
P08 - eliminate consecutive duplicates of list elements.
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
P08.type
P09 - pack consecutive duplicates of list elements into sublists.
P09 - pack consecutive duplicates of list elements into sublists.
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
P09.type
P10 - run-length encoding of a list.
P10 - run-length encoding of a list.
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
P10.type
P11 - modified run-length encoding.
P11 - modified run-length encoding.
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
P11.type
P12 - decode a run-length encoded list.
P12 - decode a run-length encoded list.
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
P12.type
P13 - run-length encoding of a list (direct solution).
P13 - run-length encoding of a list (direct solution).
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
P13.type
P14 - duplicate the elements of a list.
P14 - duplicate the elements of a list.
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
P14.type
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 Objecttrait Matchableclass Any
- Self type
-
P15.type
P16 - drop every nth element from a list.
P16 - drop every nth element from a list.
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
P16.type
P17 - split a list into two parts.
P17 - split a list into two parts.
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
P17.type
P18 - extract a slice from a list.
P18 - extract a slice from a list.
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
P18.type
P19 - rotate a list n places to the left.
P19 - rotate a list n places to the left.
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
P19.type
P20 - remove the kth element from a list.
P20 - remove the kth element from a list.
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
P20.type
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 Objecttrait Matchableclass Any
- Self type
-
P21.type
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 Objecttrait Matchableclass Any
- Self type
-
P22.type
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 Objecttrait Matchableclass Any
- Self type
-
P23.type
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 Objecttrait Matchableclass Any
- Self type
-
P24.type
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 Objecttrait Matchableclass Any
- Self type
-
P25.type
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 Objecttrait Matchableclass Any
- Self type
-
P26.type
P27 - group the elements of a set into disjoint subsets.
P27 - group the elements of a set into disjoint subsets.
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
P27.type
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 Objecttrait Matchableclass Any
- Self type
-
P28.type
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 Objecttrait Matchableclass Any
- Self type
-
P31.type
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 Objecttrait Matchableclass Any
- Self type
-
P32.type
P33 - determine whether two positive integer numbers are coprime.
P33 - determine whether two positive integer numbers are coprime.
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
P33.type
P34 - calculate Euler's totient function phi(m).
P34 - calculate Euler's totient function phi(m).
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
P34.type
P35 - determine the prime factors of a given positive integer.
P35 - determine the prime factors of a given positive integer.
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
P35.type
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 Objecttrait Matchableclass Any
- Self type
-
P36.type
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 Objecttrait Matchableclass Any
- Self type
-
P37.type
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 Objecttrait Matchableclass Any
- Self type
-
P38.type
P39 - a list of prime numbers.
P39 - a list of prime numbers.
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
P39.type
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 Objecttrait Matchableclass Any
- Self type
-
P40.type
P41 - a list of Goldbach compositions.
P41 - a list of Goldbach compositions.
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
P41.type
P46 - truth tables for logical expressions.
P46 - truth tables for logical expressions.
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
P46.type
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 Objecttrait Matchableclass Any
- Self type
-
P47.type
P49 - Gray code.
P50 - Huffman code.
P55 - Construct completely balanced binary trees.
P55 - Construct completely balanced binary trees.
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
P55.type
P56 - Symmetric binary trees.
P56 - Symmetric binary trees.
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
P56.type
P57 - Binary search trees (dictionaries).
P57 - Binary search trees (dictionaries).
Attributes
- Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
P57.type