Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Challenges

Getting perfect squares, differently

+1
−0

Create a program that gets all perfect squares starting from 0 or 1 without using any methods of multiplication (repetitive addition) and exponentiation (repetitive multiplication). Output them for validation.

Things such as built-ins/functions related to these unusable methods can't be used either. pow(x,y) and x**y are examples of these unusable methods.

A simple, yet tricky activity! Being code-golf, the shortest program in each programming language wins!

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.
Why should this post be closed?

2 comment threads

Banning builtins isn't a great idea (4 comments)
What exactly do you mean by "all"? (2 comments)

7 answers

You are accessing this answer with a direct link, so it's being shown above all other answers regardless of its score. You can return to the normal view.

+0
−0

Lua, 41 40 bytes

x=0 y=1while""do print(x)x=x+y y=y+2 end

Try it online!

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

0 comment threads

+1
−0

Japt, 9 bytes

No infinite lists in Japt so we'll have to go with a recursive solution.

ßOpTµJJµ2

Test it

ßOpTµJJµ2
ß             :Recursive call with (irrelevant) argument
 Op           :  Output with trailing newline (returns undefined and second argument is ignored)
   TµJ        :    Decrement T (initially 0) by J (initially -1)
      Jµ2     :    Decrement J by 2
History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

0 comment threads

+1
−0

Husk, 3 bytes

∫İ1

Try it online!

Scan from left over all odd numbers with addition.

Uses this formula:

$$ n^2 = \sum_{k=1}^n(2k-1) $$

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

0 comment threads

+1
−0

JavaScript (V8), 28 bytes

for(x=y=0;;++y)print(x+=++y)

Try it online!

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

0 comment threads

+0
−0

PHP, 57 bytes

<?php $x=0;$y=1;while(1){echo(string)($x+=$y)." ";$y+=2;}

Try it online!

PHP's a nice language, I tell ya.

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

0 comment threads

+0
−0

Python 3, 34 bytes

x=0;y=1
while 1:x+=y;print(x);y+=2

Try it online!

1 is the int equivalent to True, which helps save bytes.

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

0 comment threads

+0
−0

C (clang), 47 45 43 bytes

i,j;main(){for(;printf("%i ",i-=~j);j+=2);}

Try it online!

Golfed 2 bytes from inspiration of @Shaggy's answer. Golfed 2 bytes by @m90.

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

1 comment thread

Improvement (1 comment)

Sign up to answer this question »