• Re: Bellied numbers: From pipeline to awk (was: awk functionalitynot in ksh93)

    From Kaz Kylheku@480-992-1380@kylheku.com to comp.lang.awk on Thu Feb 24 20:42:20 2022
    From Newsgroup: comp.lang.awk

    On 2022-02-20, Axel Reichert <mail@axel-reichert.de> wrote:
    P. S.: With apologies to Kaz, who has read this problem some time back
    in comp.lang.lisp, with similary stupid Lisp questions from me. (-:

    This is the TXR Lisp interactive listener of TXR 274.
    Quit with :quit or Ctrl-D on an empty line. Ctrl-X ? for cheatsheet.
    In programming, you want rigor, but also to recognize and avoid rigor mortis.
    (flow (range 1000 9999)
    (keep-if [chain digits (ap > (+ @2 @3) (+ @1 @4))])
    (partition-if (op neq 1 (- @2 @1)))
    (find-max @1 : len))
    (1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932
    1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945
    1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958
    1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971
    1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984
    1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997
    1998 1999)
    (flow (range 1000 9999)
    (keep-if [chain digits (ap > (+ @2 @3) (+ @1 @4))])
    (partition-if (op neq 1 (- @2 @1)))
    (find-max-key @1 : len))
    80

    We take the range 1000 to 9999. Then we filter it, keeping the bellied
    numbers. Then we partition the list into runs of consecutive integers,
    so now we have a list of lists. We find the partition with the maximum
    length: (1920 ... 1999). Or else, the length of that partition: 80.
    --
    TXR Programming Language: http://nongnu.org/txr
    Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
    --- Synchronet 3.19c-Linux NewsLink 1.113