Sponsored Content
Operating Systems OS X (Apple) A Fun Perfect Square Checker Using Integer Arithmetic Only... ;o) Post 302952794 by wisecracker on Friday 21st of August 2015 06:17:15 PM
Old 08-21-2015
Hi all...

For those that don't know, ths is the method used...

Take all of the odd numbers in a series:-

1, 3, 5, 7, 9, 11, 13........

Then:-
[1] 1 = 1 = 1^2

[2] 1+3 = 4 = 2^2

[3] 4+5 = 1+3+5 = 9 = 3^2

[4] 9+7 = 1+3+5+7 = 16 = 4^2

[5] 16+9 = 1+3+5+7+9 = 25 = 5^2

[6] 25+11 = 1+3+5+7+9+11 = 36 = 6^2

[7] 36+13 = 1+3+5+7+9+11+13 = 49 = 7^2

And so on...

It is as simple as that, nothing more nothing less...
The linear addition by one of the square bracketed __line_numbers__ are the integer, (perfect), square root...

Hope this makes sense...

As I quoted it is a fun tongue-in-cheek method...
 

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

extraction of perfect text from file.

Hi All, I have a file of the following format. <?xml version='1.0' encoding='utf-8'?> <tomcat-users> <role rolename="tomcat"/> <role rolename="role1"/> <role rolename="manager"/> <role rolename="admin"/> <user username="tomcat" password="tomcat" roles="tomcat"/> <user... (5 Replies)
Discussion started by: nua7
5 Replies

2. UNIX for Dummies Questions & Answers

A perfect number shell program

Here's my work of testing whether a number input is perfect or not.. echo Enter a number read no i=1 ans=0 while do if then ans='expr $ans + $i' fi i='expr $i + 1' done if then echo $no is perfect else echo $no is NOT perfect fi (12 Replies)
Discussion started by: Cyansnow
12 Replies

3. AIX

I want the perfect user-interface

I've got an aix-box somewhere on the network and a PC on my desk. Nothing fancy so far. The PC is made dual-boot: - windowsXP with putty & winSCP or - slackware 13 with xfce4 installed. The aix-box runs DB2 v8.2 and I've installed db2top to monitor the database. db2top is a character... (0 Replies)
Discussion started by: dr_te_z
0 Replies

4. Shell Programming and Scripting

Delete text between square brackets and also delete those square brackets using sed or awk

Hi All, I have a text file which looks like this: computer programming systems engineering I want to get rid of these square brackets and also the text that is inside these brackets. So that my final text file looks like this: computer programming systems engineering I am using... (3 Replies)
Discussion started by: shoaibjameel123
3 Replies

5. Shell Programming and Scripting

how to compare string integer with an integer?

hi, how to I do this? i="4.000" if ; then echo "smaller" fi how do I convert the "4.000" to 4? Thanks! (4 Replies)
Discussion started by: h0ujun
4 Replies

6. UNIX for Dummies Questions & Answers

Can you perfect my sed ?

I want to print only the lines that meet the criteria : "worde:" and "wordo;" I got this far: sed -n '/\(*\)\1e:\1o;/p;' But it doesn't quite work. Can someone please perfect it and tell me exactly how its a fixed version/what was wrong with mine? Thanks heaps, (1 Reply)
Discussion started by: maximus73
1 Replies

7. Shell Programming and Scripting

egrep line with perfect mach

Hi Input File A L006 AL01 0 (OCK) L006 A006 0 (OCK) L011 AR11 1 (NLOCK) Input File B L006 AL01 0 (OCK) L006 A006 0 (OCK) Need Egrep Command for perfect Match Thanks (4 Replies)
Discussion started by: asavaliya
4 Replies

8. Shell Programming and Scripting

Not able to find the perfect code...Geting confused in between

I have to find last delimiter in each line of a file and store the value after the last '/' in a variable in ksh script...Pls Pls help me:(The file is as shown below: /opt/apps/cobqa/apps/abadv/bind/advc0007.bnd /opt/apps/cobqa/apps/abbrio/bind/naac6115.bnd... (5 Replies)
Discussion started by: bhavanabahety
5 Replies
EV(1)							      General Commands Manual							     EV(1)

NAME
ev - evaluate expressions SYNOPSIS
ev 'expr' .. DESCRIPTION
Ev evaluates expressions given on the command line, and sends the results to the standard output, one per line. An expression contains real numbers, function calls, and the following operators: + - * / ^ Operators are evaluated left to right, except '^', which is right associative. Powers have the highest precedence; multiplication and division are evaluated before addition and subtraction. Expressions can be grouped with parentheses. All values are double precision real. The following library of functions is available: if(cond, then, else) if cond is greater than zero, then is evaluated, otherwise else is evaluated. select(N, a1, a2, ..) return aN (N is rounded to the nearest integer). If N is zero, the number of available arguments is returned. rand(x) compute a random number between 0 and 1 based on x. floor(x) return largest integer not greater than x. ceil(x) return smallest integer not less than x. sqrt(x) return square root of x. exp(x) compute e to the power of x (e approx = 2.718281828). log(x) compute the logarithm of x to the base e. log10(x) compute the logarithm of x to the base 10. sin(x), cos(x), tan(x) trigonometric functions. asin(x), acos(x), atan(x) inverse trigonometric functions. atan2(y, x) inverse tangent of y/x (range -pi to pi). EXAMPLE
To pass the square root of two and the sine of .5 to a program: program `ev 'sqrt(2)' 'sin(.5)'` AUTHOR
Greg Ward SEE ALSO
icalc(1), rcalc(1) RADIANCE
10/28/96 EV(1)
All times are GMT -4. The time now is 07:50 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy