Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

You will inherit millions of dollars.


comp / comp.lang.lisp / Re: X in every language syndrome

SubjectAuthor
* Re: X in every language syndromeB. Pym
+- Re: X in every language syndromeHenHanna
+- Re: X in every language syndromeKaz Kylheku
`- Re: X in every language syndromeB. Pym

1
Subject: Re: X in every language syndrome
From: B. Pym
Newsgroups: comp.lang.lisp
Organization: A noiseless patient Spider
Date: Sat, 6 Jul 2024 21:58 UTC
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: No_spamming@noWhere_7073.org (B. Pym)
Newsgroups: comp.lang.lisp
Subject: Re: X in every language syndrome
Date: Sat, 6 Jul 2024 21:58:58 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 83
Message-ID: <v6cemu$3vogb$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Date: Sat, 06 Jul 2024 23:58:59 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="0306c62257a9c83d9f71b4161d0a4a5a";
logging-data="4186635"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18xu4/+wvl0nn2RMIAoc8uD"
User-Agent: XanaNews/1.18.1.6
Cancel-Lock: sha1:R69+Q9yeXwldpluoEdAvCZ9ZGhI=
View all headers

> The question is about so-called "bellied"
> numbers, defined as 4-digit integers for which the sum of the two
> "middle" digits is smaller than the sum of the two outer digits. So 1265
> is bellied, while 4247 is not.

[ He means the sum of middle digits is larger. ]

>
> This checking part is easy:
>
> (defun bellied-number-p (n)
> (> (+ (mod (truncate n 10) 10) (mod (truncate n 100) 10))
> (+ (mod n 10) (truncate n 1000))))
>
> Now the task is to find the longest, uninterrupted sequence of bellied
> numbers within all 4-digit number, hence from 1000 to 9999. And this is
> where I terribly screwed up:
>
> While the following code does the job,
>
> (let ((max-length 0)
> (current-length 0)
> (last-bellied-number 0))
> (dotimes (m 9000)
> (let ((n (+ 1000 m)))
> (if (bellied-number-p n)
> (incf current-length)
> (progn
> (when (> current-length max-length)
> (setf max-length current-length)
> (setf last-bellied-number (1- n)))
> (setf current-length 0)))))
> (print (format t "~&Longest sequence of ~a bellied numbers ends at ~a."
> max-length last-bellied-number)))

[ 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)

Subject: Re: X in every language syndrome
From: HenHanna
Newsgroups: comp.lang.lisp
Organization: A noiseless patient Spider
Date: Sun, 7 Jul 2024 05:21 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: HenHanna@devnull.tb (HenHanna)
Newsgroups: comp.lang.lisp
Subject: Re: X in every language syndrome
Date: Sat, 6 Jul 2024 22:21:06 -0700
Organization: A noiseless patient Spider
Lines: 108
Message-ID: <v6d8k2$771q$1@dont-email.me>
References: <v6cemu$3vogb$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 07 Jul 2024 07:21:07 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="cf7c2fa96044547c90e4fddda328c141";
logging-data="236602"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19K+PWYx90RQ1m5cV9tvWFELam7QS9a9Cg="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:dxXf5PELfC5mpYwVFpDaS+wwxS0=
In-Reply-To: <v6cemu$3vogb$1@dont-email.me>
Content-Language: en-US
View all headers

On 7/6/2024 2:58 PM, B. Pym wrote:
>> The question is about so-called "bellied"
>> numbers, defined as 4-digit integers for which the sum of the two
>> "middle" digits is smaller than the sum of the two outer digits. So 1265
>> is bellied, while 4247 is not.
>
> [ He means the sum of middle digits is larger. ]
>
>>
>> This checking part is easy:
>>
>> (defun bellied-number-p (n)
>> (> (+ (mod (truncate n 10) 10) (mod (truncate n 100) 10))
>> (+ (mod n 10) (truncate n 1000))))
>>
>> Now the task is to find the longest, uninterrupted sequence of bellied
>> numbers within all 4-digit number, hence from 1000 to 9999. And this is
>> where I terribly screwed up:
>>
>> While the following code does the job,
>>
>> (let ((max-length 0)
>> (current-length 0)
>> (last-bellied-number 0))
>> (dotimes (m 9000)
>> (let ((n (+ 1000 m)))
>> (if (bellied-number-p n)
>> (incf current-length)
>> (progn
>> (when (> current-length max-length)
>> (setf max-length current-length)
>> (setf last-bellied-number (1- n)))
>> (setf current-length 0)))))
>> (print (format t "~&Longest sequence of ~a bellied numbers ends at ~a."
>> max-length last-bellied-number)))
>
> [ 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)

> ,print-mode pretty #t length #f width 64 <--- What does this line do?

______________________

the Opposite of Humped must be Hourglass (shaped)

gosh> (load "hump.lsp")

(9000 9001 9002 9003 9004 9005 9006 9007 9008 9009 9010 9011 9012 9013
9014 9015 9016 9017 9018 9019 9020 9021 9022 9023 9024 9025 9026 9027
9028 9029 9030 9031 9032 9033 9034 9035 9036 9037 9038 9039 9040 9041
9042 9043 9044 9045 9046 9047 9048 9049 9050 9051 9052 9053 9054 9055
9056 9057 9058 9059 9060 9061 9062 9063 9064 9065 9066 9067 9068 9069
9070 9071 9072 9073 9074 9075 9076 9077 9078 9079 9080 9081 9082 9083
9084 9085 9086 9087 9088 9089)
#t
gosh>

Subject: Re: X in every language syndrome
From: Kaz Kylheku
Newsgroups: comp.lang.lisp
Organization: A noiseless patient Spider
Date: Sun, 7 Jul 2024 05:58 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 643-408-1753@kylheku.com (Kaz Kylheku)
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=
View all headers

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

Subject: Re: X in every language syndrome
From: B. Pym
Newsgroups: comp.lang.lisp
Organization: A noiseless patient Spider
Date: Sun, 7 Jul 2024 19:42 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: No_spamming@noWhere_7073.org (B. Pym)
Newsgroups: comp.lang.lisp
Subject: Re: X in every language syndrome
Date: Sun, 7 Jul 2024 19:42:18 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 109
Message-ID: <v6er2n$fd6o$1@dont-email.me>
References: <v6cemu$3vogb$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Date: Sun, 07 Jul 2024 21:42:19 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="988aed472a54273a376e5503f1be245e";
logging-data="505048"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18fKLAcSJx6FMq8BfUPnLUX"
User-Agent: XanaNews/1.18.1.6
Cancel-Lock: sha1:LpKQbivOpK4m+1OVqHd3tSjUBx4=
View all headers

On 7/6/2024, B. Pym wrote:

> > The question is about so-called "bellied"
> > numbers, defined as 4-digit integers for which the sum of the two
> > "middle" digits is smaller than the sum of the two outer digits. So 1265
> > is bellied, while 4247 is not.
>
> [ He means the sum of middle digits is larger. ]
>
> >
> > This checking part is easy:
> >
> > (defun bellied-number-p (n)
> > (> (+ (mod (truncate n 10) 10) (mod (truncate n 100) 10))
> > (+ (mod n 10) (truncate n 1000))))
> >
> > Now the task is to find the longest, uninterrupted sequence of bellied
> > numbers within all 4-digit number, hence from 1000 to 9999. And this is
> > where I terribly screwed up:
> >
> > While the following code does the job,
> >
> > (let ((max-length 0)
> > (current-length 0)
> > (last-bellied-number 0))
> > (dotimes (m 9000)
> > (let ((n (+ 1000 m)))
> > (if (bellied-number-p n)
> > (incf current-length)
> > (progn
> > (when (> current-length max-length)
> > (setf max-length current-length)
> > (setf last-bellied-number (1- n)))
> > (setf current-length 0)))))
> > (print (format t "~&Longest sequence of ~a bellied numbers ends at ~a."
> > max-length last-bellied-number)))
>
> [ 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)

A lower-level way.

(define (bellied? n)
(define (d i) (mod (div n (expt 10 i)) 10))
(> (+ (d 1) (d 2))
(+ (d 0) (d 3))))

(define (calc-length i)
(do ((j i (+ j 1)))
((not (bellied? j)) (- j i))))

(define (longest-bellied-seq)
(let go ((i 1000) (start 0) (len 0))
(if (> i 9999)
(list start len)
(let ((new-len (calc-length i)))
(cond ((zero? new-len) (go (+ i 1) start len))
((> new-len len) (go (+ i new-len) i new-len))
(#t (go (+ i new-len) start len)))))))

===>
(1920 80)

1

rocksolid light 0.9.8
clearnet tor