Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.forth > #59625
| From | "Robert L." <No_spamming@noWhere_7073.org> |
|---|---|
| Newsgroups | comp.lang.forth |
| Subject | Enigma 1713: Inventories |
| Date | 2017-05-21 02:01 +0000 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <ofqsed$1vgo$1@gioia.aioe.org> (permalink) |
> From New Scientist #2880, 1st September 2012
>
> I am going to start with a number and repeatedly take
> inventories of the digits in it. For example, if I start with
> 1531, then I read this as "one 1, one 5, one 3, one 1", which
> can be written as an inventory of 11151311. This new list has
> "three 1s, one 5, one 1, one 3, two 1s" and so has an
> inventory of 3115111321. This list, in turn, has an inventory
> of 13211531131211, and so on. Notice that in this last case,
> the original number appears as part of a subsequent inventory
> (as underlined).
>
> Find another four-figure number with the same property - one
> that appears as part of a subsequent inventory. Your original
> number must be a palindrome and its digits must add up to a
> two-figure number.
def inventory n
n.to_s.chars.chunk{|c| c}.
map{|k,v| [v.size, k]}.join
end
candidates = ("1000" .. "9999").select{|n|
n == n.reverse and n.chars.map(&:to_i).reduce(:+) > 9
}
ary = candidates.dup
begin
ary.map!{|s| inventory s}
winners = candidates.zip(ary).select{|n,s| s.include? n}
end until winners != []
winners
===>
[["3223", "3113223113"]]
In Forth?
--
The conscious and intelligent manipulation of the organized habits and opinions
of the masses is an important element in democratic society. Those who
manipulate this unseen mechanism of society constitute an invisible government
which is the true ruling power of our country. --- (((Edward Bernays)))
Back to comp.lang.forth | Previous | Next | Find similar | Unroll thread
Enigma 1713: Inventories "Robert L." <No_spamming@noWhere_7073.org> - 2017-05-21 02:01 +0000
csiph-web