• Yet another obfuscated Awk code

    From Janis Papanagnou@21:1/5 to All on Sat Jan 22 11:07:38 2022
    Just for recreational purposes here's yet another obfuscated Awk code.

    func ___(_) { return __(_,x^x,x^x^x) }
    func __(_,_x,x_) { return --_?__(_,x_,_x+x_):_x+x_ }
    { print ___($_) }

    Solutions, guesses, comments, improvements, fixes, requests for hints,
    etc. are all welcome.

    Janis

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kpop 2GM@21:1/5 to All on Sat Jan 22 10:11:04 2022
    it's not even limited by 2^-1023 or 2^-1074. since once you're past -2^53, unitary pre-decrementing a number keeps it stuck there, since it lacks the ability to accumulate your non-representable odd numbers in double precision, and will go on for quite
    some time until the either input position 2 or 3 in the two-underscore function reaches 2^1024 infinity

    just my random uneducated guess

    as for function called by print, the 3-underscore one, all of those are pure distractions, since those reduce to calling two-underscore function with

    __( original-input, 1, 0)

    wait … then that's Fibonacci then not Lucas …. i'm confused

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kpop 2GM@21:1/5 to All on Sat Jan 22 09:59:47 2022
    hmmmmmm ……..i dunno ….. maybe full length of each row of input, determines which Lucas number it'll print out. if original input were greater than zero, and integer, but degenerate into an infinite loop if original input were less-than-or-equal-
    zero, or is a non-integer real number, or contains bytes other than 0-9, +/-, space, to the left of the first position with a number-like value (e.g. decrementing capital "A" makes it -1, thus degenerate into the infinite loop case) ??

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kpop 2GM@21:1/5 to Janis Papanagnou on Sat Jan 22 09:45:37 2022
    On Saturday, January 22, 2022 at 5:07:41 AM UTC-5, Janis Papanagnou wrote:
    Just for recreational purposes here's yet another obfuscated Awk code.

    func ___(_) { return __(_,x^x,x^x^x) }
    func __(_,_x,x_) { return --_?__(_,x_,_x+x_):_x+x_ }
    { print ___($_) }

    Solutions, guesses, comments, improvements, fixes, requests for hints,
    etc. are all welcome.

    Janis

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kpop 2GM@21:1/5 to All on Sat Jan 22 10:09:10 2022
    it's not even limited by 2^-1023 or 2^-1074. since once you're past -2^53, unitary pre-decrementing a number keeps it stuck there, since it lacks the ability to accumulate your non-representable odd numbers in double precision, and will go on for quite
    some time until the either input position 2 or 3 in the two-underscore function reaches 2^1024 infinity

    just my random uneducated guess

    as for function called by print, the 3-underscore one, all of those are pure distractions, since those reduce to calling two-underscore function with

    __( original-input, 1, 1, 1)

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Janis Papanagnou@21:1/5 to Janis Papanagnou on Sun Jan 23 02:34:58 2022
    On 22.01.2022 11:07, Janis Papanagnou wrote:
    Just for recreational purposes here's yet another obfuscated Awk code.

    func ___(_) { return __(_,x^x,x^x^x) }
    func __(_,_x,x_) { return --_?__(_,x_,_x+x_):_x+x_ }
    { print ___($_) }

    Solutions, guesses, comments, improvements, fixes, requests for hints,
    etc. are all welcome.

    Janis


    On 22.01.2022 19:11, Kpop 2GM wrote:
    it's not even limited by 2^-1023 or 2^-1074. since once you're past
    -2^53, unitary pre-decrementing a number keeps it stuck there, since
    it lacks the ability to accumulate your non-representable odd numbers
    in double precision, and will go on for quite some time until the
    either input position 2 or 3 in the two-underscore function reaches
    2^1024 infinity

    just my random uneducated guess

    as for function called by print, the 3-underscore one, all of those
    are pure distractions, since those reduce to calling two-underscore
    function with

    __( original-input, 1, 0)

    wait … then that's Fibonacci then not Lucas …. i'm confused


    You've identified it!

    A couple notes. Since numbers grow extremely there's some limit as
    you noticed. I admit it was unfair that I didn't define the domain
    of the function, but you got it anyway. I could of course have had
    a condition added to make life easier, e.g. $_&&!/[^0-9]/ { ... }
    or, to obfuscate it a bit, even _=int(sqrt(-($_*-$_))) { ... } .
    The two constant parameters are indeed 1 and 0 (not the values you
    assumed in an earlier post). I used a reduced pattern of what I saw
    in your other thread's post (_^_^_^...^_) for these constants (with
    my observation that the reduced subexpression toggles between 0 and
    1). The function is the one you suspected, and (in obfuscated form)
    simpler written as just

    # defined for integer args>0
    func __(_) { return _>2?__(--_)+__(--_):1 } { print __($_) }

    I like this form even more (with those nasty --_ side effects) and
    the underlying mathematical function is more obvious, but the time
    complexity is extremely bad since we have a cascading recursion in
    that simple form. There's a transformation of the function possible
    to generate an equivalent linear recursion with good (linear) time
    complexity (and no supporting arrays and the like), and that is

    func ___(_) { return __(_,x^x,x^x^x) }
    func __(_,_x,x_) { return --_?__(_,x_,_x+x_):_x+x_ }
    $_&&!/[^0-9]/ { print ___($_) }

    And where the first version is rarely usable for arguments >35 the
    second one runs smoothly for large arguments in no time.

    Janis

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kpop 2GM@21:1/5 to All on Mon Jan 24 13:15:35 2022
    it's not your fault whatsoever you haven't defined the domain - that's what a code challenge is all about anyway :

    to identify both the core feature(s), and edge cases. you're entirely within your rights to only define what you want to define, and it's up to the participants to complete the puzzle. I'm not a mathematician whatsoever and still don't really understand
    what a Lucas number sequence is anyway.

    i was only able to identify it as Fib cuz i already have 2 variants of the fib( ) function coded in a similar fashion (but both failing to capture some edge cases) :

    function fib2(_,__) {
    return (__=!-"")+_<+__?+__\
    : fib2(_-__)+fib2(_-__-__) }

    function fib3(__,_,___){
    return !__?___:_""""""\
    ? fib3(__-(_~_),_+___,_)\
    : fib3(__-(_=_~_),___+_,_) }

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kpop 2GM@21:1/5 to All on Thu Feb 3 03:51:36 2022
    Hi Janis,

    if you care for an even more challenging obfuscated one :what is contained within that exactly 1.00 GB being outputted from this function in 95 miliseconds , given the sample input of 7 in argument position 1, and 30 in position 2 ? This code shouldn't
    have any trouble executing on just about any awk variant one can imagine. It's also fully self-contained,.

    % ( time ( gnice mawk2 'function __(_,___,____) { if (_!~"."||___<-____) { return "" } else if (((____+=++____)*++____+--____)<=+___) { _=__(_,____=int(___/=____)); gsub(".",_,_); return ___-____?(_)_:_ } else { return (""<"")<--___?(_=__(_,--___))(_)(_)_
    :___?_:(_)_ } } BEGIN { print length(__(7,30)) }' ) )

    ( gnice mawk2 ; ) 0.03s user 0.07s system 96% cpu 0.095 total
    1073741824

    The 4Chan Teller

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kpop 2GM@21:1/5 to All on Mon Apr 11 17:38:18 2022
    @Janus : This next one should be straight forward enough. For your convenience, I'm including the profiler output from gawk to show how it's being executed using gawk -P (posix) mode as well as mawk 1.3.4's debugger

    what does this function that's non-recursive, non-gawk-extension-dependent, and fully self-encapsulated return ?

    (self-encapsulating to a point it neither makes any calls to built-in functions, nor does it reference any system-wide variable)

    # gawk profile, created Mon Apr 11 20:27:37 2022

    # BEGIN rule(s)

    BEGIN {
    1 OFMT = CONVFMT = "%.50g"
    1 print _____()
    }


    # Functions, listed alphabetically

    1 function _____(_, __, ___, ____)
    {
    1 __ = ! (____ += ____ += ____ *= ____ *= ____ *= ____ = (___ = _ = _ ~ _) - +-++_ * _--)
    1562499 while (--____) {
    1562499 __ += (___ / _++) - (___ / _++)
    }
    1 return __
    }

    ====================== below is what the debugger from mawk 1.3.4 prints out ===============

    function _____
    000 . l_pusha 1
    002 . l_pusha 3
    004 . l_pusha 3
    006 . l_pusha 3
    008 . l_pusha 3
    010 . l_pusha 3
    012 . l_pusha 3
    014 . l_pusha 2
    016 . l_pusha 0
    018 . l_pushi 0 # frame-number
    020 . l_pushi 0 # frame-number
    022 . match2
    023 . assign
    024 . assign
    025 . l_pusha 0
    027 . pre_inc
    028 . uminus
    029 . uplus
    030 . l_pusha 0
    032 . post_dec
    033 . mul
    034 . sub
    035 . assign
    036 . mul_asg
    037 . mul_asg
    038 . mul_asg
    039 . add_asg
    040 . add_asg
    041 . not
    042 . assign
    043 . pop
    044 . jmp 063
    046 . l_pusha 1
    048 . l_pushi 2 # frame-number
    050 . l_pusha 0
    052 . post_inc
    053 . div
    054 . l_pushi 2 # frame-number
    056 . l_pusha 0
    058 . post_inc
    059 . div
    060 . sub
    061 . add_asg
    062 . pop
    063 . l_pusha 3
    065 . pre_dec
    066 . jnz 046
    068 . l_pushi 1 # frame-number
    070 . ret
    071 . ret0
    BEGIN
    000 . f_pusha OFMT
    002 . f_pusha CONVFMT
    004 . pushs "%.50g"
    006 . f_assign
    007 . f_assign
    008 . pop
    009 . call _____ 0
    012 . pushint 1
    014 . print
    016 . exit0

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kpop 2GM@21:1/5 to All on Sat May 28 05:07:40 2022
    @Janus : i just realized because your code doesn't perform any data scrubbing, anything that's not a positive integer immediately stack overflow due to infinite loop

    here's the version that fixes both of those :

    function ___(_) { return (_ = int(_)) <= _^(_<_) ? -_<+_ : __(_,_~_,_<_) } function __(_,____,_____) { return (_ -= (____ += +_____)^(_<_)) ? __(_,_____,____) : +____ }{ print ___($-_) }

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Janis Papanagnou@21:1/5 to All on Sat May 28 14:43:11 2022
    On 28.05.2022 14:07, Kpop 2GM wrote:
    @Janus : i just realized because your code doesn't perform any data scrubbing, anything that's not a positive integer immediately stack
    overflow due to infinite loop

    This is a correct observation, and I think I've addressed that in my
    last post of this sub-thread where I suggested adding a condition to
    keep the numbers in the domain of valid numbers.

    (BTW, I suggest, in Usenet posts, to quote context to make it easier
    to see what you are referring to. Thanks.)

    Janis

    [...]

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)