Path: csiph.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: "J.O. Aho" Newsgroups: comp.lang.php Subject: Re: Competition. Date: Thu, 14 Jan 2021 18:21:02 +0100 Lines: 53 Message-ID: References: <5f16e796-155c-46ba-9c45-83c30f98f1d7n@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-Trace: individual.net LcfY/OJazhM2voWlaJJAaQDOpr3pgvFDKHjJyoO39PG45E4I1D Cancel-Lock: sha1:i8v521fynzyerV66iSqeF/CwapE= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.6.1 In-Reply-To: Content-Language: en-US-large Xref: csiph.com comp.lang.php:18510 On 14/01/2021 14.03, Arno Welzel wrote: > Y A: > >> Arno Welzel kirjutas esmaspäev, 11. jaanuar 2021 kl 02:54:38 UTC+2: >>> I I: >>>> Who will post the cross sum of following number first, will get an adorable reward from me. >>>> >>>> The number: >>>> 58349863148967341986793418678943167894317568943579812347643263461438776834177468314765864533703574653715456716465804656089576907569568456680257542768434686845796847604780607596864802468874265807426587026578406466539046579467684906749046758049663588463065836688638658768635806365889683658746862486247487652774625076485806648907696785970467957869053868763688046236880752825686569877668097860897676807746897456368844688745768468242622686282862869874986865749685796854096857706759759674569074359357697539375903576096780074367589368590356896686539 >>> 2977 >>> >>> And - what's the award? >>> >>> >>> -- >>> Arno Welzel >>> https://arnowelzel.de >> >> This is not the number, that I have on my paper. > > Then your number is wrong. 2977 is the cross sum of all digits above: > > > $value = > '58349863148967341986793418678943167894317568943579812347643263461438776834177468314765864533703574653715456716465804656089576907569568456680257542768434686845796847604780607596864802468874265807426587026578406466539046579467684906749046758049663588463065836688638658768635806365889683658746862486247487652774625076485806648907696785970467957869053868763688046236880752825686569877668097860897676807746897456368844688745768468242622686282862869874986865749685796854096857706759759674569074359357697539375903576096780074367589368590356896686539'; > > $n = 0; > for($i=0; $i $n+=(int)substr($value, $i, 1); > } > > echo $n; if you want cleaner looking code in the for loop $n+=(int)$value[$i]; or use this, of course I think it will use up more memory but a bit cleaner look. foreach(str_split($value) as $c) { $n += (int)$c; } -- //Aho