Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #18510

Re: Competition.

From "J.O. Aho" <user@example.net>
Newsgroups comp.lang.php
Subject Re: Competition.
Date 2021-01-14 18:21 +0100
Message-ID <i6bcruFegmgU1@mid.individual.net> (permalink)
References <5f16e796-155c-46ba-9c45-83c30f98f1d7n@googlegroups.com> <i61lu7FgksvU1@mid.individual.net> <c121ff51-1191-47a3-b9ae-2238e591d168n@googlegroups.com> <i6atp9Fbgc7U1@mid.individual.net>

Show all headers | View raw


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:
> 
> <?php
> 
> $value =
> '58349863148967341986793418678943167894317568943579812347643263461438776834177468314765864533703574653715456716465804656089576907569568456680257542768434686845796847604780607596864802468874265807426587026578406466539046579467684906749046758049663588463065836688638658768635806365889683658746862486247487652774625076485806648907696785970467957869053868763688046236880752825686569877668097860897676807746897456368844688745768468242622686282862869874986865749685796854096857706759759674569074359357697539375903576096780074367589368590356896686539';
> 
> $n = 0;
> for($i=0; $i<strlen($value); $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

Back to comp.lang.php | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Competition. I I <kpuctjanpobam@mail.com> - 2021-01-09 11:33 -0800
  Re: Competition. Arno Welzel <usenet@arnowelzel.de> - 2021-01-11 01:54 +0100
    Re: Competition. Y A <kpuctjanpobam@mail.com> - 2021-01-12 05:31 -0800
      Re: Competition. Arno Welzel <usenet@arnowelzel.de> - 2021-01-14 14:03 +0100
        Re: Competition. ند ارائه نماييدبا تشکر ند ارائه نمايي تش <kpuctjanpobam@mail.com> - 2021-01-14 08:31 -0800
        Re: Competition. "J.O. Aho" <user@example.net> - 2021-01-14 18:21 +0100
    Re: Competition. Jerry Stuckle <jstucklex@attglobal.net> - 2021-01-12 12:35 -0500
      Re: Competition. Y A <kpuctjanpobam@mail.com> - 2021-01-13 03:14 -0800
        Re: Competition. Jerry Stuckle <jstucklex@attglobal.net> - 2021-01-13 19:27 -0500

csiph-web