เครื่องสร้างรหัสตั๋วสุ่ม


18

บริษัท ลอตเตอรีต้องการสร้างหมายเลขตั๋วลอตเตอรี่แบบสุ่มที่มีความยาว 10 อักขระ

เขียนรหัสในภาษาใด ๆ เพื่อสร้างตัวเลขที่ทุกหลักมาเพียงครั้งเดียวเช่น9354716208ในจำนวนนี้จำนวนเต็มทั้งหมดจาก 0 ถึง 9 มาเพียงครั้งเดียว หมายเลขนี้ควรเป็นตัวเลขสุ่ม

  • หมายเลขที่สร้างควรแสดงบนหน้าจอ
  • จะต้องสามารถสร้างการเรียงสับเปลี่ยนทั้งหมดของอักขระที่อนุญาตทั้งหมด
  • รหัสจำเป็นต้องมีขนาดเล็กที่สุดเท่าที่จะเป็นไปได้ (เป็นไบต์)

3
ทำไมมันควรอยู่ใน Java หรือ PhP?
Fabinout

4
โดยทั่วไปแล้วควรจะอนุญาตให้ใช้ภาษาใด ๆ ตามคำอธิบายของcode-golf
Konrad Borowski

10
ทำไมคำตอบที่ยาวที่สุดและน้อยที่สุด (คำตอบ SQL) โดยไม่นับแม้แต่ตัวอักษรนับเป็นคำตอบที่ยอมรับในcode-golfเมื่อคนอย่าง @Howard มีคำตอบ 5 หรือ 8 ตัว?
Darren Stone

1
ใช่ @marinus มีโซลูชัน 4 ไบต์ (ของฉันคือ 6 ไบต์)
Timtech

4
-1 การเลือกผู้ชนะนั้นไม่เหมาะสมเนื่องจากนี่เป็นความท้าทายของนักกอล์ฟ
DavidC

คำตอบ:


41

J (4 ไบต์)

ไม่สามารถต้านทาน

?~10

ใน J ถ้าFเป็น dyadic, เป็นเช่นเดียวกับF~ xx F x


3
+1 ฉันคิดว่าฉันอาจต้องลองทำอะไรที่สั้นกว่า Python เพื่อเอาชนะสิ่งนี้เล็กน้อย
Joachim Isaksson

นี่อนุญาตรหัสผ่านที่ขึ้นต้นด้วยศูนย์หรือไม่? ตามกฎของโปรแกรม "จะต้องสามารถสร้างการเรียงสับเปลี่ยนทั้งหมดของตัวละครที่อนุญาตทั้งหมด"
DavidC

@DavidCarraher: ใช่ มันเลือก 10 ตัวเลขสุ่มที่ไม่ซ้ำกันจากช่วง[0..10)ดังนั้นโดยทั่วไปหมายถึงการเปลี่ยนแปลงแบบสุ่มของ '0123456789'
marinus

1
ฉันเห็น. ฉันยกสิ่งนี้เพราะในภาษาส่วนใหญ่ "หมายเลข" 0123456789 จะถูกแก้ไขโดยอัตโนมัติไปยังแบบฟอร์ม 123456789 สตริง "0123456789" ยังคงไม่ถูกแตะต้อง ดังนั้นคำถามของฉันคือสิ่งนี้จริง ๆ : คุณเอาท์พุทเป็นตัวเลขหรือสตริง?
DavidC

@DavidCarraher มันเป็นอาร์เรย์
หวด

12

J, 5 ตัวอักษรและ APL, 8 ตัวอักษร

J

10?10

J มีตัวดำเนินการดีลในตัว ( ?) ดังนั้นเราสามารถนำ 10 จาก 10 ( 10?10)

APL

1-⍨10?10

APL มีโอเปอเรเตอร์เดียวกันซึ่งเริ่มต้นด้วยหนึ่งแทนที่จะเป็นศูนย์ เราจึงลบหนึ่งหมายเลขจากแต่ละหมายเลข ( 1-⍨XหมายถึงX-1เนื่องจากผู้ดำเนินการเดินทาง)


โอ้วววมันดีนะ
Konrad Borowski

ถ้า OP ขอให้หมายเลขไม่ใช่อาเรย์โดยเฉพาะคุณควรแปลงมันเป็น base10 number ด้วยโดย10#.
swish

คุณอาจสันนิษฐานได้ว่า⎕IO←0คุณไม่ต้องลบออก นอกจากนี้สำหรับทั้ง J และ APL คุณสามารถใช้การเดินทางเพื่อบันทึกไบต์ด้วย?~10และ?⍨10เนื่องจากแอปพลิเคชัน monadic ของฟังก์ชันที่ได้รับใช้อาร์กิวเมนต์ที่ถูกต้องและยังเป็นอาร์กิวเมนต์ซ้าย ทราบ แต่ที่นี้จะทำให้รหัส J เหมือนกับที่ Marinus
อดัม

9

Python 2.7 ( 64 63 57)

ไม่ใช่โอกาสที่นี่เมื่อเทียบกับภาษาหนักของโอเปอเรเตอร์และเนื่องจากไม่มีการโหลดแบบสุ่มเริ่มต้น :) นี่คือสั้นที่สุดที่ฉันสามารถหาได้

from random import*
print''.join(sample("0123456789",10))

มันสร้างช่วงและตัวอย่าง 10 ตัวเลขจากมันโดยไม่ต้องเปลี่ยน

(ขอบคุณ @xfix สำหรับการแก้ไขรูปแบบการนำเข้าที่สั้นกว่าและ @blkknght สำหรับการชี้ช่วงการสุ่มตัวอย่างที่ค่อนข้างซับซ้อนของฉัน)

Python 2.7 (40)

หากคุณเรียกใช้จากพรอมต์แบบอินเทอร์แอคทีฟและสามารถอ่านเครื่องหมายจุลภาคคั่นได้คุณสามารถโกนมันได้ถึง 40 แต่มันให้ความรู้สึกเหมือนเป็นการทำลายจิตวิญญาณของกฎ

from random import*
sample(range(10),10)

1
คุณสามารถใช้from random import*เพื่อบันทึกอักขระหนึ่งตัว ดูเหมือนว่าโซลูชัน Perl 6 ของฉัน แต่ verbose มากขึ้น แต่ก็ดีที่เห็นว่าสิ่งนี้สามารถทำงานใน Python แม้ว่า verbose มากขึ้น
Konrad Borowski

@ xfix ใช่น่าเศร้าที่โมดูลใน Python ค่อนข้างละเอียดในการเปรียบเทียบ :) อัปเดตด้วยการแก้ไขการนำเข้าของคุณซึ่งค่อนข้างใหม่สำหรับสิ่งตีกอล์ฟดังนั้นไม่ถึง "เสมอ" ในสำนวนของฉัน
Joachim Isaksson

คุณสามารถบันทึกอีกไม่กี่ตัวอักษรโดยการสุ่มตัวอย่างจากสตริง"0123456789"มากกว่าการใช้และการทำแผนที่พวกเขาrange str
Blckknght

@Blckknght ขอบคุณการปรับปรุงด้วยข้อเสนอแนะของคุณ :)
โจอาคิม Isaksson

8

PHP, 29 ตัวอักษร

<?=str_shuffle('0123456789');

ด้วย PHP ไม่จำเป็นต้องใช้แท็กปิด แต่ถ้ามันผิดกฎคุณก็สามารถแทนที่ได้ ด้วย?> สำหรับการเพิ่มสุทธิ 1 ครั้ง


คุณเอาชนะฉันในการแก้ปัญหานี้
Shaun Bebbers

8

ทับทิม, 18

รันสิ่งนี้ในirb:

[*0..9].shuffle*''

หากคุณต้องการให้สิ่งนี้เป็นโปรแกรมแบบสแตนด์อโลนที่มีเอาต์พุตไปที่stdout(กฎดูเหมือนจะไม่ต้องการสิ่งนี้) จากนั้นเพิ่ม 4 ตัวอักษรเหล่านี้ในตอนเริ่มต้น:

$><<

คุณอาจจะสั้นลงไป(0..9).to_a [*0..9]
Howard

ทำแล้วเสร็จครับ ขอบคุณ!
Darren Stone

ไม่เป็นไร แต่ทำไมคุณไม่ใช้[*0..9].shuffleตั้งแต่แรก?
Howard

@Howard เพราะมันสายและฉันเป็นใบ้ :) ขอบคุณ!
Darren Stone

อาร์เรย์ส่งคืนนี้มีหมายเลขไม่ใช่ number

8

PHP - 37 ตัวอักษร

<?=join('',array_rand(range(0,9),10))

ฉันมีวิธีแก้ปัญหา 18 ตัวที่ใช้งานได้จริงในทางทฤษฎี แต่ PHP นั้นแปลก

หรือถ้าคุณต้องการคำตอบ xkcd:

<?="5398421706" // Chosen by program above; guaranteed to be random ?>

แก้ไข: ขอบคุณ xfix ตอนนี้มันสั้นลงและเสร็จสมบูรณ์ 5 ตัวอักษร แก้ไขอีกครั้ง: ตัวอย่างสด


เขียนโปรแกรมที่สมบูรณ์แทนที่จะเป็นแค่ส่วนที่สมบูรณ์ นอกจากนี้echoไม่จำเป็นต้อง parens และถ้าechoเป็นคำสั่งแรกในโปรแกรมที่คุณสามารถแทนที่ด้วย<?php echo <?=นอกจากนี้ยังเป็นนามแฝงสำหรับjoin implode
Konrad Borowski

@ xfix ขอบคุณฉันจะแก้ไข :)
cjfaure

คุณไม่จำเป็นต้องและ<?= ?>มันเป็นโค้ด PHP ที่ถูกต้องหากไม่มีมัน
jeremy

@ Jeremy Golf ต้องการให้แสดงหมายเลข; นอกจากecho นี้ความยาวเท่ากับ<?=และ?>รวมกันและหากไม่มีสิ่งเหล่านี้มันจะไม่ทำงานใน Codepad ขอบคุณ : P
cjfaure

1
@ Jeremy Ah, PHP ซึ่งการใช้งานที่ไม่ได้ฝังตัวอยู่นอกเหนือจากเทอร์มินัลหายาก : P
cjfaure

8

Perl 6 (18 16 ตัวอักษร)

print pick *,^10

สิ่งนี้สร้างอาร์เรย์ที่มีองค์ประกอบแบบสุ่มทั้งหมด ( pick *) จาก0ถึง9และส่งออกผลลัพธ์ ( print)

ตัวอย่างผลลัพธ์:

$ perl6 -e 'print pick *,^10'
4801537269
$ perl6 -e 'print pick *,^10'
1970384265
$ perl6 -e 'print pick *,^10'
3571684902

+1 pickผมคิดว่าคุณไม่จำเป็นต้องเว้นวรรคก่อน
โฮเวิร์ด

1
@Howard: ฉันต้องการมันจริงๆ [~](ซึ่งแยกเป็น listop ตามไวยากรณ์ Perl 6) ต้องมีช่องว่าง (หรือ paren) หลังจากนั้นถ้ามันมีข้อโต้แย้งใด ๆ มิฉะนั้นคอมไพเลอร์ Perl 6 บ่นเกี่ยวกับ "สองคำในแถว" มันไม่จำเป็นสำหรับ Perl 6 รุ่นเก่า แต่นี่คืออดีต Perl 6 ยังคงทำงานต่อไป
Konrad Borowski

1
@xfix: ใช้printแทนsay [~]และบันทึก 2 ตัวอักษร :)
Ayiko

@Ayiko: ขอบคุณสำหรับการปรับปรุง :)
Konrad Borowski

7

GolfScript 12 ตัวอักษร

10,{;9rand}$

เพียงสร้างรายการของตัวเลข ( 10,) และเรียงลำดับ{...}$ตามคีย์สุ่มบางตัว - ซึ่งให้ลำดับของตัวเลขแบบสุ่ม

ตัวอย่าง (ลองออนไลน์ ):

4860972315

0137462985

ฉันกำลังจะโพสต์สิ่งนี้: P
Doorknob

นั่นคือการสลับแบบอึเป็นตัวอย่างเช่นตัวเลขตัวแรกจะมีค่าประมาณ 0 มากกว่า 1 เท่าการแทนที่9randด้วย99rand(ส่วนใหญ่) จะแทนที่ด้วย 9.?randจะได้รับการปฏิบัติจริงที่สมบูรณ์แบบ
Ilmari Karonen

1
@IlmariKaronen ฉันรู้ แต่คำถามไม่ได้พูดอะไรเกี่ยวกับการกระจายเครื่องแบบ
Howard

6

R (23 ตัวอักษร)

cat(sample(0:9),sep="")

ตัวอย่างผลลัพธ์:

> cat(sample(0:9),sep="")
3570984216
> cat(sample(0:9),sep="")
3820791654
> cat(sample(0:9),sep="")
0548697132

6

TI-BASIC 5 ไบต์

randIntNoRep(1,10

แสดงรายการแทนที่จะเป็นตัวเลข randIntNoRep(0,9:.1sum(Ans10^(cumSum(1 or Ansคุณกำลังมองหา
lirtosiast

2
ฉันไม่คิดว่าความท้าทายนี้ต้องใช้ประเภทจำนวนเต็มเฉพาะที่ "หมายเลขที่สร้างขึ้นควรแสดงบนหน้าจอ" ซึ่งเป็น
Timtech

อืมฉันคิดว่าคำถามกำลังขอหมายเลข (เช่นเดียวกับคนอื่น ๆแต่ดูเหมือนว่าเจตนาของผู้เขียนที่ท้าทายไม่เคยมีการชี้แจงโซลูชั่นอื่น ๆ ที่ส่งออกเป็นรายการ (J และ APL) ในกรณีใด ๆ
lirtosiast

ฉันจะไม่คิดว่าถ้าฉันไม่แน่ใจเพราะวิธีนี้สั้นกว่า
Timtech

5

ระดับแปดเสียง (14)

randperm(10)-1

randperm น่าเสียดายที่สร้างสิ่งที่เลือกจาก 1..n ดังนั้นต้องลบ 1 ท้ายเพื่อรับ 0-9


5

ในเซิร์ฟเวอร์ sql

DECLARE @RandomNo varchar(10)
SET @RandomNo = ''

;WITH num as (
SELECT 0 AS [number]
Union 
select 1
Union 
select 2
Union 
select 3
Union 
select 4
Union 
select 5
Union 
select 6
Union 
select 7
Union 
select 8
Union 
select 9
)
SELECT Top 9 @RandomNo = COALESCE(@RandomNo + '', '') + cast(n.number AS varchar(1))
FROM numbers n
ORDER BY NEWID()

SELECT cast(@RandomNo AS numeric(10,0))

ดูตัวอย่าง

หรือสิ่งที่คล้ายกัน (ความอนุเคราะห์ของ @manatwork) โดยใช้การเรียกซ้ำและ xml

with c as(select 0i union all select i+1from c where i<9)select i+0from c order by newid()for xml path('')

1
ผู้ชายคุณรัก CTEs ... แต่เนื่องจากนี่เป็นความท้าทายของนักกอล์ฟที่ดีกว่า ของฉันที่ดีที่สุดคือ 186 select i+0from(select 0i union select 1union select 2union select 3union select 4union select 5union select 6union select 7union select 8union select 9)f order by newid()for xml path('')ตัวอักษร: (BTW, เคล็ดลับที่ยอดเยี่ยมnewid())
จัดการ

1
ตกลงคุณขวา สั้นกว่าด้วย CTE 106 ตัวอักษร: with c as(select 0i union all select i+1from c where i<9)select i+0from c order by newid()for xml path('').
จัดการ

คุณสามารถทำให้ cte ง่ายขึ้นด้วย(VALUES (1),(2),...)
ypercubeᵀᴹ

5

Javascript ( 79 78 68 ตัวอักษร)

แทนที่จะสร้างอาร์เรย์ด้วยตัวเลข 0-9 และเรียงลำดับฉันตัดสินใจสร้างตัวเลขสุ่ม เมื่อมันมาพร้อมกับตัวเลขที่ไม่ได้อยู่ในอาเรย์แล้วเพิ่มมัน การทำซ้ำสิบครั้งแล้วแจ้งเตือนผลลัพธ์

for(a="";!a[9];){~a.indexOf(b=~~(Math.random()*10))||(a+=b)}alert(a)


คุณสามารถประหยัดได้ 1 ไบต์โดยใช้||การประเมินการลัดวงจรแทนif: for(a="";!a[9];){b=Math.floor(Math.random()*10);~a.indexOf(b)||(a+=b)}alert(a)
Steven Palinkas

1
@StevenPalinkas Thanks, great idea! I have updated the post accordingly.
scribblemaniac

We could also save 2 bytes with a bit of rearrangement in the code: for(a="";!a[9];){~a.indexOf(b=Math.floor(Math.random()*10))||(a+=b)}alert(a)
Steven Palinkas

We can save an additional 8 bytes using the "shorthand" for Math.floor like: for(a="";!a[9];){~a.indexOf(b=~~(Math.random()*10))||(a+=b)}alert(a)
Steven Palinkas


4

Shell/Coreutils, 23

shuf -i0-9|paste -sd ''

หากเราไม่ต้องการบรรทัดใหม่ที่ตามมาคุณสามารถโกนอันนี้ไว้ที่ 20 ด้วยshuf -i0-9|tr -d \\n
joeytwiddle

สิ่งที่เกี่ยวกับshuf -zi0-9
marcosm

@marcosm: นั่นให้บรรทัดที่ลงท้ายด้วยศูนย์ซึ่งแปลกเล็กน้อย
Hasturkun

4

JavaScript, 82 ตัวอักษร

แก้ไข:ขอบคุณRob W, code length is reduced to 90 characters.

แก้ไข:ขอบคุณGeorge Reith, code length is reduced to 82 characters (using for loop).

วิธีที่ตรงไปตรงมาสวย: เลือกองค์ประกอบแบบสุ่มของ [0,1,2,3,4,5,6,7,8,9] array and append it to the output, then reduce array and replay.

รุ่นเก่า (106 ตัวอักษร):

a=[0,1,2,3,4,5,6,7,8,9],l=11,t="";while(--l){r=Math.floor(Math.random()*l);t+=a[r];a.splice(r,1);}alert(t)

รุ่นที่อ่านได้:

a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], l = 10,t = "";
while(l--) {
  r = Math.floor(Math.random() * l);
  t += a[r];
  a.splice(r, 1);
}
alert(t);

รุ่นที่ดีกว่า (90 ตัวอักษร):

a="0123456789".split(t=""),l=11;while(--l)t+=a[r=0|Math.random()*l],a.splice(r,1);alert(t)

รุ่นล่าสุด (82 ตัวอักษร):

a="0123456789".split(t='');for(l=11;--l;t+=a.splice(0|Math.random()*l,1));alert(t)

JSFiddle: http://jsfiddle.net/gthacoder/qH3t9/


1
I golfed down your method to 90 characters: a='0123456789'.split(t=''),l=10;while(l--)t+=a[r=0|Math.random()*l],a.splice(r,1);alert(t). Big savers: Math.random(x) === 0|x. Replace curly braces and semicolons with commas. Directly use the result of an assignment as a value, instead of using an intermediate variable. Finally, initialize the initial array using .split(r=''). This is shorter than creating an array using array literals and assigning the string value in a separate expression.
Rob W

@RobW Thanks for the tips. I updated my answer. P.S. I guess you meant Math.floor(x) === 0|x.
gthacoder

1
This always has 9 at the end. To fix, initialize l=11 and switch your while loop condition to while(--l)
Greg

@Greg Good point. Thank you. I updated the answer.
gthacoder

1
82 Characters: a="0123456789".split(t='');for(l=11;--l;t+=a.splice(0|Math.random()*l,1));alert(t) - Your code fits perfectly into a for loops initialisation, condition and expression arguments. The r variable is redundant.
George Reith

4

C#, 145 bytes

Ungolfed

using System;
using System.Linq;
class P
{
    static void Main()
    {
        Enumerable.Range(0,10).OrderBy(g => Guid.NewGuid()).ToList().ForEach(Console.Write);
    }
}

Golfed

using System;using System.Linq;class P{static void Main(){Enumerable.Range(0,10).OrderBy(g => Guid.NewGuid()).ToList().ForEach(Console.Write);}}

1
You can use Enumerable.Range(0,10), and you don't need the curly brackets in the foreach loop.
Rik

3

JavaScript (80 characters)

alert("0123456789".split("").sort(function(){return .5-Math.random()}).join(""))

JS-Fiddle: http://jsfiddle.net/IQAndreas/3rmza/


3
Note this can be golfed further by using an arrow function (which currently only works in FF, but is coming soon to interpreters everywhere): alert("0123456789".split("").sort(n=>.5-Math.random()).join(""))
apsillers

1
You don't need the space between return and .5
Tibos

1
@Greg Shhhh! Do you have any idea how many characters a real shuffling function takes? ;)
IQAndreas

1
@Greg It is a random distribution (assuming Math.random is sufficiently random), it just isn't a uniform one.
SuperJedi224

1
The original blog post is gone, adding the internet archive for posterity: web.archive.org/web/20150212083701/http://sroucheray.org/blog/…
Greg


3

Mathematica 40

The number is created as a string so as to allow zero to be displayed as the first character, when needed.

""<>RandomSample["0"~CharacterRange~"9"]

Output examples

"0568497231"
"6813029574"

Explanation

"0"~CharacterRange~"9" is infix notation for `CharacterRange["0","9"]". Either of these returns the list, {"0","1","2","3","4","5","6","7","8","9"}.

RandomSample[list] by default returns a permutation of the list. (It can also be used for other kinds of sampling, when parameters are included. E.g. RandomSample[list, 4] will return a Random sample of 4 characters, with no repeats.


But why to display 0 as the first character?
Ankush

According to the OP, the program "must be able to generate all permutations of all allowable characters".
DavidC

@Ankush That's infix notation, so "0" is not always the first char.
Ajasja

Ajasja is correct. The program can generate any permutation. I added some remarks above to clarify this.
DavidC



2

Prolog, 177/302 characters

I'm a beginner on Prolog, so probably this is not the most condensed code.

:- use_module(library(clpfd)).
sort(N) :-
    N = [N0,N1,N2,N3,N4,N5,N6,N7,N8,N9],
    domain([N0],1,9),
    domain([N1,N2,N3,N4,N5,N6,N7,N8,N9],0,9),
    all_different(N),
    labeling([],N).

Returns:

| ?- sort2(N).                                         
N = [1,0,2,3,4,5,6,7,8,9] ? ;
N = [1,0,2,3,4,5,6,7,9,8] ? ;
N = [1,0,2,3,4,5,6,8,7,9] ? ;
N = [1,0,2,3,4,5,6,8,9,7] ? ;
N = [1,0,2,3,4,5,6,9,7,8] ? 
yes

If you want it to return an integer:

:- use_module(library(clpfd)).
sort(M) :-
    N = [N0,N1,N2,N3,N4,N5,N6,N7,N8,N9],
    domain([N0],1,9),
    domain([N1,N2,N3,N4,N5,N6,N7,N8,N9],0,9),
    all_different(N),
    labeling([],N),
    M is (N0*1000000000)+(N1*100000000)+(N2*10000000)+(N3*1000000)+
         (N4*100000)+(N5*10000)+(N6*1000)+(N7*100)+(N8*10)+N9.

Returns:

| ?- sort(N).
N = 1023456789 ? ;
N = 1023456798 ? ;
N = 1023456879 ? ;
N = 1023456897 ? ;
N = 1023456978 ? 
yes

Using instead:

labeling([down],N)

Gives the numbers in the opposite order:

| ?- sort(N).                                        
N = 9876543210 ? n
N = 9876543201 ? n
N = 9876543120 ? n
N = 9876543102 ? n
N = 9876543021 ? 
yes

Unlike some other codes posted, this returns all possibilities (with no repetitions).





2

Javascript, 83 characters

a=[];while(!a[9]){b=Math.floor(Math.random()*10);!a.includes(b)&&a.push(b)}alert(a)

While running until array has 10 elements.

Generating random number from 0 - 9 then check if array !includes this number and add it to the array.


1
Welcome to the site! :)
DJMcMayhem

1

This is not much smaller than JMK's answer, but here's a slightly smaller C# solution (135):

using System;
using System.Linq;
class P { 
    static void Main() 
    { 
        Console.Write(string.Join("", "0123456789".OrderBy(g => Guid.NewGuid()))); 
    } 
}

Compacted (134):

using System;using System.Linq;class P{static void Main(){Console.Write(string.Join("", "0123456789".OrderBy(g => Guid.NewGuid())));}}

Alternate version (135):

using System;
using System.Linq;
class P { 
    static void Main() 
    { 
        "0123456789".OrderBy(g => Guid.NewGuid()).ToList().ForEach(Console.Write); 
    } 
}

Compacted:

using System;using System.Linq;class P{static void Main(){"0123456789".OrderBy(g => Guid.NewGuid()).ToList().ForEach(Console.Write);}}

They're equal in length, but it really just depends on whether you want to use Linq's ForEach function or String's Join function. I was able to remove 10 characters in length by spelling out the range "0123456789" in a string instead of using Enumerable.Range(0, 10).


1

LOGO, 64 characters

make "d 1234567890
repeat 10 [
    make "n pick d
    show n
    make "d butmember n d
]

pick returns random item of the supplied list. butmember returns list with all occurrences of the specified item removed. Note: Not all Logo implementations support butmember command.


โดยการใช้ไซต์ของเรา หมายความว่าคุณได้อ่านและทำความเข้าใจนโยบายคุกกี้และนโยบายความเป็นส่วนตัวของเราแล้ว
Licensed under cc by-sa 3.0 with attribution required.