| Deutsch English Français Italiano |
|
<20240706224643.130@kylheku.com> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Kaz Kylheku <643-408-1753@kylheku.com>
Newsgroups: comp.lang.lisp
Subject: Re: X in every language syndrome
Date: Sun, 7 Jul 2024 05:58:57 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 68
Message-ID: <20240706224643.130@kylheku.com>
References: <v6cemu$3vogb$1@dont-email.me>
Injection-Date: Sun, 07 Jul 2024 07:58:57 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="d43bd929db10dfc067029da3ebb502ec";
logging-data="241704"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/Ic5YCBIsEsg7XB+RM3bXyx3hhl4INkiU="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:u9s18y8+jqAgas1RIGMB9WgEavg=
Bytes: 3019
On 2024-07-06, B. Pym <No_spamming@noWhere_7073.org> wrote:
> [ Another poster: ]
>
>> TXR Lisp.
>>
>> Having defined:
>>
>> (defun bellied-p (num)
>> (let ((d (digits num)))
>> (and (= 4 (len d))
>> (< (+ [d 0] [d 3])
>> (+ [d 1] [d 2])))))
>>
>> We casually do this at the prompt:
>>
>> 1> [find-max [partition-by bellied-p (range 1000 9999)] :
>> [iff [chain car bellied-p] len (ret 0)]]
>> (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)
>
> Shorter.
>
> Gauche Scheme:
>
> (use gauche.sequence) ;; group-contiguous-sequence find-max
> ,print-mode pretty #t length #f width 64
>
> (define (bellied? n)
> (define (d i) (mod (div n (expt 10 i)) 10))
> (> (+ (d 1) (d 2))
> (+ (d 0) (d 3))))
>
> (find-max
> (group-contiguous-sequence (filter bellied? (iota 9000 1000)))
> :key length)
>
> ===>
> (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)
(defun bellied (num)
(match (@a @b @c @d) (digits num)
(< (+ a d) (+ b c))))
[find-max (split* (range 1000 9999) (op where [notf bellied])) : len]
OR:
(defun not-bellied (num)
(match (@a @b @c @d) (digits num)
(>= (+ a d) (+ b c))))
[find-max (split* (range 1000 9990) (op where not-bellied)) : len]
--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca