Options
All
  • Public
  • Public/Protected
  • All
Menu

Module puzzle/Helper

Helper module for the Mystery Master Logic Puzzle Solver.

copyright

mysterymaster.com. All rights reserved.

author

Michael Benson

version

2021-08-31

Index

Functions

formatDT

  • formatDT(date: Date): string
  • Returns given date as string with format "YYYY-MM-DD hh:mm:ss.ms".

    Parameters

    • date: Date

      Date.

    Returns string

    Formatted string of date.

getArray2D

  • getArray2D(d1: number, d2: number, v?: number): number[][]
  • Returns 2D array of numbers with each element initialized to given value.

    Parameters

    • d1: number

      Dimension 1.

    • d2: number

      Dimension 2.

    • v: number = 0

      Initial value for each element in 2D array.

    Returns number[][]

    2D array.

getArray2DAsString

  • getArray2DAsString(a: number[][]): string
  • Parameters

    • a: number[][]

    Returns string

getBoolean

  • getBoolean(val: any): boolean
  • Determines if given value is boolean true or false. Returns true if (a) val is boolean and true, (b) val is numeric and not zero, or (c) val is string "true" (case insensitive), otherwise returns false.

    Parameters

    • val: any

      Value.

    Returns boolean

    True or false.

getChartAsText

  • getChartAsText(puzzle: Puzzle, chartCol1: number, isSolution: boolean): string
  • Returns chart as text table. Called by solver.saySolution.

    Parameters

    • puzzle: Puzzle

      Puzzle object.

    • chartCol1: number

      Zero-based index of first noun type to display in chart.

    • isSolution: boolean

      True if chart has solution, otherwise false.

    Returns string

    Text table.

Const getFirstCap

  • getFirstCap(name: string): string
  • Returns given name with first letter capitalized.

    Parameters

    • name: string

      Name.

    Returns string

    Name with first letter capitalized.

getListExcept

  • getListExcept(list1: any[], list2: any[]): any[]
  • Parameters

    • list1: any[]
    • list2: any[]

    Returns any[]

Const getMsgAsOneLine

  • getMsgAsOneLine(str: string, sep?: string): string
  • Returns multi-line string as one line with new lines replaced by given separator.

    Parameters

    • str: string

      String.

    • sep: string = " "

      Separator.

    Returns string

    String with new lines replaced by separator.

getNounArray2D

  • getNounArray2D(d1: number, d2: number, v?: Noun): Noun[][]
  • Returns 2D array of nouns with each element initialized to given value.

    Parameters

    • d1: number

      Dimension 1.

    • d2: number

      Dimension 2.

    • v: Noun = null

      Initial value for each element in 2D array.

    Returns Noun[][]

    2D array of nouns.

Const getObjName

  • getObjName(obj: Function): string
  • Parameters

    • obj: Function

    Returns string

getVerbArray2D

  • getVerbArray2D(d1: number, d2: number, v?: Verb): Verb[][]
  • Returns 2D array of verbs with each element initialized to given value.

    Parameters

    • d1: number

      Dimension 1.

    • d2: number

      Dimension 2.

    • v: Verb = null

      Initial value for each element in 2D array.

    Returns Verb[][]

    2D array of verbs.

Const isBoolean

  • isBoolean(val: any): boolean
  • Determines if given value is a boolean.

    Parameters

    • val: any

      Value.

    Returns boolean

    True if given value is a boolean, otherwise false.

isInt

  • isInt(str: string): boolean
  • Determines if value of given string is an integer.

    Parameters

    • str: string

      String value.

    Returns boolean

    True if value of given string is an integer, otherwise false.

isNotDivisibleBy

  • isNotDivisibleBy(noun: Noun, num: number): boolean
  • Returns true if integer value of noun's name is not divisible by given number, otherwise false.

    Parameters

    • noun: Noun

      Noun.

    • num: number

      Number.

    Returns boolean

    True if integer value of noun's name is not divisible by given number, otherwise false.

Const isNumber

  • isNumber(val: any): boolean
  • Determines if given value is a number.

    Parameters

    • val: any

      Value.

    Returns boolean

    True if given value is a number, otherwise false.

solveEquations

  • solveEquations(a: number[][]): number[]
  • Solves system of n linear equations with n variables x[0], x[1], ..., x[n-1] using Gaussian Elimination and Backward Substitution. Note: This is an augmented matrix, so there is an additional column; hence, n is one less than the number of columns.

    Parameters

    • a: number[][]

    Returns number[]

    1D array of solutions.

Const toInt

  • toInt(str: string): number
  • Returns integer value of given string. Note: Returns zero if string is null, while parseInt returns NaN.

    Parameters

    • str: string

      String value.

    Returns number

    Integer value of string.

Const toTitleCase

  • toTitleCase(str: string): string
  • Returns given string converted to title case.

    Parameters

    • str: string

      String.

    Returns string

    String converted to title case.

Generated using TypeDoc