| Bytes | Lang | Time | Link |
|---|---|---|---|
| 016 | Uiua | 250911T205853Z | nyxbird |
| 042 | AWK | 250911T180805Z | xrs |
| 020 | TIBASIC TI84 Plus CE Python | 250911T160737Z | madeforl |
| 077 | Juby | 250505T002823Z | Jordan |
| 024 | CASIO BASIC CASIO fx9750GIII | 250507T150707Z | madeforl |
| 041 | Ruby | 230811T005020Z | Value In |
| 006 | Vyxal 3 | 250505T091441Z | Themooni |
| 033 | ARBLE | 230811T050608Z | ATaco |
| 014 | Vyxal | 230810T194745Z | Joao-3 |
| 039 | Arturo | 230810T151017Z | chunes |
| 005 | Vyxal | 230810T102223Z | emanresu |
| 005 | Thunno 2 | 230810T101626Z | The Thon |
| 061 | C# Visual C# Interactive Compiler | 180915T052642Z | Epicness |
| 009 | Stax | 180913T185543Z | Khuldrae |
| 009 | MATL | 181211T145649Z | Sanchise |
| 016 | Pyth | 180916T194828Z | kungfush |
| 4305 | Taxi | 181006T032724Z | JosiahRy |
| 046 | APLNARS | 181006T134451Z | user5898 |
| 004 | MathGolf | 180912T115838Z | maxb |
| 074 | C# .NET Core | 181005T200654Z | Meerkat |
| 005 | Ohm v2 | 181005T203634Z | ThePlasm |
| 020 | Wolfram Language Mathematica | 181005T191308Z | Misha La |
| 070 | Java 8 | 180911T073046Z | Kevin Cr |
| 047 | Groovy | 180912T204345Z | archange |
| 047 | Perl 5 | 180912T200248Z | yomother |
| 007 | Pyt | 180910T214333Z | mudkip20 |
| 008 | Brachylog | 180911T081926Z | Kroppeb |
| 111 | F# | 180911T233140Z | Ciaran_M |
| 042 | JavaScript ES7 | 180910T182707Z | Arnauld |
| 034 | Perl 6 | 180910T224154Z | Jo King |
| 053 | Haskell | 180911T011428Z | totallyh |
| 067 | Scala | 180911T001945Z | Varon |
| 059 | C gcc | 180910T183054Z | cleblanc |
| 067 | Red | 180911T125909Z | Galen Iv |
| 037 | Matlab | 180910T184028Z | DimChtz |
| 023 | Pari/GP | 180911T071106Z | alephalp |
| 022 | K oK | 180910T192056Z | mkst |
| 415 | Shakespeare Programming Language | 180911T005159Z | JosiahRy |
| 043 | Octave / MATLAB | 180910T214550Z | Luis Men |
| 032 | Mathematica | 180910T205856Z | LegionMa |
| 018 | APL Dyalog Unicode | 180910T204115Z | J. Sall& |
| 041 | Proton | 180910T200525Z | hyperneu |
| 005 | Gaia | 180910T195304Z | Mr. Xcod |
| 007 | Japt | 180910T182952Z | Luis fel |
| 006 | Jelly | 180910T182536Z | Jonathan |
| 005 | 05AB1E | 180910T183853Z | Jonathan |
| 056 | PowerShell | 180910T184211Z | AdmBorkB |
| 006 | Husk | 180910T184403Z | ბიმო |
| 055 | Python 2 | 180910T184005Z | Chas Bro |
| 005 | Neim | 180910T183840Z | Okx |
| 037 | R | 180910T182922Z | Giuseppe |
Uiua, 16 bytes
=⊸⁅⍜°√/+⊂⊚=0⊸◿⊸⇡
⊸⇡ # range up to n
⊚=0⊸◿ # where mod by n equals 0
⊂ # join n
⍜°√/+ # under squaring, sum
=⊸⁅ # equal to rounded?
TI-BASIC (TI-84 Plus CE Python), 20 bytes
not(fPart(√(Σ(F²not(fPart(Ans/F)),F,1,Ans
J-uby, 77 bytes
~:^%(:& &(:%|:>&1)|:+&:select|:|&:+|~:|&(:sum+(~:**&2)|~:**&0.5|~:%&1|:==&0))
CASIO BASIC (CASIO fx-9750GIII), 24 bytes
?→N
Not Frac √Σ(F²Not Frac N⌟F,F,1,N
outputs 1 or 0 for true or false respectively
Vyxal 3, 6 bytes
K²∑√/⌊
K²∑√/⌊
√ # is the square root of
∑ # the sum of
K # the implicit input's factors
² # squared
/⌊ # an integer?
💎
Created with the help of Luminespire.
<script type="vyxal3">
K²∑√/⌊
</script>
<script>
args=[["42"],["1"],["246"],["10"],["16"]]
</script>
<script src="https://themoonisacheese.github.io/snippeterpreter/snippet.js" type="module"/>
Vyxal, 14 bytes (Test cases)
ɾḊT›ƛ:*;ƒ+√:ṙ=
Arturo, 39 bytes
$=>[=floor<=sqrt∑map factors&'x->x*x]
$=>[ ; a function where input is assigned to &
factors& ; divisors of the input
map _ 'x->x*x ; square each
∑ ; sum
sqrt ; square root
<= ; duplicate
floor ; floor
= ; are the equal?
] ; end function
Vyxal, 5 bytes
K²∑∆²
∆² # Is
∑ # The sum of
² # The squares of
K # The factors of the input
∆² # A perfect square?
Thunno 2, 5 bytes
F²SƲ
Explanation
F²SƲ # Implicit input
F # Factors
² # Square
S # Sum
Ʋ # Perfect square
# Implicit output
C# (Visual C# Interactive Compiler), 141 137 135 131 61 bytes
Thanks ASCII-only.
a=>Math.Sqrt(Enumerable.Range(1,a).Sum(b=>a%b==0?b*b:0))%1==0
Explanation:
a => Math.Sqrt( ) % 1 == 0 //Square root, test for whole number
Enumerable.Range(1, a).Sum( ) //Sum 1 through a with..
b => a % b==0 ? b * b: 0 //b^2 if a modulo b = 0, else 0
Stax, 10 9 bytes
▀ùj╦┬44eR
Run and debug it at staxlang.xyz!
Unpacked (11 bytes) and explanation:
:d{J+kc|qJ=
:d Implicit input. Make list of divisors.
{ k Reduce using block:
J+ Square and add to the running total.
c Copy this sum of squares on the stack.
|qJ Take square root, rounding down. Square.
= Check for equality.
MATL, 9 bytes
Z\UsX^tk=
As simple as it gets
Z\ % Divisors of (implicit) input
U % Square
s % Sum
X^ % Square root
t % Duplicate this value
k= % Is it equal to its rounded value?
Pyth, 26 16 bytes
!%@s^R2*M{yPQ2 1
I'm new to Pyth (and golfing in general) so this is pretty bad. Pyth doesn't have a built-in to get divisors, so I had to do that. Up until the perfect-square check, it was pretty alright, but after that it became a bit cluttered because of the if statement. Criticism is welcome.
-10 bytes thanks to Sok
Explanation:
Q #get user input
*M{yP #get the divisors
^R2 #square each divisor
s #sum the list
@ 2 #get square root
% 1 #check if sqrt is a whole number (mod 1)
! #invert (0 -> True, any other num -> False)
Taxi, 4430 4305 bytes
Go to Post Office:w 1 l 1 r 1 l.Pickup a passenger going to The Babelfishery.Go to The Babelfishery:s 1 l 1 r.Pickup a passenger going to Cyclone.0 is waiting at Starchild Numerology.0 is waiting at Starchild Numerology.Go to Starchild Numerology:n 1 l 1 l 1 l 2 l.Pickup a passenger going to Rob's Rest.Pickup a passenger going to Addition Alley.Go to Rob's Rest:w 1 r 2 l 1 r.Go to Cyclone:s 1 l 1 l 2 l.[B]Pickup a passenger going to Divide and Conquer.1 is waiting at Starchild Numerology.Go to Starchild Numerology:n 1 r 3 l.Pickup a passenger going to Addition Alley.Go to Addition Alley:w 1 r 3 r 1 r 1 r.Pickup a passenger going to Cyclone.Go to Cyclone:n 1 l 1 l.Pickup a passenger going to Sunny Skies Park.Pickup a passenger going to Divide and Conquer.Go to Divide and Conquer:n 2 r 2 r 1 r.Pickup a passenger going to Cyclone.Go to Sunny Skies Park:e 1 l 1 l 2 l 1 l.Go to Zoom Zoom:n 1 r.Go to Cyclone:w.Pickup a passenger going to Sunny Skies Park.Pickup a passenger going to Equal's Corner.Pickup a passenger going to Trunkers.Go to Sunny Skies Park:n 1 r.Go to Trunkers:s 1 l.Pickup a passenger going to Equal's Corner.Go to Equal's Corner:w 1 l.Switch to plan C if no one is waiting.Pickup a passenger going to Riverview Bridge.Go to Sunny Skies Park:n.Pickup a passenger going to Sunny Skies Park.Pickup a passenger going to Cyclone.Go to Riverview Bridge:n 1 r 1 r.Go to Cyclone:w 2 l.Pickup a passenger going to Cyclone.Go to Sunny Skies Park:n 1 r.Go to Cyclone:n 1 l.Pickup a passenger going to Multiplication Station.Pickup a passenger going to Multiplication Station.Go to Multiplication Station:s 1 l 2 r 4 l.Pickup a passenger going to Addition Alley.Go to Rob's Rest:s 1 r 2 l 1 l 1 r 1 r.Pickup a passenger going to Addition Alley.Go to Addition Alley:s 1 l 1 l 2 r 1 r 1 r.Pickup a passenger going to Rob's Rest.Go to Rob's Rest:n 1 l 1 l 1 l 2 r 1 r.Go to Cyclone:s 1 l 1 l 2 l.Pickup a passenger going to Magic Eight.Go to Sunny Skies Park:n 1 r.Pickup a passenger going to Cyclone.Go to Cyclone:n 1 l.Pickup a passenger going to Cyclone.Pickup a passenger going to Magic Eight.Go to Magic Eight:s 1 l 2 r.Switch to plan D if no one is waiting.Pickup a passenger going to Addition Alley.Go to Cyclone:n 1 l 2 r.Switch to plan B.[C]Go to Sunny Skies Park:n.Pickup a passenger going to Cyclone.Pickup a passenger going to Addition Alley.Go to Cyclone:n 1 l.Switch to plan B.[D]Go to Cyclone:n 1 l 2 r.Pickup a passenger going to Sunny Skies Park.Pickup a passenger going to Sunny Skies Park.Go to Sunny Skies Park:n 1 r.Go to Rob's Rest:s 2 r 1 r.Pickup a passenger going to Cyclone.Go to Cyclone:s 1 l 1 l 2 l.Pickup a passenger going to Cyclone.Pickup a passenger going to Cyclone.Go to Zoom Zoom:n.Go to Cyclone:w.[E]Pickup a passenger going to Joyless Park.Pickup a passenger going to Divide and Conquer.Go to Joyless Park:n 2 r 2 r 2 l.Go to Cyclone:w 1 r 2 l 2 l.Pickup a passenger going to Cyclone.Pickup a passenger going to Joyless Park.Go to Joyless Park:n 2 r 2 r 2 l.Go to Cyclone:w 1 r 2 l 2 l.Pickup a passenger going to Divide and Conquer.Pickup a passenger going to Divide and Conquer.Go to Divide and Conquer:n 2 r 2 r 1 r.Pickup a passenger going to Magic Eight.1 is waiting at Starchild Numerology.Go to Starchild Numerology:e 1 r 3 r 1 l 1 l 2 l.Pickup a passenger going to Magic Eight.Go to Magic Eight:w 1 r 2 r 1 r.Switch to plan F if no one is waiting.Pickup a passenger going to Riverview Bridge.Go to Joyless Park:e 2 l 4 r.Pickup a passenger going to Cyclone.Pickup a passenger going to The Underground.Go to The Underground:w 1 l.Pickup a passenger going to Cyclone.Go to Fueler Up:s.Go to Riverview Bridge:n 3 l.Go to Cyclone:w 2 l.Switch to plan E.[F]Go to Joyless Park:e 2 l 4 r.Pickup a passenger going to What's The Difference.Pickup a passenger going to Cyclone.Go to Cyclone:w 1 r 2 l 2 l.Pickup a passenger going to Multiplication Station.Pickup a passenger going to Multiplication Station.Go to Multiplication Station:s 1 l 2 r 4 l.Pickup a passenger going to What's The Difference.Go to What's The Difference:n 2 l 1 r 3 l.Pickup a passenger going to Knots Landing.Go to Knots Landing:e 4 r 1 l.Pickup a passenger going to The Babelfishery.Go to The Babelfishery:w 1 l.Pickup a passenger going to Post Office.Go to Post Office:n 1 l 1 r.
I went to a lot of places in Townsburg that I've never visited before for this program. Because this program is HUGE (mainly due to the fact that there isn't a one-stop way to take square roots; I still don't actually do that, though), I'm going to attempt to sketch out an explanation of this program.
Go to Post Office:w 1 l 1 r 1 l.
[Take an input line from STDIN.]
Pickup a passenger going to The Babelfishery.
Go to The Babelfishery:s 1 l 1 r.
[Take it to The Babelfishery, which converts the string to a double.]
[If you were to give it a double, it gives back a string.]
Pickup a passenger going to Cyclone.
[We're going to clone this number by sending it to the Cyclone.]
0 is waiting at Starchild Numerology.
[In Taxi, numeric passengers are introduced once they wait at Starchild Numerology.]
[This passenger will be our running squares total.]
0 is waiting at Starchild Numerology.
[This passenger will be our counter, going from 1 to the inputted number.]
[Yes, it's starting at 0 here, but it is incremented at the start of our loop.]
Go to Starchild Numerology:n 1 l 1 l 1 l 2 l.
Pickup a passenger going to Rob's Rest.
Pickup a passenger going to Addition Alley.
Go to Rob's Rest:w 1 r 2 l 1 r.
Go to Cyclone:s 1 l 1 l 2 l.
[Drop off the squares total at Rob's Rest. We'll pick it back up later when we need it.]
[Also, do the actual cloning of the inputted number.]
[At the start of each loop, our only passenger is the counter, going to Addition Alley.]
[B]
Pickup a passenger going to Divide and Conquer.
[Pick up one of the clones of the inputted number.]
[We will leave the other clone here for later.]
1 is waiting at Starchild Numerology.
Go to Starchild Numerology:n 1 r 3 l.
Pickup a passenger going to Addition Alley.
Go to Addition Alley:w 1 r 3 r 1 r 1 r.
Pickup a passenger going to Cyclone.
[Pick up the number 1, and add it to the counter, then pick up the result.]
[This new passenger is our new counter.]
Go to Cyclone:n 1 l 1 l.
Pickup a passenger going to Sunny Skies Park.
Pickup a passenger going to Divide and Conquer.
[First we pick up the other clone of the inputted number, going to Sunny Skies Park.]
[Sunny Skies Park is basically a First-In-First-Out queue, where we will stick it for later.]
[Then we pick up a clone of the counter which we just dropped off, so we can divide the input by it.]
[We will leave the other clone here for later.]
Go to Divide and Conquer:n 2 r 2 r 1 r.
Pickup a passenger going to Cyclone.
[Divide the inputted number by the counter, and prepare to clone it.]
Go to Sunny Skies Park:e 1 l 1 l 2 l 1 l.
[Drop off our clone of the inputted number at Sunny Skies Park.]
Go to Zoom Zoom:n 1 r.
[Can't forget to get gas!]
[Zoom Zoom is a close gas station, and we have so many credits that one stop here every iteration fills us up completely.]
Go to Cyclone:w.
Pickup a passenger going to Sunny Skies Park.
Pickup a passenger going to Equal's Corner.
Pickup a passenger going to Trunkers.
[First we pick up the other clone of the counter, going to Sunny Skies Park for later.]
[Then we pick up a clone of the division result, going to Equal's Corner.]
[Equal's Corner takes multiple numeric passengers, and returns the value of one of them if they are equal, but otherwise it returns no one.]
[Finally we pick up the other clone of the division result, going to Trunkers.]
[Dropping off a passenger at Trunkers is equivalent to the floor function. We need it here because division results are "exact".]
[(Well, as exact as double precision arithmetic can be.)]
[We will compare the result of this to the exact result of the division.]
Go to Sunny Skies Park:n 1 r.
[Drop off our clone of the counter at Sunny Skies Park.]
Go to Trunkers:s 1 l.
Pickup a passenger going to Equal's Corner.
Go to Equal's Corner:w 1 l.
[Compare the exact division result with the floored division result.]
[If they are equal, then the value of one of them will be waiting.]
[This also means that the counter is a divisor of the input, and we should add the square of the counter to our running squares total.]
[If they are not equal, no one will be waiting, the counter is not a divisor of the input, and nothing should happen.]
Switch to plan C if no one is waiting.
[This is Taxi's only conditional operator.]
[It jumps to a bracketed label (in this case, C) if there is no one waiting at this stop.]
[Of course, there is an unconditional version of this, too.]
[If we are on this path, we are adding the square of the counter to our running squares total.]
Pickup a passenger going to Riverview Bridge.
[We don't actually need the passenger that's waiting here (and leaving it there will not work at all).]
[So what do you do when you have a pesky passenger you don't want? You take them to Riverview Bridge!]
[Riverview Bridge has a lovely view, but passengers dropped off there always seem to fall in the river.]
[This means you don't collect your fare for bringing them there, but at least the pesky passenger is gone.]
Go to Sunny Skies Park:n.
Pickup a passenger going to Sunny Skies Park.
Pickup a passenger going to Cyclone.
[We want to pick up the counter (so we can multiply it by itself). That dang input is in the way, but we still need it.]
[So what do we do? We just take it back to where it was waiting!]
[Yup, even though one would never do this in real life, a passenger's current location is a perfectly legal destination in Taxi.]
Go to Riverview Bridge:n 1 r 1 r.
[So long, Equal's Corner result!]
Go to Cyclone:w 2 l.
Pickup a passenger going to Cyclone.
Go to Sunny Skies Park:n 1 r.
[We clone the counter so we can still use it, then we drop the inputted number back at Sunny Side Park.]
[Again, we will leave the other clone here for later.]
Go to Cyclone:n 1 l.
Pickup a passenger going to Multiplication Station.
Pickup a passenger going to Multiplication Station.
Go to Multiplication Station:s 1 l 2 r 4 l.
[Square the counter.]
Pickup a passenger going to Addition Alley.
Go to Rob's Rest:s 1 r 2 l 1 l 1 r 1 r.
Pickup a passenger going to Addition Alley.
Go to Addition Alley:s 1 l 1 l 2 r 1 r 1 r.
Pickup a passenger going to Rob's Rest.
Go to Rob's Rest:n 1 l 1 l 1 l 2 r 1 r.
[Pick up the running squares total from Rob's Rest, add it to the square of the counter, then bring it back.]
Go to Cyclone:s 1 l 1 l 2 l.
Pickup a passenger going to Magic Eight.
[Pick up the counter, going to Magic Eight.]
[Magic Eight takes two numeric passengers, and returns the first passenger if it is less than the second, but otherwise it returns no one.]
[We will compare the counter to the inputted number...]
Go to Sunny Skies Park:n 1 r.
Pickup a passenger going to Cyclone.
Go to Cyclone:n 1 l.
Pickup a passenger going to Cyclone.
Pickup a passenger going to Magic Eight.
[...who we take now, so we can make a clone of it and compare it to the counter.]
Go to Magic Eight:s 1 l 2 r.
Switch to plan D if no one is waiting.
[Compare.]
[If the counter is waiting here, the loop is to continue.]
[If not, switch to plan D, end the loop, and start detecting whether or not the running squares total is a square itself.]
Pickup a passenger going to Addition Alley.
Go to Cyclone:n 1 l 2 r.
Switch to plan B.
[Reset everything, and loop back to the start of plan B.]
[C]
[If we are on this path, the counter is not a divisor of the inputted number, but the loop should continue anyways.]
Go to Sunny Skies Park:n.
Pickup a passenger going to Cyclone.
Pickup a passenger going to Addition Alley.
Go to Cyclone:n 1 l.
Switch to plan B.
[Reset everything, and loop back to the start of plan B.]
[D]
[We are finally out of the loop. Now it's time for the real fun.]
Go to Cyclone:n 1 l 2 r.
Pickup a passenger going to Sunny Skies Park.
Pickup a passenger going to Sunny Skies Park.
Go to Sunny Skies Park:n 1 r.
[We don't need the inputted number anymore, but we can't change its destination from the Cyclone.]
[So we go to the Cyclone, so we can take the two clones and bring them to Sunny Skies Park forever.]
[We could send them to Riverview Bridge, but that will take more bytes.]
Go to Rob's Rest:s 2 r 1 r.
[Pick up our running squares total from Rob's Rest, so it can go out and see the town.]
Pickup a passenger going to Cyclone.
Go to Cyclone:s 1 l 1 l 2 l.
Pickup a passenger going to Cyclone.
Pickup a passenger going to Cyclone.
Go to Zoom Zoom:n.
Go to Cyclone:w.
[We need to end up with 4 clones of the total.]
[Two of them will actually be used as the counter in this loop.]
[At the start of each loop, we have no passengers.]
[E]
Pickup a passenger going to Joyless Park.
Pickup a passenger going to Divide and Conquer.
Go to Joyless Park:n 2 r 2 r 2 l.
[We will leave one clone of the total at Joyless Park (like Sunny Side Park, but on the opposite side of town).]
[The other clone will be used in a division.]
Go to Cyclone:w 1 r 2 l 2 l.
Pickup a passenger going to Cyclone.
Pickup a passenger going to Joyless Park.
Go to Joyless Park:n 2 r 2 r 2 l.
[We will leave one clone of the counter at Joyless Park.]
[We will clone the other clone (clone-ception?).]
Go to Cyclone:w 1 r 2 l 2 l.
Pickup a passenger going to Divide and Conquer.
Pickup a passenger going to Divide and Conquer.
Go to Divide and Conquer:n 2 r 2 r 1 r.
[We will use both clones of the counter in a division.]
[Divide and Conquer can take 3 arguments, and the result here will be equivalent to total / counter^2 .]
[If the square of the counter is equal to the total, the result will be 1.]
[If the square of the counter is less than the total, the result will be greater than 1.]
[If the square of the counter is greater than the total, the result will be less than 1.]
Pickup a passenger going to Magic Eight.
1 is waiting at Starchild Numerology.
Go to Starchild Numerology:e 1 r 3 r 1 l 1 l 2 l.
Pickup a passenger going to Magic Eight.
Go to Magic Eight:w 1 r 2 r 1 r.
Switch to plan F if no one is waiting.
[We compare the result of the division against 1 to decide our next course of action.]
[If it is greater or equal, the loop should end, and the counter is equal to the floor of the square root.]
[If it is less, the loop should continue.]
Pickup a passenger going to Riverview Bridge.
[Whoops, we don't actually need this anymore.]
Go to Joyless Park:e 2 l 4 r.
Pickup a passenger going to Cyclone.
[We will clone the total later, so we can reuse it in the next loop iteration.]
Pickup a passenger going to The Underground.
Go to The Underground:w 1 l.
[Instead of taking the number 1 and subtracting it from the counter, we can do an optimization here.]
[The Underground is a destination that takes 1 passenger, and subtracts 1 from it.]
[If the result is positive, it returns the result. Otherwise, it returns no one.]
[The latter result will not happen for us, however.]
Pickup a passenger going to Cyclone.
[We will clone the counter later, so we can reuse it in the next loop iteration.]
Go to Fueler Up:s.
[Gotta remember to stop for gas!]
Go to Riverview Bridge:n 3 l.
[So long, Magic Eight result!]
Go to Cyclone:w 2 l.
Switch to plan E.
[Reset everything, and loop back to the start of plan E.]
[F]
Go to Joyless Park:e 2 l 4 r.
Pickup a passenger going to What's The Difference.
Pickup a passenger going to Cyclone.
[Once we've figured out the square root of the total, we're still not done.]
Go to Cyclone:w 1 r 2 l 2 l.
Pickup a passenger going to Multiplication Station.
Pickup a passenger going to Multiplication Station.
Go to Multiplication Station:s 1 l 2 r 4 l.
[We actually square the square root...]
Pickup a passenger going to What's The Difference.
Go to What's The Difference:n 2 l 1 r 3 l.
[...and subtract it from the total at What's The Difference (which subtracts dropped-off passengers).]
Pickup a passenger going to Knots Landing.
Go to Knots Landing:e 4 r 1 l.
[If the result is 0, the total is a perfect square, and a truthy value should be output.]
[If the result is nonzero, the total is not a perfect square, and a falsy value should be output.]
[Luckily, Knots Landing does our work for us.]
[Knots Landing inverts the boolean logic of numeric passengers (i.e. 0 becomes 1, nonzero becomes 0).]
Pickup a passenger going to The Babelfishery.
Go to The Babelfishery:w 1 l.
[Convert it to a string...]
Pickup a passenger going to Post Office.
Go to Post Office:n 1 l 1 r.
[...and output it.]
[We would exit the program by going to the Taxi Garage, but that takes bytes.]
[The boss fires us because we didn't bring the taxi back to the garage, but that gets output to STDERR, so that's OK.]
APL(NARS), 23 chars, 46 bytes
{0=1∣√+/×⍨(0=a∣⍵)/a←⍳⍵}
test:
g←{0=1∣√+/×⍨(0=a∣⍵)/a←⍳⍵}
g¨ 42 1 246 10 16
1 1 1 0 0
MathGolf, 5 4 bytes
─²Σ°
Explanation
─ Get all divisors as list (implicit input)
² Square (implicit map)
Σ Sum
° Is perfect square?
Very similar to other answers, compared to 05AB1E I gain one byte for my "is perfect square" operator.
C# (.NET Core), 115 74 bytes
Thanks to user Misha Lavrov for teaching me how to properly do code golf! :)
a=>{int s=0;for(int i=0;i++<=a;)s+=a%i==0?i*i:0;return Math.Sqrt(s)%1==0;}
Ungolfed:
a => { // reads input
int s = 0; // holds sum of squares
for(int i = 0; i++ <= a;) // index from 1 to input, inclusive
{
s += // add to sum
a % i == 0 ? // check if remainder of input divided by current index is zero
i * i : 0; // if true, add square of current index, else add zero
}
return Math.Sqrt(s) % 1 == 0; // prints "True" if square root is whole number, "False" otherwise
}
Ohm v2, 5 bytes
V²ΣƲ
Try it online! Explanation:
V²ΣƲ
V Pushes input's divisors
² Squares
Σ Sum
Ʋ Returns whether value is a proper square.
Wolfram Language (Mathematica), 24 20 bytes
1∣Norm@Divisors@#&
Divisors finds all the divisors of a number, Norm takes the square root of the sum of squares, and then we test if this is divisible by 1 (i.e., is an integer).
Java 8, 75 70 bytes
n->{int s=0,i=0;for(;++i<=n;)s+=n%i<1?i*i:0;return Math.sqrt(s)%1==0;}
-5 bytes thanks to @archangel.mjj.
Explanation:
n->{ // Method with integer parameter and boolean return-type
int s=0, // Sum-integer, starting at 0
i=0; // Divisor integer, starting at 0
for(;++i<=n;) // Loop `i` in the range [1, n]
s+=n%i<1? // If `n` is divisible by `i`:
i*i // Increase the sum by the square of `i`
: // Else:
0; // Leave the sum the same by adding 0
return Math.sqrt(s)%1==0;}
// Return whether the sum `s` is a perfect square
Groovy, 47 bytes
A lambda accepting a numeric argument.
n->s=(1..n).sum{i->n%i?0:i*i}
!(s%Math.sqrt(s))
Explanation
(1..n) creates an array of the values 1 to n
n%i is false (as 0 is falsy) if i divides n without remainder
n%i ? 0 : i*i is the sum of the square of the value i if it divides n without remainder, otherwise is 0
sum{ i-> n%i ? 0 : i*i } sums the previous result across all i in the array.
s%Math.sqrt(s) is false (as 0 is falsy) if the sqrt of s divides s without remainder
!(s%Math.sqrt(s)) returns from the lambda (return implicit on last statement) !false when the sqrt of s divides s without remainder
Perl 5, 47 bytes
$a+=$_*$_*!($n%$_)for 1..$n;$a=!($a**.5=~/\D/);
Returns 1 for true and nothing for false.
Explanation:
$a+= for 1..$n; sum over i=1 to n
$_*$_ square each component of the sum
*!($n%$_) multiply by 1 if i divides n.
$a= a equals
($a**.5 whether the square root of a
! =~/\D/); does not contain a non-digit.
Pyt, 7 bytes
ð²ƩĐř²∈
Explanation
Implicit input
ð Get list of divisors
² Square each element
Ʃ Sum the list [n]
Đ Duplicate the top of the stack
ř² Push the first n square numbers
∈ Is n in the list of square numbers?
Implicit output
ð²Ʃ√ĐƖ=
Explanation
Implicit input
ð Get list of divisors
² Square each element
Ʃ Sum the list [n]
√ Take the square root of n
Đ Duplicate the top of the stack
Ɩ Cast to an integer
= Are the top two elements on the stack equal to each other?
Implicit output
ð²Ʃ√1%¬
Explanation
Implicit input
ð Get list of divisors
² Square each element
Ʃ Sum the list [n]
√ Take the square root of n
1% Take the square root of n modulo 1
¬ Negate [python typecasting ftw :)]
Implicit output
Brachylog, 12 8 bytes
f^₂ᵐ+~^₂
-4 bytes thanks to Fatelize cause i didn't realize brachylog has a factors functions
explanation
f^₂ᵐ+~^₂ # full code
f # get divisors
^₂ᵐ # square each one
+ # added together
~^₂ # is the result of squaring a number
F#, 111 bytes
let d n=Seq.where(fun v->n%v=0){1..n}
let u n=
let m=d n|>Seq.sumBy(fun x->x*x)
d m|>Seq.exists(fun x->x*x=m)
So d gets the divisors for all numbers between 1 and n inclusive. In the main function u, the first line assigns the sum of all squared divisors to m. The second line gets the divisors for m and determines if any of them squared equals m.
JavaScript (ES7), 46 44 42 bytes
Saved 1 byte thanks to @Hedi
n=>!((g=d=>d&&d*d*!(n%d)+g(d-1))(n)**.5%1)
Commented
n => // n = input
!( // we will eventually convert the result to a Boolean
(g = d => // g is a recursive function taking the current divisor d
d && // if d is equal to 0, stop recursion
d * d // otherwise, compute d²
* !(n % d) // add it to the result if d is a divisor of n
+ g(d - 1) // add the result of a recursive call with the next divisor
)(n) // initial call to g with d = n
** .5 % 1 // test whether the output of g is a perfect square
) // return true if it is or false otherwise
Haskell, 78 64 53 bytes
-14 bytes thanks to Ørjan Johansen. -11 bytes thanks to ovs.
f x=sum[i^2|i<-[1..x],x`mod`i<1]`elem`map(^2)[1..x^2]
Hey, it's been a while since I've... written any code, so my Haskell and golfing might a bit rusty. I forgot the troublesome Haskell numeric types. :P
Scala, 68 67 bytes
def j(s:Int)=Math.sqrt((1 to s).filter(s%_<1).map(a=>a*a).sum)%1==0
C (gcc), 67 63 60 59 bytes
-1 bytes thanks to @JonathanFrech
i,s;f(n){for(s=i=0;i++<n;)s+=n%i?0:i*i;n=sqrt(s);n=n*n==s;}
Matlab, 39 37 bytes
@(v)~mod(sqrt(sum(divisors(v).^2)),1)
Unfortunately, it doesn't work on Octave (on tio) so no tio link.
Note As @LuisMendo stated, divisors() belongs to Symbolic Toolbox.
K (oK), 26 25 22 bytes
Solution:
{~1!%+/x*x*~1!x%:1+!x}
Explanation:
{~1!%+/x*x*~1!x%:1+!x} / the solution
{ } / lambda taking x as input
!x / range 0..x-1 \
1+ / add 1 |
x%: / x divided by and save result into x |
1! / modulo 1 | get divisors
~ / not |
x* / multiply by x /
x* / multiply by x (aka square) > square
+/ / sum up > sum up
% / square root \
1! / modulo 1 | check if a square
~ / not /
Notes:
- -1 bytes taking inspiration from the PowerShell solution
- -3 bytes taking inspiration from the APL solution
Shakespeare Programming Language, 434 428 415 bytes
,.Ajax,.Ford,.Puck,.Act I:.Scene I:.[Enter Ajax and Ford]Ford:Listen tothy.Scene V:.Ajax:You be the sum ofyou a cat.Ford:Is the remainder of the quotient betweenyou I worse a cat?[Exit Ajax][Enter Puck]Ford:If soyou be the sum ofyou the square ofI.[Exit Puck][Enter Ajax]Ford:Be you nicer I?If solet usScene V.[Exit Ford][Enter Puck]Puck:Is the square ofthe square root ofI worse I?You zero.If notyou cat.Open heart
-13 bytes thanks to Jo King!
Outputs 1 for true result, outputs 0 for false result.
Mathematica, 32 bytes
IntegerQ@Sqrt[2~DivisorSigma~#]&
Pure function. Takes a number as input and returns True or False as output. Not entirely sure if there's a shorter method for checking perfect squares.
APL (Dyalog Unicode), 18 bytes
0=1|.5*⍨2+.*⍨∘∪⍳∨⊢
Anonymous lambda. Returns 1 for truthy and 0 for falsy (test cases in TIO are prettified).
Shoutouts to @H.PWiz for 4 bytes!
How:
0=1|.5*⍨2+.*⍨∘∪⍳∨⊢ ⍝ Main function, argument ⍵ → 42
∨⊢ ⍝ Greatest common divisor (∨) between ⍵ (⊢)
⍳ ⍝ and the range (⍳) [1..⍵]
∪ ⍝ Get the unique items (all the divisors of 42; 1 2 3 6 7 14 21 42)
∘ ⍝ Then
⍨ ⍝ Swap arguments of
2+.* ⍝ dot product (.) of sum (+) and power (*) between the list and 2
⍝ (sums the result of each element in the vector squared)
⍨ ⍝ Use the result vector as base
.5* ⍝ Take the square root
1| ⍝ Modulo 1
0= ⍝ Equals 0
Japt, 11 9 7 bytes
-2 bytes from @Giuseppe and another -2 from @Shaggy
â x²¬v1
â x²¬v1 Full program. Implicity input U
â get all integer divisors of U
x² square each element and sum
¬ square root result
v1 return true if divisible by 1
Jelly, 6 bytes
ÆD²SƲ
Try it online! Or see the test-suite.
How?
ÆD²SƲ - Main Link: integer
ÆD - divisors
² - square
S - sum
Ʋ - is square?
PowerShell, 68 56 bytes
param($n)1..$n|%{$a+=$_*$_*!($n%$_)};1..$a|?{$_*$_-eq$a}
Seems long ...
-12 bytes thanks to mazzy
Does exactly what it says on the tin. Takes the range from 1 to input $n and multiplies out the square $_*$_ times whether it's a divisor or not !($n%$_). This makes divisors equal to a nonzero number and non-divisors equal to zero. We then take the sum of them with our accumulator $a. Next, we loop again from 1 up to $a and pull out those numbers where |?{...} it squared is -equal to $a. That is left on the pipeline and output is implicit.
Outputs a positive integer for truthy, and nothing for falsey.
Husk, 6 bytes
£İ□ṁ□Ḋ
Explanation
£İ□ṁ□Ḋ -- example input 12
Ḋ -- divisors: [1,2,3,4,6,12]
ṁ -- map the following ..
□ -- | square: [1,4,9,16,36,144]
-- .. and sum: 210
£ -- is it element of (assumes sorted)
İ□ -- | list of squares: [1,4,9,16..196,225,..
Neim, 5 bytes
𝐅ᛦ𝐬q𝕚
Explanation:
𝐅 Factors
ᛦ Squared
𝐬 Summed
𝕚 is in?
q infinite list of square numbers
R, 39 37 bytes
!sum((y=1:(x=scan()))[!x%%y]^2)^.5%%1
Uses the classic "test if perfect square" approach, taking the non-integral part of the square root S^.5%%1 and taking the logical negation of it, as it maps zero (perfect square) to TRUE and nonzero to FALSE.
Thanks to Robert S for saving a couple of bytes!