Numbers Manipulation challenge
Clash Royale CLAN TAG#URR8PPP
up vote
2
down vote
favorite
Use any programming language to generate two random digits between 1 and 9 (including both). Then your program should display:
- in the first line: the first random digit,
- in the second line: the second random digit,
- in the third line: a number whose tens and units digits are the first and second random digits respectively,
- in the fourth line: the number from the third line raised to the power of 2.
For example, if digits "9" and "2" were generated, your program should display exactly:
9
2
92
8464
code-golf random
add a comment |Â
up vote
2
down vote
favorite
Use any programming language to generate two random digits between 1 and 9 (including both). Then your program should display:
- in the first line: the first random digit,
- in the second line: the second random digit,
- in the third line: a number whose tens and units digits are the first and second random digits respectively,
- in the fourth line: the number from the third line raised to the power of 2.
For example, if digits "9" and "2" were generated, your program should display exactly:
9
2
92
8464
code-golf random
8
Can we output an array?
â Quintec
3 hours ago
1
Can we sample without replacement, ie exclude 1,1 2,2 3,3... from the pairs?
â JayCe
1 hour ago
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
Use any programming language to generate two random digits between 1 and 9 (including both). Then your program should display:
- in the first line: the first random digit,
- in the second line: the second random digit,
- in the third line: a number whose tens and units digits are the first and second random digits respectively,
- in the fourth line: the number from the third line raised to the power of 2.
For example, if digits "9" and "2" were generated, your program should display exactly:
9
2
92
8464
code-golf random
Use any programming language to generate two random digits between 1 and 9 (including both). Then your program should display:
- in the first line: the first random digit,
- in the second line: the second random digit,
- in the third line: a number whose tens and units digits are the first and second random digits respectively,
- in the fourth line: the number from the third line raised to the power of 2.
For example, if digits "9" and "2" were generated, your program should display exactly:
9
2
92
8464
code-golf random
code-golf random
edited 3 hours ago
l4m2
4,1131432
4,1131432
asked 4 hours ago
Monolica
284113
284113
8
Can we output an array?
â Quintec
3 hours ago
1
Can we sample without replacement, ie exclude 1,1 2,2 3,3... from the pairs?
â JayCe
1 hour ago
add a comment |Â
8
Can we output an array?
â Quintec
3 hours ago
1
Can we sample without replacement, ie exclude 1,1 2,2 3,3... from the pairs?
â JayCe
1 hour ago
8
8
Can we output an array?
â Quintec
3 hours ago
Can we output an array?
â Quintec
3 hours ago
1
1
Can we sample without replacement, ie exclude 1,1 2,2 3,3... from the pairs?
â JayCe
1 hour ago
Can we sample without replacement, ie exclude 1,1 2,2 3,3... from the pairs?
â JayCe
1 hour ago
add a comment |Â
19 Answers
19
active
oldest
votes
up vote
3
down vote
C (gcc), 68 67 bytes
-1 byte thanks to cleblanc
f(r)r=rand()%81*10/9+11;printf("%dn%dn%dn%d",r/10,r%10,r,r*r);
Try it online!
save one byte usingr;f()
-->f(r)
â cleblanc
2 hours ago
add a comment |Â
up vote
2
down vote
Python 3, 83 bytes
from random import*
a,b=map(randint,(1,1),(9,9))
k=a*10+b
[*map(print,[a,b,k,k*k])]
Try it online!
82 bytes.
â Erik the Outgolfer
1 hour ago
1
76 bytes
â nwellnhof
1 hour ago
add a comment |Â
up vote
2
down vote
Perl 6, 39 bytes
.comb,$_,$_ò([~] roll 1..9: 2)>>.put
Try it online!
add a comment |Â
up vote
2
down vote
R, 48 bytes
cat(x<-sample(9,2,T),y<-x%*%c(10,1),y^2,sep="
")
Try it online!
add a comment |Â
up vote
2
down vote
PowerShell, 48 bytes
($a,$b=1..9+1..9|Random -c 2)
($x="$a$b")
+$x*$x
Try it online!
Concatenates two ranges 1..9
together, pipes that to Get-Random
with a -c
ount of 2
to pull out two elements, stores them into $a
and $b
, and encapsulates that in parens to place a copy of them on the pipeline.
Next we string concatenate $a$b
and store it into $x
, again placing in parens to put a copy on the pipeline. Finally we take $x
squared and leave it on the pipeline.
All the results are gathered from the pipeline and an implicit Write-Output
gives us newlines between elements for free.
Smart get-random
â mazzy
1 hour ago
add a comment |Â
up vote
2
down vote
Pyth, 14 bytes
^
i,
hO9
hO9T2
Note that the newlines are significant. Try it online here.
Explanation, with newlines replaced with ö character:
^öi,öhO9öhO9T2 Implicit: T=10
O9 Choose a random number in [0-9)
h Increment
ö Output with newline - value printed is yielded as expression result
öhO9 Do the above again
, Wrap the two previous results in a two-element array
i T Convert to decimal from base 10
ö Output with newline
^ 2 Square the previous result, implicit print
@Downvoter - any particular reason why?
â Sok
1 hour ago
add a comment |Â
up vote
2
down vote
Japt, 14 bytes
9õ ï ö
pUìUì ò
9õ ï ö
pUìUì ò Full program
-----------------------------------------
9õ Range [1,9]
ï Cartesian product with itself
ö get a random element
This result is assigned to U
p Push into U
Uì Elements in U joined
Uì ò and elements joined squared
Implicit output each element
separated with new line -R
Try it online!
1
Mq
can return0
â Shaggy
2 hours ago
@Shaggy didn't notice that the random numbers range was [1, 9]. It should be fixed now
â Luis felipe De jesus Munoz
1 hour ago
add a comment |Â
up vote
2
down vote
T-SQL, 142 105 115 114 96 bytes
DECLARE @ AS char=LEFT(RAND()*9+1,1),@a AS char=LEFT(RAND()*9+1,1)SELECT @,@a,@+@a,POWER(@+@a,2)
-37 bytes: Realized I could just use two different random numbers and use the first digits from each!
+10 bytes: Edited to meet requirements of range from 1-9, instead of 0-9
-1 byte: Changed RIGHT() to LEFT() in @b
-18 bytes: Various changes suggested by BradC
Ungolfed:
-- Setting RAND() separately in these produces different numbers.
-- [RAND() * b + a] sets the range for a random number, from a to b inclusive.
-- Set the variable string to the first number.
DECLARE @ AS char = LEFT(RAND() * 9 + 1, 1),
@a AS char = LEFT(RAND() * 9 + 1, 1)
SELECT @, -- first digit
@a, -- second digit
@ + @a, -- first two digits combined (not added, as they are type char)
POWER(@ + @a, 2) -- first two digits combined, squared (POWER function will cast the first argument to a number if it is a string)
1
Nice work, a few ways to save more: usechar
instead ofvarchar
, use@
by itself for one of the two variables (its valid!), simplify eachRAND
toRAND()*9+1
(which is 10-1, your code wasn't allowing for 9s).
â BradC
26 mins ago
Ooo, you'd have to change yourSELECT
math, but you can declare both variables as INT, and just let it to an implicit converstion, dropping theLEFT
altogether!DECLARE @ AS INT=RAND()*9+1,@b AS INT=...
â BradC
18 mins ago
The stuff in the first comment definitely works, I'll edit that in. Problem with making the variablesint
s is that I would need to cast each individually aschar
s in theSELECT
where necessary. With that, since each variable would need to be converted twice (in@+@a
andPOWER(@+@a,2)
), it'd add more characters than it would save.
â Meerkat
11 mins ago
add a comment |Â
up vote
1
down vote
JavaScript (ES6), 67 bytes
f=_=>(n=Math.random()*90+10|0)%10?(n/10|0)+`
$n%10
$n
`+n*n:f()
Try it online!
add a comment |Â
up vote
1
down vote
Charcoal, 16 bytes
âÂÂâÂÂòâÂÂâ½â¹øâÂÂøø⸿IXIøò
Try it online! Link is to verbose version of code. Explanation:
âÂÂâÂÂòâÂÂâ½â¹ø
Generate two random characters in the range 1
to 9
.
âÂÂø
Output them downwards i.e. on separate lines.
ø⸿
Output them horizontally on their own line.
IXIøò
Cast to integer, square, cast back to string for implicit print.
add a comment |Â
up vote
1
down vote
Jelly, 10 9 bytes
9á¹Â2Xá¹Ââ¬á¸Âá¹Âò
Try it online!
How it works
9á¹Â2Xá¹Ââ¬á¸Âá¹Âò Main link. No arguments.
9 Set the return value to 9.
á¹Â2 Promote 9 to [1, ..., 9] and take the second Cartesian power, yielding
[[1, 1], [1, 2], ..., [9, 8], [9, 9]].
X Pseudo-randomly select one of the pairs.
á¹Â⬠Print each integer in the pair, followed by a newline.
ḠUndecimal; convert the integer pair from base 10 to an integer.
á¹ Print the integer, followed by a newline.
ò Take the square.
(implicit) Print the last return value.
add a comment |Â
up vote
1
down vote
Ruby, 41 bytes
puts [(a=11+10*rand(81)/9)/10,a%10,a,a*a]
Try it online!
add a comment |Â
up vote
1
down vote
Vim, 44 bytes
:%!$RANDOM
:s/0//g
2f:hy2hVpo=0*0
kYPa
Try it online!
Not the right tool for the job. This produces most likely the desired output
Step by step:
:%!$RANDOM
Enter Enter
Produces a string like/bin/bash: 25266: command not found
:s/0//g
removes all zeroes2f:hy2hVp
moves the cursor one to the left of the colon after the number, copy the last two digits and replace the entire string with thoseo
Ctrl+R=
Ctrl+R0*
Ctrl+R0
Enter
add a new line and evaluate an expression. In this case, I'll multiply the number in register 0 (the one that was just copied) with itself. Result:Esc
kYPa
Enter
Copy the upper line and paste it above. The cursor ends up in the first line, on the first character. Now we just have to append a line break to it
Limitations: If the result of $RANDOM
is a number with less than two non-zero digits, this will not produce the desired output
add a comment |Â
up vote
1
down vote
Java 8, 99 98 90 81 80 bytes
v->int i=81;i*=Math.random();return(i=i*10/9+11)/10+"n"+i%10+"n"+i+"n"+i*i;
-8 bytes after being inspired by @Arnauld's JavaScript answer.
-9 bytes thanks to @nwellnhof.
Try it online.
Explanation:
v-> // Method with empty unused parameter and no return-type
int i=81;i*=Math.random();// Create a random integer `i` in the range [0,81)
return(i=i*10/9+11) // Set `i` to 10 times `i`, integer-divided by 9, and 11 added
/10+"n" // Return the first digit of `i`, a newline,
+i%10+"n" // the last digit of `i`, a newline,
+i+"n" // `i` itself, a newline,
+i*i; // and `i` multiplied by itself
// All concatted to each other
@nwellnhof Thanks! And been able to golf 1 more byte with my previous trick ofint i=81;i*=Math.random();return(i=i*10/9+11)
.
â Kevin Cruijssen
1 hour ago
add a comment |Â
up vote
1
down vote
05AB1E, 14 11 bytes
2F9Lé=}J=n,
-3 bytes thanks to @Emigna.
Try it online.
Explanation:
2F } # Loop 2 times:
9Lé # Create a list in the range [1,9], and pick a random element from it
= # Output it (without popping it from the stack)
J # Join them together
= # Output it (without popping it from the stack)
n # Take it to the power of 2
, # And output it as well
11 bytes alternative:
9Lãéé`îJDnû
Try it online.
Explanation:
9L # List in the range [1,9]
ã # Cartesian product with itself: [[1,1],[1,2],[1,3],...,[9,7],[9,8],[9,9]]
é # Take a random element from it
é # Store it in the register (without popping)
` # Pop and push both items as separated items onto the stack
î # Retrieve the list of digits from the register again
J # Join them together to a single 2-digit number
Dn # Duplicate it, and take the power of 2 of the copy
û # Merge all values on the stack by newlines (and output implicitly)
1
Shorter in a looP:2F9Lé=}J=n,
â Emigna
3 hours ago
@Emigna I was about to look for shorter alternatives, but smart use of the=
!
â Kevin Cruijssen
3 hours ago
add a comment |Â
up vote
1
down vote
Python 2, 84 75 bytes
from random import*
k=randint(9,89)*10/9+1
for x in k/10,k%10,k,k*k:print x
Try it online!
Saved
- -1 bytes, thanks to Erik the Outgolfer
- -8 bytes, thanks to nwellnhof
Moderate golf: 83 bytes.
â Erik the Outgolfer
1 hour ago
@EriktheOutgolfer Thanks :)
â TFeld
45 mins ago
@nwellnhof Thanks :)
â TFeld
45 mins ago
add a comment |Â
up vote
0
down vote
C# (.NET Core), 130 bytes
Random r=new Random();int a=r.Next(1,9),b=r.Next(1,9),c=int.Parse(a.ToString()+b.ToString());Console.Write(a+" "+b+" "+c+" "+c*c);
Try it online!
Ungolfed:
Random r = new Random(); // initializes random number generator
int a = r.Next(1, 9), // gets random number between 1 and 9 inclusive
b = r.Next(1, 9), // gets random number between 1 and 9 inclusive
c = int.Parse(a.ToString() + b.ToString()); // concatenates a and b into one two-digit number
Console.Write(a + " " + b + " " + c + " " + c*c); // writes a, b, c, and c^2 to the console
add a comment |Â
up vote
0
down vote
K (oK), 28 bytes
t:2?10;t,:10/t;$t,:t[2]*t[2]
Explanation
t:2?10 //define t as two random numbers from 1-10
t,:10/t //join the base 10 joining of the elements of t to t
t,:t[2]*t[2]//join the square of the index 2 element to t
$ //String each element of the result (to output on newlines)
Try it online!
Cleaner Output, 32 bytes
t:2?10;t,:10/t;`0:$t,:t[2]*t[2];
`0: //Cleanly prints the strings
Try it online!
add a comment |Â
up vote
0
down vote
PHP, 64 bytes
<?$d=($c=(10*($a=rand(1,9))+$b=rand(1,9)))*$c;echo"$a
$b
$c
$d";
Try it online!
add a comment |Â
19 Answers
19
active
oldest
votes
19 Answers
19
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
C (gcc), 68 67 bytes
-1 byte thanks to cleblanc
f(r)r=rand()%81*10/9+11;printf("%dn%dn%dn%d",r/10,r%10,r,r*r);
Try it online!
save one byte usingr;f()
-->f(r)
â cleblanc
2 hours ago
add a comment |Â
up vote
3
down vote
C (gcc), 68 67 bytes
-1 byte thanks to cleblanc
f(r)r=rand()%81*10/9+11;printf("%dn%dn%dn%d",r/10,r%10,r,r*r);
Try it online!
save one byte usingr;f()
-->f(r)
â cleblanc
2 hours ago
add a comment |Â
up vote
3
down vote
up vote
3
down vote
C (gcc), 68 67 bytes
-1 byte thanks to cleblanc
f(r)r=rand()%81*10/9+11;printf("%dn%dn%dn%d",r/10,r%10,r,r*r);
Try it online!
C (gcc), 68 67 bytes
-1 byte thanks to cleblanc
f(r)r=rand()%81*10/9+11;printf("%dn%dn%dn%d",r/10,r%10,r,r*r);
Try it online!
edited 2 hours ago
answered 2 hours ago
nwellnhof
5,098920
5,098920
save one byte usingr;f()
-->f(r)
â cleblanc
2 hours ago
add a comment |Â
save one byte usingr;f()
-->f(r)
â cleblanc
2 hours ago
save one byte using
r;f()
--> f(r)
â cleblanc
2 hours ago
save one byte using
r;f()
--> f(r)
â cleblanc
2 hours ago
add a comment |Â
up vote
2
down vote
Python 3, 83 bytes
from random import*
a,b=map(randint,(1,1),(9,9))
k=a*10+b
[*map(print,[a,b,k,k*k])]
Try it online!
82 bytes.
â Erik the Outgolfer
1 hour ago
1
76 bytes
â nwellnhof
1 hour ago
add a comment |Â
up vote
2
down vote
Python 3, 83 bytes
from random import*
a,b=map(randint,(1,1),(9,9))
k=a*10+b
[*map(print,[a,b,k,k*k])]
Try it online!
82 bytes.
â Erik the Outgolfer
1 hour ago
1
76 bytes
â nwellnhof
1 hour ago
add a comment |Â
up vote
2
down vote
up vote
2
down vote
Python 3, 83 bytes
from random import*
a,b=map(randint,(1,1),(9,9))
k=a*10+b
[*map(print,[a,b,k,k*k])]
Try it online!
Python 3, 83 bytes
from random import*
a,b=map(randint,(1,1),(9,9))
k=a*10+b
[*map(print,[a,b,k,k*k])]
Try it online!
answered 3 hours ago
ovs
18k21058
18k21058
82 bytes.
â Erik the Outgolfer
1 hour ago
1
76 bytes
â nwellnhof
1 hour ago
add a comment |Â
82 bytes.
â Erik the Outgolfer
1 hour ago
1
76 bytes
â nwellnhof
1 hour ago
82 bytes.
â Erik the Outgolfer
1 hour ago
82 bytes.
â Erik the Outgolfer
1 hour ago
1
1
76 bytes
â nwellnhof
1 hour ago
76 bytes
â nwellnhof
1 hour ago
add a comment |Â
up vote
2
down vote
Perl 6, 39 bytes
.comb,$_,$_ò([~] roll 1..9: 2)>>.put
Try it online!
add a comment |Â
up vote
2
down vote
Perl 6, 39 bytes
.comb,$_,$_ò([~] roll 1..9: 2)>>.put
Try it online!
add a comment |Â
up vote
2
down vote
up vote
2
down vote
Perl 6, 39 bytes
.comb,$_,$_ò([~] roll 1..9: 2)>>.put
Try it online!
Perl 6, 39 bytes
.comb,$_,$_ò([~] roll 1..9: 2)>>.put
Try it online!
edited 3 hours ago
answered 3 hours ago
nwellnhof
5,098920
5,098920
add a comment |Â
add a comment |Â
up vote
2
down vote
R, 48 bytes
cat(x<-sample(9,2,T),y<-x%*%c(10,1),y^2,sep="
")
Try it online!
add a comment |Â
up vote
2
down vote
R, 48 bytes
cat(x<-sample(9,2,T),y<-x%*%c(10,1),y^2,sep="
")
Try it online!
add a comment |Â
up vote
2
down vote
up vote
2
down vote
R, 48 bytes
cat(x<-sample(9,2,T),y<-x%*%c(10,1),y^2,sep="
")
Try it online!
R, 48 bytes
cat(x<-sample(9,2,T),y<-x%*%c(10,1),y^2,sep="
")
Try it online!
answered 3 hours ago
Giuseppe
15.6k31051
15.6k31051
add a comment |Â
add a comment |Â
up vote
2
down vote
PowerShell, 48 bytes
($a,$b=1..9+1..9|Random -c 2)
($x="$a$b")
+$x*$x
Try it online!
Concatenates two ranges 1..9
together, pipes that to Get-Random
with a -c
ount of 2
to pull out two elements, stores them into $a
and $b
, and encapsulates that in parens to place a copy of them on the pipeline.
Next we string concatenate $a$b
and store it into $x
, again placing in parens to put a copy on the pipeline. Finally we take $x
squared and leave it on the pipeline.
All the results are gathered from the pipeline and an implicit Write-Output
gives us newlines between elements for free.
Smart get-random
â mazzy
1 hour ago
add a comment |Â
up vote
2
down vote
PowerShell, 48 bytes
($a,$b=1..9+1..9|Random -c 2)
($x="$a$b")
+$x*$x
Try it online!
Concatenates two ranges 1..9
together, pipes that to Get-Random
with a -c
ount of 2
to pull out two elements, stores them into $a
and $b
, and encapsulates that in parens to place a copy of them on the pipeline.
Next we string concatenate $a$b
and store it into $x
, again placing in parens to put a copy on the pipeline. Finally we take $x
squared and leave it on the pipeline.
All the results are gathered from the pipeline and an implicit Write-Output
gives us newlines between elements for free.
Smart get-random
â mazzy
1 hour ago
add a comment |Â
up vote
2
down vote
up vote
2
down vote
PowerShell, 48 bytes
($a,$b=1..9+1..9|Random -c 2)
($x="$a$b")
+$x*$x
Try it online!
Concatenates two ranges 1..9
together, pipes that to Get-Random
with a -c
ount of 2
to pull out two elements, stores them into $a
and $b
, and encapsulates that in parens to place a copy of them on the pipeline.
Next we string concatenate $a$b
and store it into $x
, again placing in parens to put a copy on the pipeline. Finally we take $x
squared and leave it on the pipeline.
All the results are gathered from the pipeline and an implicit Write-Output
gives us newlines between elements for free.
PowerShell, 48 bytes
($a,$b=1..9+1..9|Random -c 2)
($x="$a$b")
+$x*$x
Try it online!
Concatenates two ranges 1..9
together, pipes that to Get-Random
with a -c
ount of 2
to pull out two elements, stores them into $a
and $b
, and encapsulates that in parens to place a copy of them on the pipeline.
Next we string concatenate $a$b
and store it into $x
, again placing in parens to put a copy on the pipeline. Finally we take $x
squared and leave it on the pipeline.
All the results are gathered from the pipeline and an implicit Write-Output
gives us newlines between elements for free.
answered 2 hours ago
AdmBorkBork
25.2k361219
25.2k361219
Smart get-random
â mazzy
1 hour ago
add a comment |Â
Smart get-random
â mazzy
1 hour ago
Smart get-random
â mazzy
1 hour ago
Smart get-random
â mazzy
1 hour ago
add a comment |Â
up vote
2
down vote
Pyth, 14 bytes
^
i,
hO9
hO9T2
Note that the newlines are significant. Try it online here.
Explanation, with newlines replaced with ö character:
^öi,öhO9öhO9T2 Implicit: T=10
O9 Choose a random number in [0-9)
h Increment
ö Output with newline - value printed is yielded as expression result
öhO9 Do the above again
, Wrap the two previous results in a two-element array
i T Convert to decimal from base 10
ö Output with newline
^ 2 Square the previous result, implicit print
@Downvoter - any particular reason why?
â Sok
1 hour ago
add a comment |Â
up vote
2
down vote
Pyth, 14 bytes
^
i,
hO9
hO9T2
Note that the newlines are significant. Try it online here.
Explanation, with newlines replaced with ö character:
^öi,öhO9öhO9T2 Implicit: T=10
O9 Choose a random number in [0-9)
h Increment
ö Output with newline - value printed is yielded as expression result
öhO9 Do the above again
, Wrap the two previous results in a two-element array
i T Convert to decimal from base 10
ö Output with newline
^ 2 Square the previous result, implicit print
@Downvoter - any particular reason why?
â Sok
1 hour ago
add a comment |Â
up vote
2
down vote
up vote
2
down vote
Pyth, 14 bytes
^
i,
hO9
hO9T2
Note that the newlines are significant. Try it online here.
Explanation, with newlines replaced with ö character:
^öi,öhO9öhO9T2 Implicit: T=10
O9 Choose a random number in [0-9)
h Increment
ö Output with newline - value printed is yielded as expression result
öhO9 Do the above again
, Wrap the two previous results in a two-element array
i T Convert to decimal from base 10
ö Output with newline
^ 2 Square the previous result, implicit print
Pyth, 14 bytes
^
i,
hO9
hO9T2
Note that the newlines are significant. Try it online here.
Explanation, with newlines replaced with ö character:
^öi,öhO9öhO9T2 Implicit: T=10
O9 Choose a random number in [0-9)
h Increment
ö Output with newline - value printed is yielded as expression result
öhO9 Do the above again
, Wrap the two previous results in a two-element array
i T Convert to decimal from base 10
ö Output with newline
^ 2 Square the previous result, implicit print
answered 2 hours ago
Sok
3,219722
3,219722
@Downvoter - any particular reason why?
â Sok
1 hour ago
add a comment |Â
@Downvoter - any particular reason why?
â Sok
1 hour ago
@Downvoter - any particular reason why?
â Sok
1 hour ago
@Downvoter - any particular reason why?
â Sok
1 hour ago
add a comment |Â
up vote
2
down vote
Japt, 14 bytes
9õ ï ö
pUìUì ò
9õ ï ö
pUìUì ò Full program
-----------------------------------------
9õ Range [1,9]
ï Cartesian product with itself
ö get a random element
This result is assigned to U
p Push into U
Uì Elements in U joined
Uì ò and elements joined squared
Implicit output each element
separated with new line -R
Try it online!
1
Mq
can return0
â Shaggy
2 hours ago
@Shaggy didn't notice that the random numbers range was [1, 9]. It should be fixed now
â Luis felipe De jesus Munoz
1 hour ago
add a comment |Â
up vote
2
down vote
Japt, 14 bytes
9õ ï ö
pUìUì ò
9õ ï ö
pUìUì ò Full program
-----------------------------------------
9õ Range [1,9]
ï Cartesian product with itself
ö get a random element
This result is assigned to U
p Push into U
Uì Elements in U joined
Uì ò and elements joined squared
Implicit output each element
separated with new line -R
Try it online!
1
Mq
can return0
â Shaggy
2 hours ago
@Shaggy didn't notice that the random numbers range was [1, 9]. It should be fixed now
â Luis felipe De jesus Munoz
1 hour ago
add a comment |Â
up vote
2
down vote
up vote
2
down vote
Japt, 14 bytes
9õ ï ö
pUìUì ò
9õ ï ö
pUìUì ò Full program
-----------------------------------------
9õ Range [1,9]
ï Cartesian product with itself
ö get a random element
This result is assigned to U
p Push into U
Uì Elements in U joined
Uì ò and elements joined squared
Implicit output each element
separated with new line -R
Try it online!
Japt, 14 bytes
9õ ï ö
pUìUì ò
9õ ï ö
pUìUì ò Full program
-----------------------------------------
9õ Range [1,9]
ï Cartesian product with itself
ö get a random element
This result is assigned to U
p Push into U
Uì Elements in U joined
Uì ò and elements joined squared
Implicit output each element
separated with new line -R
Try it online!
edited 1 hour ago
answered 3 hours ago
Luis felipe De jesus Munoz
3,46011049
3,46011049
1
Mq
can return0
â Shaggy
2 hours ago
@Shaggy didn't notice that the random numbers range was [1, 9]. It should be fixed now
â Luis felipe De jesus Munoz
1 hour ago
add a comment |Â
1
Mq
can return0
â Shaggy
2 hours ago
@Shaggy didn't notice that the random numbers range was [1, 9]. It should be fixed now
â Luis felipe De jesus Munoz
1 hour ago
1
1
Mq
can return 0
â Shaggy
2 hours ago
Mq
can return 0
â Shaggy
2 hours ago
@Shaggy didn't notice that the random numbers range was [1, 9]. It should be fixed now
â Luis felipe De jesus Munoz
1 hour ago
@Shaggy didn't notice that the random numbers range was [1, 9]. It should be fixed now
â Luis felipe De jesus Munoz
1 hour ago
add a comment |Â
up vote
2
down vote
T-SQL, 142 105 115 114 96 bytes
DECLARE @ AS char=LEFT(RAND()*9+1,1),@a AS char=LEFT(RAND()*9+1,1)SELECT @,@a,@+@a,POWER(@+@a,2)
-37 bytes: Realized I could just use two different random numbers and use the first digits from each!
+10 bytes: Edited to meet requirements of range from 1-9, instead of 0-9
-1 byte: Changed RIGHT() to LEFT() in @b
-18 bytes: Various changes suggested by BradC
Ungolfed:
-- Setting RAND() separately in these produces different numbers.
-- [RAND() * b + a] sets the range for a random number, from a to b inclusive.
-- Set the variable string to the first number.
DECLARE @ AS char = LEFT(RAND() * 9 + 1, 1),
@a AS char = LEFT(RAND() * 9 + 1, 1)
SELECT @, -- first digit
@a, -- second digit
@ + @a, -- first two digits combined (not added, as they are type char)
POWER(@ + @a, 2) -- first two digits combined, squared (POWER function will cast the first argument to a number if it is a string)
1
Nice work, a few ways to save more: usechar
instead ofvarchar
, use@
by itself for one of the two variables (its valid!), simplify eachRAND
toRAND()*9+1
(which is 10-1, your code wasn't allowing for 9s).
â BradC
26 mins ago
Ooo, you'd have to change yourSELECT
math, but you can declare both variables as INT, and just let it to an implicit converstion, dropping theLEFT
altogether!DECLARE @ AS INT=RAND()*9+1,@b AS INT=...
â BradC
18 mins ago
The stuff in the first comment definitely works, I'll edit that in. Problem with making the variablesint
s is that I would need to cast each individually aschar
s in theSELECT
where necessary. With that, since each variable would need to be converted twice (in@+@a
andPOWER(@+@a,2)
), it'd add more characters than it would save.
â Meerkat
11 mins ago
add a comment |Â
up vote
2
down vote
T-SQL, 142 105 115 114 96 bytes
DECLARE @ AS char=LEFT(RAND()*9+1,1),@a AS char=LEFT(RAND()*9+1,1)SELECT @,@a,@+@a,POWER(@+@a,2)
-37 bytes: Realized I could just use two different random numbers and use the first digits from each!
+10 bytes: Edited to meet requirements of range from 1-9, instead of 0-9
-1 byte: Changed RIGHT() to LEFT() in @b
-18 bytes: Various changes suggested by BradC
Ungolfed:
-- Setting RAND() separately in these produces different numbers.
-- [RAND() * b + a] sets the range for a random number, from a to b inclusive.
-- Set the variable string to the first number.
DECLARE @ AS char = LEFT(RAND() * 9 + 1, 1),
@a AS char = LEFT(RAND() * 9 + 1, 1)
SELECT @, -- first digit
@a, -- second digit
@ + @a, -- first two digits combined (not added, as they are type char)
POWER(@ + @a, 2) -- first two digits combined, squared (POWER function will cast the first argument to a number if it is a string)
1
Nice work, a few ways to save more: usechar
instead ofvarchar
, use@
by itself for one of the two variables (its valid!), simplify eachRAND
toRAND()*9+1
(which is 10-1, your code wasn't allowing for 9s).
â BradC
26 mins ago
Ooo, you'd have to change yourSELECT
math, but you can declare both variables as INT, and just let it to an implicit converstion, dropping theLEFT
altogether!DECLARE @ AS INT=RAND()*9+1,@b AS INT=...
â BradC
18 mins ago
The stuff in the first comment definitely works, I'll edit that in. Problem with making the variablesint
s is that I would need to cast each individually aschar
s in theSELECT
where necessary. With that, since each variable would need to be converted twice (in@+@a
andPOWER(@+@a,2)
), it'd add more characters than it would save.
â Meerkat
11 mins ago
add a comment |Â
up vote
2
down vote
up vote
2
down vote
T-SQL, 142 105 115 114 96 bytes
DECLARE @ AS char=LEFT(RAND()*9+1,1),@a AS char=LEFT(RAND()*9+1,1)SELECT @,@a,@+@a,POWER(@+@a,2)
-37 bytes: Realized I could just use two different random numbers and use the first digits from each!
+10 bytes: Edited to meet requirements of range from 1-9, instead of 0-9
-1 byte: Changed RIGHT() to LEFT() in @b
-18 bytes: Various changes suggested by BradC
Ungolfed:
-- Setting RAND() separately in these produces different numbers.
-- [RAND() * b + a] sets the range for a random number, from a to b inclusive.
-- Set the variable string to the first number.
DECLARE @ AS char = LEFT(RAND() * 9 + 1, 1),
@a AS char = LEFT(RAND() * 9 + 1, 1)
SELECT @, -- first digit
@a, -- second digit
@ + @a, -- first two digits combined (not added, as they are type char)
POWER(@ + @a, 2) -- first two digits combined, squared (POWER function will cast the first argument to a number if it is a string)
T-SQL, 142 105 115 114 96 bytes
DECLARE @ AS char=LEFT(RAND()*9+1,1),@a AS char=LEFT(RAND()*9+1,1)SELECT @,@a,@+@a,POWER(@+@a,2)
-37 bytes: Realized I could just use two different random numbers and use the first digits from each!
+10 bytes: Edited to meet requirements of range from 1-9, instead of 0-9
-1 byte: Changed RIGHT() to LEFT() in @b
-18 bytes: Various changes suggested by BradC
Ungolfed:
-- Setting RAND() separately in these produces different numbers.
-- [RAND() * b + a] sets the range for a random number, from a to b inclusive.
-- Set the variable string to the first number.
DECLARE @ AS char = LEFT(RAND() * 9 + 1, 1),
@a AS char = LEFT(RAND() * 9 + 1, 1)
SELECT @, -- first digit
@a, -- second digit
@ + @a, -- first two digits combined (not added, as they are type char)
POWER(@ + @a, 2) -- first two digits combined, squared (POWER function will cast the first argument to a number if it is a string)
edited 7 mins ago
answered 1 hour ago
Meerkat
1215
1215
1
Nice work, a few ways to save more: usechar
instead ofvarchar
, use@
by itself for one of the two variables (its valid!), simplify eachRAND
toRAND()*9+1
(which is 10-1, your code wasn't allowing for 9s).
â BradC
26 mins ago
Ooo, you'd have to change yourSELECT
math, but you can declare both variables as INT, and just let it to an implicit converstion, dropping theLEFT
altogether!DECLARE @ AS INT=RAND()*9+1,@b AS INT=...
â BradC
18 mins ago
The stuff in the first comment definitely works, I'll edit that in. Problem with making the variablesint
s is that I would need to cast each individually aschar
s in theSELECT
where necessary. With that, since each variable would need to be converted twice (in@+@a
andPOWER(@+@a,2)
), it'd add more characters than it would save.
â Meerkat
11 mins ago
add a comment |Â
1
Nice work, a few ways to save more: usechar
instead ofvarchar
, use@
by itself for one of the two variables (its valid!), simplify eachRAND
toRAND()*9+1
(which is 10-1, your code wasn't allowing for 9s).
â BradC
26 mins ago
Ooo, you'd have to change yourSELECT
math, but you can declare both variables as INT, and just let it to an implicit converstion, dropping theLEFT
altogether!DECLARE @ AS INT=RAND()*9+1,@b AS INT=...
â BradC
18 mins ago
The stuff in the first comment definitely works, I'll edit that in. Problem with making the variablesint
s is that I would need to cast each individually aschar
s in theSELECT
where necessary. With that, since each variable would need to be converted twice (in@+@a
andPOWER(@+@a,2)
), it'd add more characters than it would save.
â Meerkat
11 mins ago
1
1
Nice work, a few ways to save more: use
char
instead of varchar
, use @
by itself for one of the two variables (its valid!), simplify each RAND
to RAND()*9+1
(which is 10-1, your code wasn't allowing for 9s).â BradC
26 mins ago
Nice work, a few ways to save more: use
char
instead of varchar
, use @
by itself for one of the two variables (its valid!), simplify each RAND
to RAND()*9+1
(which is 10-1, your code wasn't allowing for 9s).â BradC
26 mins ago
Ooo, you'd have to change your
SELECT
math, but you can declare both variables as INT, and just let it to an implicit converstion, dropping the LEFT
altogether! DECLARE @ AS INT=RAND()*9+1,@b AS INT=...
â BradC
18 mins ago
Ooo, you'd have to change your
SELECT
math, but you can declare both variables as INT, and just let it to an implicit converstion, dropping the LEFT
altogether! DECLARE @ AS INT=RAND()*9+1,@b AS INT=...
â BradC
18 mins ago
The stuff in the first comment definitely works, I'll edit that in. Problem with making the variables
int
s is that I would need to cast each individually as char
s in the SELECT
where necessary. With that, since each variable would need to be converted twice (in @+@a
and POWER(@+@a,2)
), it'd add more characters than it would save.â Meerkat
11 mins ago
The stuff in the first comment definitely works, I'll edit that in. Problem with making the variables
int
s is that I would need to cast each individually as char
s in the SELECT
where necessary. With that, since each variable would need to be converted twice (in @+@a
and POWER(@+@a,2)
), it'd add more characters than it would save.â Meerkat
11 mins ago
add a comment |Â
up vote
1
down vote
JavaScript (ES6), 67 bytes
f=_=>(n=Math.random()*90+10|0)%10?(n/10|0)+`
$n%10
$n
`+n*n:f()
Try it online!
add a comment |Â
up vote
1
down vote
JavaScript (ES6), 67 bytes
f=_=>(n=Math.random()*90+10|0)%10?(n/10|0)+`
$n%10
$n
`+n*n:f()
Try it online!
add a comment |Â
up vote
1
down vote
up vote
1
down vote
JavaScript (ES6), 67 bytes
f=_=>(n=Math.random()*90+10|0)%10?(n/10|0)+`
$n%10
$n
`+n*n:f()
Try it online!
JavaScript (ES6), 67 bytes
f=_=>(n=Math.random()*90+10|0)%10?(n/10|0)+`
$n%10
$n
`+n*n:f()
Try it online!
answered 3 hours ago
Arnauld
67.1k584282
67.1k584282
add a comment |Â
add a comment |Â
up vote
1
down vote
Charcoal, 16 bytes
âÂÂâÂÂòâÂÂâ½â¹øâÂÂøø⸿IXIøò
Try it online! Link is to verbose version of code. Explanation:
âÂÂâÂÂòâÂÂâ½â¹ø
Generate two random characters in the range 1
to 9
.
âÂÂø
Output them downwards i.e. on separate lines.
ø⸿
Output them horizontally on their own line.
IXIøò
Cast to integer, square, cast back to string for implicit print.
add a comment |Â
up vote
1
down vote
Charcoal, 16 bytes
âÂÂâÂÂòâÂÂâ½â¹øâÂÂøø⸿IXIøò
Try it online! Link is to verbose version of code. Explanation:
âÂÂâÂÂòâÂÂâ½â¹ø
Generate two random characters in the range 1
to 9
.
âÂÂø
Output them downwards i.e. on separate lines.
ø⸿
Output them horizontally on their own line.
IXIøò
Cast to integer, square, cast back to string for implicit print.
add a comment |Â
up vote
1
down vote
up vote
1
down vote
Charcoal, 16 bytes
âÂÂâÂÂòâÂÂâ½â¹øâÂÂøø⸿IXIøò
Try it online! Link is to verbose version of code. Explanation:
âÂÂâÂÂòâÂÂâ½â¹ø
Generate two random characters in the range 1
to 9
.
âÂÂø
Output them downwards i.e. on separate lines.
ø⸿
Output them horizontally on their own line.
IXIøò
Cast to integer, square, cast back to string for implicit print.
Charcoal, 16 bytes
âÂÂâÂÂòâÂÂâ½â¹øâÂÂøø⸿IXIøò
Try it online! Link is to verbose version of code. Explanation:
âÂÂâÂÂòâÂÂâ½â¹ø
Generate two random characters in the range 1
to 9
.
âÂÂø
Output them downwards i.e. on separate lines.
ø⸿
Output them horizontally on their own line.
IXIøò
Cast to integer, square, cast back to string for implicit print.
answered 2 hours ago
Neil
77.2k744174
77.2k744174
add a comment |Â
add a comment |Â
up vote
1
down vote
Jelly, 10 9 bytes
9á¹Â2Xá¹Ââ¬á¸Âá¹Âò
Try it online!
How it works
9á¹Â2Xá¹Ââ¬á¸Âá¹Âò Main link. No arguments.
9 Set the return value to 9.
á¹Â2 Promote 9 to [1, ..., 9] and take the second Cartesian power, yielding
[[1, 1], [1, 2], ..., [9, 8], [9, 9]].
X Pseudo-randomly select one of the pairs.
á¹Â⬠Print each integer in the pair, followed by a newline.
ḠUndecimal; convert the integer pair from base 10 to an integer.
á¹ Print the integer, followed by a newline.
ò Take the square.
(implicit) Print the last return value.
add a comment |Â
up vote
1
down vote
Jelly, 10 9 bytes
9á¹Â2Xá¹Ââ¬á¸Âá¹Âò
Try it online!
How it works
9á¹Â2Xá¹Ââ¬á¸Âá¹Âò Main link. No arguments.
9 Set the return value to 9.
á¹Â2 Promote 9 to [1, ..., 9] and take the second Cartesian power, yielding
[[1, 1], [1, 2], ..., [9, 8], [9, 9]].
X Pseudo-randomly select one of the pairs.
á¹Â⬠Print each integer in the pair, followed by a newline.
ḠUndecimal; convert the integer pair from base 10 to an integer.
á¹ Print the integer, followed by a newline.
ò Take the square.
(implicit) Print the last return value.
add a comment |Â
up vote
1
down vote
up vote
1
down vote
Jelly, 10 9 bytes
9á¹Â2Xá¹Ââ¬á¸Âá¹Âò
Try it online!
How it works
9á¹Â2Xá¹Ââ¬á¸Âá¹Âò Main link. No arguments.
9 Set the return value to 9.
á¹Â2 Promote 9 to [1, ..., 9] and take the second Cartesian power, yielding
[[1, 1], [1, 2], ..., [9, 8], [9, 9]].
X Pseudo-randomly select one of the pairs.
á¹Â⬠Print each integer in the pair, followed by a newline.
ḠUndecimal; convert the integer pair from base 10 to an integer.
á¹ Print the integer, followed by a newline.
ò Take the square.
(implicit) Print the last return value.
Jelly, 10 9 bytes
9á¹Â2Xá¹Ââ¬á¸Âá¹Âò
Try it online!
How it works
9á¹Â2Xá¹Ââ¬á¸Âá¹Âò Main link. No arguments.
9 Set the return value to 9.
á¹Â2 Promote 9 to [1, ..., 9] and take the second Cartesian power, yielding
[[1, 1], [1, 2], ..., [9, 8], [9, 9]].
X Pseudo-randomly select one of the pairs.
á¹Â⬠Print each integer in the pair, followed by a newline.
ḠUndecimal; convert the integer pair from base 10 to an integer.
á¹ Print the integer, followed by a newline.
ò Take the square.
(implicit) Print the last return value.
edited 2 hours ago
answered 2 hours ago
Dennisâ¦
183k32293725
183k32293725
add a comment |Â
add a comment |Â
up vote
1
down vote
Ruby, 41 bytes
puts [(a=11+10*rand(81)/9)/10,a%10,a,a*a]
Try it online!
add a comment |Â
up vote
1
down vote
Ruby, 41 bytes
puts [(a=11+10*rand(81)/9)/10,a%10,a,a*a]
Try it online!
add a comment |Â
up vote
1
down vote
up vote
1
down vote
Ruby, 41 bytes
puts [(a=11+10*rand(81)/9)/10,a%10,a,a*a]
Try it online!
Ruby, 41 bytes
puts [(a=11+10*rand(81)/9)/10,a%10,a,a*a]
Try it online!
answered 2 hours ago
G B
7,3371327
7,3371327
add a comment |Â
add a comment |Â
up vote
1
down vote
Vim, 44 bytes
:%!$RANDOM
:s/0//g
2f:hy2hVpo=0*0
kYPa
Try it online!
Not the right tool for the job. This produces most likely the desired output
Step by step:
:%!$RANDOM
Enter Enter
Produces a string like/bin/bash: 25266: command not found
:s/0//g
removes all zeroes2f:hy2hVp
moves the cursor one to the left of the colon after the number, copy the last two digits and replace the entire string with thoseo
Ctrl+R=
Ctrl+R0*
Ctrl+R0
Enter
add a new line and evaluate an expression. In this case, I'll multiply the number in register 0 (the one that was just copied) with itself. Result:Esc
kYPa
Enter
Copy the upper line and paste it above. The cursor ends up in the first line, on the first character. Now we just have to append a line break to it
Limitations: If the result of $RANDOM
is a number with less than two non-zero digits, this will not produce the desired output
add a comment |Â
up vote
1
down vote
Vim, 44 bytes
:%!$RANDOM
:s/0//g
2f:hy2hVpo=0*0
kYPa
Try it online!
Not the right tool for the job. This produces most likely the desired output
Step by step:
:%!$RANDOM
Enter Enter
Produces a string like/bin/bash: 25266: command not found
:s/0//g
removes all zeroes2f:hy2hVp
moves the cursor one to the left of the colon after the number, copy the last two digits and replace the entire string with thoseo
Ctrl+R=
Ctrl+R0*
Ctrl+R0
Enter
add a new line and evaluate an expression. In this case, I'll multiply the number in register 0 (the one that was just copied) with itself. Result:Esc
kYPa
Enter
Copy the upper line and paste it above. The cursor ends up in the first line, on the first character. Now we just have to append a line break to it
Limitations: If the result of $RANDOM
is a number with less than two non-zero digits, this will not produce the desired output
add a comment |Â
up vote
1
down vote
up vote
1
down vote
Vim, 44 bytes
:%!$RANDOM
:s/0//g
2f:hy2hVpo=0*0
kYPa
Try it online!
Not the right tool for the job. This produces most likely the desired output
Step by step:
:%!$RANDOM
Enter Enter
Produces a string like/bin/bash: 25266: command not found
:s/0//g
removes all zeroes2f:hy2hVp
moves the cursor one to the left of the colon after the number, copy the last two digits and replace the entire string with thoseo
Ctrl+R=
Ctrl+R0*
Ctrl+R0
Enter
add a new line and evaluate an expression. In this case, I'll multiply the number in register 0 (the one that was just copied) with itself. Result:Esc
kYPa
Enter
Copy the upper line and paste it above. The cursor ends up in the first line, on the first character. Now we just have to append a line break to it
Limitations: If the result of $RANDOM
is a number with less than two non-zero digits, this will not produce the desired output
Vim, 44 bytes
:%!$RANDOM
:s/0//g
2f:hy2hVpo=0*0
kYPa
Try it online!
Not the right tool for the job. This produces most likely the desired output
Step by step:
:%!$RANDOM
Enter Enter
Produces a string like/bin/bash: 25266: command not found
:s/0//g
removes all zeroes2f:hy2hVp
moves the cursor one to the left of the colon after the number, copy the last two digits and replace the entire string with thoseo
Ctrl+R=
Ctrl+R0*
Ctrl+R0
Enter
add a new line and evaluate an expression. In this case, I'll multiply the number in register 0 (the one that was just copied) with itself. Result:Esc
kYPa
Enter
Copy the upper line and paste it above. The cursor ends up in the first line, on the first character. Now we just have to append a line break to it
Limitations: If the result of $RANDOM
is a number with less than two non-zero digits, this will not produce the desired output
edited 1 hour ago
answered 1 hour ago
oktupol
6379
6379
add a comment |Â
add a comment |Â
up vote
1
down vote
Java 8, 99 98 90 81 80 bytes
v->int i=81;i*=Math.random();return(i=i*10/9+11)/10+"n"+i%10+"n"+i+"n"+i*i;
-8 bytes after being inspired by @Arnauld's JavaScript answer.
-9 bytes thanks to @nwellnhof.
Try it online.
Explanation:
v-> // Method with empty unused parameter and no return-type
int i=81;i*=Math.random();// Create a random integer `i` in the range [0,81)
return(i=i*10/9+11) // Set `i` to 10 times `i`, integer-divided by 9, and 11 added
/10+"n" // Return the first digit of `i`, a newline,
+i%10+"n" // the last digit of `i`, a newline,
+i+"n" // `i` itself, a newline,
+i*i; // and `i` multiplied by itself
// All concatted to each other
@nwellnhof Thanks! And been able to golf 1 more byte with my previous trick ofint i=81;i*=Math.random();return(i=i*10/9+11)
.
â Kevin Cruijssen
1 hour ago
add a comment |Â
up vote
1
down vote
Java 8, 99 98 90 81 80 bytes
v->int i=81;i*=Math.random();return(i=i*10/9+11)/10+"n"+i%10+"n"+i+"n"+i*i;
-8 bytes after being inspired by @Arnauld's JavaScript answer.
-9 bytes thanks to @nwellnhof.
Try it online.
Explanation:
v-> // Method with empty unused parameter and no return-type
int i=81;i*=Math.random();// Create a random integer `i` in the range [0,81)
return(i=i*10/9+11) // Set `i` to 10 times `i`, integer-divided by 9, and 11 added
/10+"n" // Return the first digit of `i`, a newline,
+i%10+"n" // the last digit of `i`, a newline,
+i+"n" // `i` itself, a newline,
+i*i; // and `i` multiplied by itself
// All concatted to each other
@nwellnhof Thanks! And been able to golf 1 more byte with my previous trick ofint i=81;i*=Math.random();return(i=i*10/9+11)
.
â Kevin Cruijssen
1 hour ago
add a comment |Â
up vote
1
down vote
up vote
1
down vote
Java 8, 99 98 90 81 80 bytes
v->int i=81;i*=Math.random();return(i=i*10/9+11)/10+"n"+i%10+"n"+i+"n"+i*i;
-8 bytes after being inspired by @Arnauld's JavaScript answer.
-9 bytes thanks to @nwellnhof.
Try it online.
Explanation:
v-> // Method with empty unused parameter and no return-type
int i=81;i*=Math.random();// Create a random integer `i` in the range [0,81)
return(i=i*10/9+11) // Set `i` to 10 times `i`, integer-divided by 9, and 11 added
/10+"n" // Return the first digit of `i`, a newline,
+i%10+"n" // the last digit of `i`, a newline,
+i+"n" // `i` itself, a newline,
+i*i; // and `i` multiplied by itself
// All concatted to each other
Java 8, 99 98 90 81 80 bytes
v->int i=81;i*=Math.random();return(i=i*10/9+11)/10+"n"+i%10+"n"+i+"n"+i*i;
-8 bytes after being inspired by @Arnauld's JavaScript answer.
-9 bytes thanks to @nwellnhof.
Try it online.
Explanation:
v-> // Method with empty unused parameter and no return-type
int i=81;i*=Math.random();// Create a random integer `i` in the range [0,81)
return(i=i*10/9+11) // Set `i` to 10 times `i`, integer-divided by 9, and 11 added
/10+"n" // Return the first digit of `i`, a newline,
+i%10+"n" // the last digit of `i`, a newline,
+i+"n" // `i` itself, a newline,
+i*i; // and `i` multiplied by itself
// All concatted to each other
edited 1 hour ago
answered 3 hours ago
Kevin Cruijssen
32.7k554176
32.7k554176
@nwellnhof Thanks! And been able to golf 1 more byte with my previous trick ofint i=81;i*=Math.random();return(i=i*10/9+11)
.
â Kevin Cruijssen
1 hour ago
add a comment |Â
@nwellnhof Thanks! And been able to golf 1 more byte with my previous trick ofint i=81;i*=Math.random();return(i=i*10/9+11)
.
â Kevin Cruijssen
1 hour ago
@nwellnhof Thanks! And been able to golf 1 more byte with my previous trick of
int i=81;i*=Math.random();return(i=i*10/9+11)
.â Kevin Cruijssen
1 hour ago
@nwellnhof Thanks! And been able to golf 1 more byte with my previous trick of
int i=81;i*=Math.random();return(i=i*10/9+11)
.â Kevin Cruijssen
1 hour ago
add a comment |Â
up vote
1
down vote
05AB1E, 14 11 bytes
2F9Lé=}J=n,
-3 bytes thanks to @Emigna.
Try it online.
Explanation:
2F } # Loop 2 times:
9Lé # Create a list in the range [1,9], and pick a random element from it
= # Output it (without popping it from the stack)
J # Join them together
= # Output it (without popping it from the stack)
n # Take it to the power of 2
, # And output it as well
11 bytes alternative:
9Lãéé`îJDnû
Try it online.
Explanation:
9L # List in the range [1,9]
ã # Cartesian product with itself: [[1,1],[1,2],[1,3],...,[9,7],[9,8],[9,9]]
é # Take a random element from it
é # Store it in the register (without popping)
` # Pop and push both items as separated items onto the stack
î # Retrieve the list of digits from the register again
J # Join them together to a single 2-digit number
Dn # Duplicate it, and take the power of 2 of the copy
û # Merge all values on the stack by newlines (and output implicitly)
1
Shorter in a looP:2F9Lé=}J=n,
â Emigna
3 hours ago
@Emigna I was about to look for shorter alternatives, but smart use of the=
!
â Kevin Cruijssen
3 hours ago
add a comment |Â
up vote
1
down vote
05AB1E, 14 11 bytes
2F9Lé=}J=n,
-3 bytes thanks to @Emigna.
Try it online.
Explanation:
2F } # Loop 2 times:
9Lé # Create a list in the range [1,9], and pick a random element from it
= # Output it (without popping it from the stack)
J # Join them together
= # Output it (without popping it from the stack)
n # Take it to the power of 2
, # And output it as well
11 bytes alternative:
9Lãéé`îJDnû
Try it online.
Explanation:
9L # List in the range [1,9]
ã # Cartesian product with itself: [[1,1],[1,2],[1,3],...,[9,7],[9,8],[9,9]]
é # Take a random element from it
é # Store it in the register (without popping)
` # Pop and push both items as separated items onto the stack
î # Retrieve the list of digits from the register again
J # Join them together to a single 2-digit number
Dn # Duplicate it, and take the power of 2 of the copy
û # Merge all values on the stack by newlines (and output implicitly)
1
Shorter in a looP:2F9Lé=}J=n,
â Emigna
3 hours ago
@Emigna I was about to look for shorter alternatives, but smart use of the=
!
â Kevin Cruijssen
3 hours ago
add a comment |Â
up vote
1
down vote
up vote
1
down vote
05AB1E, 14 11 bytes
2F9Lé=}J=n,
-3 bytes thanks to @Emigna.
Try it online.
Explanation:
2F } # Loop 2 times:
9Lé # Create a list in the range [1,9], and pick a random element from it
= # Output it (without popping it from the stack)
J # Join them together
= # Output it (without popping it from the stack)
n # Take it to the power of 2
, # And output it as well
11 bytes alternative:
9Lãéé`îJDnû
Try it online.
Explanation:
9L # List in the range [1,9]
ã # Cartesian product with itself: [[1,1],[1,2],[1,3],...,[9,7],[9,8],[9,9]]
é # Take a random element from it
é # Store it in the register (without popping)
` # Pop and push both items as separated items onto the stack
î # Retrieve the list of digits from the register again
J # Join them together to a single 2-digit number
Dn # Duplicate it, and take the power of 2 of the copy
û # Merge all values on the stack by newlines (and output implicitly)
05AB1E, 14 11 bytes
2F9Lé=}J=n,
-3 bytes thanks to @Emigna.
Try it online.
Explanation:
2F } # Loop 2 times:
9Lé # Create a list in the range [1,9], and pick a random element from it
= # Output it (without popping it from the stack)
J # Join them together
= # Output it (without popping it from the stack)
n # Take it to the power of 2
, # And output it as well
11 bytes alternative:
9Lãéé`îJDnû
Try it online.
Explanation:
9L # List in the range [1,9]
ã # Cartesian product with itself: [[1,1],[1,2],[1,3],...,[9,7],[9,8],[9,9]]
é # Take a random element from it
é # Store it in the register (without popping)
` # Pop and push both items as separated items onto the stack
î # Retrieve the list of digits from the register again
J # Join them together to a single 2-digit number
Dn # Duplicate it, and take the power of 2 of the copy
û # Merge all values on the stack by newlines (and output implicitly)
edited 56 mins ago
answered 3 hours ago
Kevin Cruijssen
32.7k554176
32.7k554176
1
Shorter in a looP:2F9Lé=}J=n,
â Emigna
3 hours ago
@Emigna I was about to look for shorter alternatives, but smart use of the=
!
â Kevin Cruijssen
3 hours ago
add a comment |Â
1
Shorter in a looP:2F9Lé=}J=n,
â Emigna
3 hours ago
@Emigna I was about to look for shorter alternatives, but smart use of the=
!
â Kevin Cruijssen
3 hours ago
1
1
Shorter in a looP:
2F9Lé=}J=n,
â Emigna
3 hours ago
Shorter in a looP:
2F9Lé=}J=n,
â Emigna
3 hours ago
@Emigna I was about to look for shorter alternatives, but smart use of the
=
!â Kevin Cruijssen
3 hours ago
@Emigna I was about to look for shorter alternatives, but smart use of the
=
!â Kevin Cruijssen
3 hours ago
add a comment |Â
up vote
1
down vote
Python 2, 84 75 bytes
from random import*
k=randint(9,89)*10/9+1
for x in k/10,k%10,k,k*k:print x
Try it online!
Saved
- -1 bytes, thanks to Erik the Outgolfer
- -8 bytes, thanks to nwellnhof
Moderate golf: 83 bytes.
â Erik the Outgolfer
1 hour ago
@EriktheOutgolfer Thanks :)
â TFeld
45 mins ago
@nwellnhof Thanks :)
â TFeld
45 mins ago
add a comment |Â
up vote
1
down vote
Python 2, 84 75 bytes
from random import*
k=randint(9,89)*10/9+1
for x in k/10,k%10,k,k*k:print x
Try it online!
Saved
- -1 bytes, thanks to Erik the Outgolfer
- -8 bytes, thanks to nwellnhof
Moderate golf: 83 bytes.
â Erik the Outgolfer
1 hour ago
@EriktheOutgolfer Thanks :)
â TFeld
45 mins ago
@nwellnhof Thanks :)
â TFeld
45 mins ago
add a comment |Â
up vote
1
down vote
up vote
1
down vote
Python 2, 84 75 bytes
from random import*
k=randint(9,89)*10/9+1
for x in k/10,k%10,k,k*k:print x
Try it online!
Saved
- -1 bytes, thanks to Erik the Outgolfer
- -8 bytes, thanks to nwellnhof
Python 2, 84 75 bytes
from random import*
k=randint(9,89)*10/9+1
for x in k/10,k%10,k,k*k:print x
Try it online!
Saved
- -1 bytes, thanks to Erik the Outgolfer
- -8 bytes, thanks to nwellnhof
edited 45 mins ago
answered 3 hours ago
TFeld
12.8k2836
12.8k2836
Moderate golf: 83 bytes.
â Erik the Outgolfer
1 hour ago
@EriktheOutgolfer Thanks :)
â TFeld
45 mins ago
@nwellnhof Thanks :)
â TFeld
45 mins ago
add a comment |Â
Moderate golf: 83 bytes.
â Erik the Outgolfer
1 hour ago
@EriktheOutgolfer Thanks :)
â TFeld
45 mins ago
@nwellnhof Thanks :)
â TFeld
45 mins ago
Moderate golf: 83 bytes.
â Erik the Outgolfer
1 hour ago
Moderate golf: 83 bytes.
â Erik the Outgolfer
1 hour ago
@EriktheOutgolfer Thanks :)
â TFeld
45 mins ago
@EriktheOutgolfer Thanks :)
â TFeld
45 mins ago
@nwellnhof Thanks :)
â TFeld
45 mins ago
@nwellnhof Thanks :)
â TFeld
45 mins ago
add a comment |Â
up vote
0
down vote
C# (.NET Core), 130 bytes
Random r=new Random();int a=r.Next(1,9),b=r.Next(1,9),c=int.Parse(a.ToString()+b.ToString());Console.Write(a+" "+b+" "+c+" "+c*c);
Try it online!
Ungolfed:
Random r = new Random(); // initializes random number generator
int a = r.Next(1, 9), // gets random number between 1 and 9 inclusive
b = r.Next(1, 9), // gets random number between 1 and 9 inclusive
c = int.Parse(a.ToString() + b.ToString()); // concatenates a and b into one two-digit number
Console.Write(a + " " + b + " " + c + " " + c*c); // writes a, b, c, and c^2 to the console
add a comment |Â
up vote
0
down vote
C# (.NET Core), 130 bytes
Random r=new Random();int a=r.Next(1,9),b=r.Next(1,9),c=int.Parse(a.ToString()+b.ToString());Console.Write(a+" "+b+" "+c+" "+c*c);
Try it online!
Ungolfed:
Random r = new Random(); // initializes random number generator
int a = r.Next(1, 9), // gets random number between 1 and 9 inclusive
b = r.Next(1, 9), // gets random number between 1 and 9 inclusive
c = int.Parse(a.ToString() + b.ToString()); // concatenates a and b into one two-digit number
Console.Write(a + " " + b + " " + c + " " + c*c); // writes a, b, c, and c^2 to the console
add a comment |Â
up vote
0
down vote
up vote
0
down vote
C# (.NET Core), 130 bytes
Random r=new Random();int a=r.Next(1,9),b=r.Next(1,9),c=int.Parse(a.ToString()+b.ToString());Console.Write(a+" "+b+" "+c+" "+c*c);
Try it online!
Ungolfed:
Random r = new Random(); // initializes random number generator
int a = r.Next(1, 9), // gets random number between 1 and 9 inclusive
b = r.Next(1, 9), // gets random number between 1 and 9 inclusive
c = int.Parse(a.ToString() + b.ToString()); // concatenates a and b into one two-digit number
Console.Write(a + " " + b + " " + c + " " + c*c); // writes a, b, c, and c^2 to the console
C# (.NET Core), 130 bytes
Random r=new Random();int a=r.Next(1,9),b=r.Next(1,9),c=int.Parse(a.ToString()+b.ToString());Console.Write(a+" "+b+" "+c+" "+c*c);
Try it online!
Ungolfed:
Random r = new Random(); // initializes random number generator
int a = r.Next(1, 9), // gets random number between 1 and 9 inclusive
b = r.Next(1, 9), // gets random number between 1 and 9 inclusive
c = int.Parse(a.ToString() + b.ToString()); // concatenates a and b into one two-digit number
Console.Write(a + " " + b + " " + c + " " + c*c); // writes a, b, c, and c^2 to the console
edited 46 mins ago
answered 57 mins ago
Meerkat
1215
1215
add a comment |Â
add a comment |Â
up vote
0
down vote
K (oK), 28 bytes
t:2?10;t,:10/t;$t,:t[2]*t[2]
Explanation
t:2?10 //define t as two random numbers from 1-10
t,:10/t //join the base 10 joining of the elements of t to t
t,:t[2]*t[2]//join the square of the index 2 element to t
$ //String each element of the result (to output on newlines)
Try it online!
Cleaner Output, 32 bytes
t:2?10;t,:10/t;`0:$t,:t[2]*t[2];
`0: //Cleanly prints the strings
Try it online!
add a comment |Â
up vote
0
down vote
K (oK), 28 bytes
t:2?10;t,:10/t;$t,:t[2]*t[2]
Explanation
t:2?10 //define t as two random numbers from 1-10
t,:10/t //join the base 10 joining of the elements of t to t
t,:t[2]*t[2]//join the square of the index 2 element to t
$ //String each element of the result (to output on newlines)
Try it online!
Cleaner Output, 32 bytes
t:2?10;t,:10/t;`0:$t,:t[2]*t[2];
`0: //Cleanly prints the strings
Try it online!
add a comment |Â
up vote
0
down vote
up vote
0
down vote
K (oK), 28 bytes
t:2?10;t,:10/t;$t,:t[2]*t[2]
Explanation
t:2?10 //define t as two random numbers from 1-10
t,:10/t //join the base 10 joining of the elements of t to t
t,:t[2]*t[2]//join the square of the index 2 element to t
$ //String each element of the result (to output on newlines)
Try it online!
Cleaner Output, 32 bytes
t:2?10;t,:10/t;`0:$t,:t[2]*t[2];
`0: //Cleanly prints the strings
Try it online!
K (oK), 28 bytes
t:2?10;t,:10/t;$t,:t[2]*t[2]
Explanation
t:2?10 //define t as two random numbers from 1-10
t,:10/t //join the base 10 joining of the elements of t to t
t,:t[2]*t[2]//join the square of the index 2 element to t
$ //String each element of the result (to output on newlines)
Try it online!
Cleaner Output, 32 bytes
t:2?10;t,:10/t;`0:$t,:t[2]*t[2];
`0: //Cleanly prints the strings
Try it online!
edited 1 min ago
answered 29 mins ago
Thaufeki
16117
16117
add a comment |Â
add a comment |Â
up vote
0
down vote
PHP, 64 bytes
<?$d=($c=(10*($a=rand(1,9))+$b=rand(1,9)))*$c;echo"$a
$b
$c
$d";
Try it online!
add a comment |Â
up vote
0
down vote
PHP, 64 bytes
<?$d=($c=(10*($a=rand(1,9))+$b=rand(1,9)))*$c;echo"$a
$b
$c
$d";
Try it online!
add a comment |Â
up vote
0
down vote
up vote
0
down vote
PHP, 64 bytes
<?$d=($c=(10*($a=rand(1,9))+$b=rand(1,9)))*$c;echo"$a
$b
$c
$d";
Try it online!
PHP, 64 bytes
<?$d=($c=(10*($a=rand(1,9))+$b=rand(1,9)))*$c;echo"$a
$b
$c
$d";
Try it online!
answered 1 min ago
Jo.
98419
98419
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f175006%2fnumbers-manipulation-challenge%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
8
Can we output an array?
â Quintec
3 hours ago
1
Can we sample without replacement, ie exclude 1,1 2,2 3,3... from the pairs?
â JayCe
1 hour ago