@larryk/

wof functions

PHP (Legacy)

No description

fork
loading
main.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
 # Enhances function STRPOS to return results that are always useful
 FUNCTION wof_find_string_position( $isNeedle , $isHaystack )
 {
  $uselessresult = STRPOS( $isHaystack , $isNeedle ) ;
  IF( $uselessresult === FALSE ) { RETURN -1             ; }
  ELSE                           { RETURN $uselessresult ; }
 }
 #
 # Compresses for REGEX. Will be used as a mask for every single unknown letter
 # wof_compress_for_regex("ABCDEFGHIJKLMNOPQRSTUVWXYZ") returns A-Z
 # wof_compress_for_regex("ABDEFOPQRSUVWXZ") returns ABD-FO-SU-XZ
 # Input should be uppercase, unique, and sorted
 FUNCTION wof_compress_for_regex( $isInput )
 {
  (string) $skAlphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ;
  (string) $sOutput = "" ;
  WHILE( STRLEN( $isInput) > 0 )
  {
   IF( STRLEN( $isInput ) > 2 )
   {
    (string) $sInputCopy = $isInput ;
    (int) $iFoundGroup = 0 ;
    WHILE( STRLEN( $sInputCopy ) > 2 )
    {
     IF( wof_find_string_position( $sInputCopy , $skAlphabet ) > -1 )
     {
      $iFoundGroup = 1 ;
      $sOutput .= SUBSTR( $sInputCopy , 0 , 1 ) . '-' . SUBSTR( $sInputCopy , STRLEN( $sInputCopy ) -1 ) ;
      $isInput  = SUBSTR( $isInput , STRLEN( $sInputCopy ) )  ;
      $sInputCopy = "" ;
     }
     ELSE
     {
      $sInputCopy  = SUBSTR( $sInputCopy , 0 , STRLEN( $sInputCopy ) - 1 )  ;
     }
    }
    IF( $iFoundGroup == 0 )
    {
     $sOutput .= SUBSTR( $isInput , 0 , 1 ) ;
     $isInput  = SUBSTR( $isInput , 1 )  ;
    }
   }
   ELSE
   {
    $sOutput .= SUBSTR( $isInput , 0 , 1 ) ;
    $isInput  = SUBSTR( $isInput , 1 )  ;
   }
  }
  RETURN( $sOutput ) ;
 }
ECHO( "\n1.1" . wof_compress_for_regex("ABCDEFGHIJKLMNOPQRSTUVWXYZ") );
ECHO( "\n1.2" . wof_compress_for_regex("ABCDEFOPQRSUVWXZ") );
 FUNCTION wof_get_letter_utilization( $isInput )
 {
  (string) $skAlphabet   = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ;
  (string) $sUniques     = COUNT_CHARS( STRTOUPPER( $isInput ) , 3 ) ;
  (array)  $aOutput      = ARRAY() ;
  (string) $aOutput[ 0 ] = "" ;
  (string) $aOutput[ 1 ] = "" ;
  WHILE( STRLEN( $skAlphabet) > 0 )
  {
   IF( wof_find_string_position( SUBSTR( $skAlphabet , 0 , 1 ) , $sUniques ) < 0 ) { $aOutput[ 0 ] .= SUBSTR( $skAlphabet , 0 , 1 ) ; }
   ELSE                                                                            { $aOutput[ 1 ] .= SUBSTR( $skAlphabet , 0 , 1 ) ; }
   $skAlphabet  = SUBSTR( $skAlphabet , 1 )  ;
  }
  RETURN( $aOutput ) ;
 }
ECHO "\n3." ;
PRINT_R( wof_get_letter_utilization("ZB\tBFBAdaq\n") ) ;
 # wof_get_letters_used("ZB\tBFBAdaq\n") returns ARRAY( [0] => CEGHIJKLMNOPRSTUVWXY [1] => ABDFQZ)
 FUNCTION wof_get_letters_used(   $isInput ) { (array) $aUtilization = wof_get_letter_utilization( $isInput ) ; RETURN( $aUtilization[ 1 ] ) ; }
ECHO "\n4." . wof_get_letters_used("ZB\tBFBAdaq\n") ;
 FUNCTION wof_get_letters_unused( $isInput ) { (array) $aUtilization = wof_get_letter_utilization( $isInput ) ; RETURN( $aUtilization[ 0 ] ) ; }
ECHO "\n5." . wof_get_letters_unused("ZB\tBFBAdaq\n") ;

PHP 7.0.8 (Legacy: use the following for new features: Command-line PHP: https://repl.it/languages/php_cli PHP Web Server: https://repl.it/languages/php7