NHÓM STEAM
Kickass Programmers quprogs
NHÓM STEAM
Kickass Programmers quprogs
0
ĐANG CHƠI
6
TRÊN MẠNG
Thành lập
6 Tháng 11, 2015
Ngôn ngữ
Tiếng Anh
Tất cả thảo luận > General Discussion > Chi tiết chủ đề
makka 4 Thg06, 2016 @ 2:19pm
Code Golf -- Implement Bogosort
Haven't done a codegolf in awhile... and this one is just too good to pass.[codegolf.stackexchange.com]
Write the shortest function to implement bogosort. In specific, your function should:

Take an array (or your language's equivalent) as input
Check if its elements are in sorted order; if so, return the array
If not, shuffle the elements, and start again

GO GO GO GO
< >
Đang hiển thị 1-1 trong 1 bình luận
makka 4 Thg06, 2016 @ 3:10pm 
C++14, 158 bytes
Probably would be less bytes if the requirement were not for it to be uniform (could just use std::random_shuffle and not have to include random nor specify an engine or source of entropy).
include <algorithm> #include <random> [](int*a,int s){std::random_device r;for(std::knuth_b g(r());!std::is_sorted(a,a+s);std::shuffle(a,a+s,g));return a;};
< >
Đang hiển thị 1-1 trong 1 bình luận
Mỗi trang: 1530 50

Tất cả thảo luận > General Discussion > Chi tiết chủ đề