Rocksolid Light

Welcome to Rocksolid Light

mail  files  register  newsreader  groups  login

Message-ID:  

UNIX is many things to many people, but it's never been everything to anybody.


computers / comp.os.linux.advocacy / Re: while((i*i) < ps) {++i;}

SubjectAuthor
o Re: while((i*i) < ps) {++i;}DFS

1
Re: while((i*i) < ps) {++i;}

<65e9b041$0$2088294$882e4bbb@reader.netnews.com>

  copy mid

https://news.novabbs.org/computers/article-flat.php?id=11831&group=comp.os.linux.advocacy#11831

  copy link   Newsgroups: comp.os.linux.advocacy
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!feeder.usenetexpress.com!tr2.iad1.usenetexpress.com!news-out.netnews.com!eu1.netnews.com!eu1.netnews.com!not-for-mail
X-Trace: DXC=\mPCUmFfbIO]2f>5GVFLaGHWonT5<]0TMQ;nb^V>PUfF5[gZBW6J?LLb4Xlnec8YjDik;KCS;OjAER3A:i1JIhbAMba][>SC2CGf;]EoU=id5F=R<hY6_C9TH
X-Complaints-To: support@blocknews.net
Date: Thu, 7 Mar 2024 07:17:05 -0500
MIME-Version: 1.0
User-Agent: Betterbird (Windows)
From: nospam@dfs.com (DFS)
Subject: Re: while((i*i) < ps) {++i;}
Newsgroups: comp.os.linux.advocacy
References: <n7uAH.19256$Eo4.8778@fx44.iad> <Jeff-Relf.Me@Mar.6--6.41pm.Seattle.2024>
Content-Language: en-US
In-Reply-To: <Jeff-Relf.Me@Mar.6--6.41pm.Seattle.2024>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 75
Message-ID: <65e9b041$0$2088294$882e4bbb@reader.netnews.com>
NNTP-Posting-Host: 127.0.0.1
X-Trace: 1709813825 reader.netnews.com 2088294 127.0.0.1:38357
 by: DFS - Thu, 7 Mar 2024 12:17 UTC

On 3/6/2024 9:41 PM, Relf wrote:
> DFS:
>> Write your own C program with a single line of logic to determine the
>> root of a given [!perfect square], without using a sqrt() function.
>>
>> My solution at:
>> http://s000.tinyupload.com/index.php?file_id=35742826989410139221
>
> Your link doesn't work. 2^.5 == 1.41421354:
>
> float Given = 2, SqrRt = 1 ; LoopJ(4) SqrRt = ( SqrRt + Given/SqrRt )/2 ;
> // For context, see "z1.CPP" in "Jeff-Relf.Me/z1.ZIP".

That post was from Dec 2020. tinyupload.com went offline in May 2021
and never came back.

The code was:

------------------------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <Windows.h>

//triangular calc
int tri(int n) { return (n*(n+1))/2; }

//program timing
LARGE_INTEGER frequency,start,end;
double elapsedtime(LARGE_INTEGER startingtimer)
{ QueryPerformanceCounter(&end);
return (end.QuadPart - startingtimer.QuadPart) /
(double)frequency.QuadPart;
}

int main(int argc, char *argv[])
{ QueryPerformanceFrequency(&frequency);
int ps = atoi(argv[1]);
int loops = atoi(argv[2]);
int j = 1;
QueryPerformanceCounter(&start);
for(int t = 0;t < loops; t++)
{
while((tri(j-1) + tri(j)) < ps) {++j;}
}
printf(" %.4fs to loop %dx Feeb method (root =
%d)\n",elapsedtime(start), loops, j);

int i = 0;
QueryPerformanceCounter(&start);
for(int t = 0;t < loops; t++)
{
while((i*i) < ps) {++i;}
}
printf(" %.4fs to loop %dx DFS method (root =
%d)\n",elapsedtime(start), loops, i);
return(0);
} ---------------------------------------------------------------------

My method was 4x-5x faster than Feeb's.

$ psqr 60481729 10000000
0.2400s to loop 10000000x Feeb method (root = 7777)
0.0536s to loop 10000000x DFS method (root = 7777)


computers / comp.os.linux.advocacy / Re: while((i*i) < ps) {++i;}

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor