STEAM 群組
Kickass Programmers quprogs
STEAM 群組
Kickass Programmers quprogs
2
遊戲中
10
線上
創立
2015 年 11 月 6 日
語言
英文
所有討論 > General Discussion > 主題細節
makka 2016 年 6 月 4 日 下午 2:19
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
< >
目前顯示第 1-1 則留言,共 1
makka 2016 年 6 月 4 日 下午 3:10 
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;};
< >
目前顯示第 1-1 則留言,共 1
每頁顯示: 1530 50

所有討論 > General Discussion > 主題細節