Fibonacci Butt Sort
1
Name:
Anonymous
2009-08-16 23:08
Let us discuss the various implementations of theF I B O N A C C I B U T T S O R T .
2
Name:
Anonymous
2009-08-16 23:09
3
Name:
Anonymous
2009-08-16 23:11
4
Name:
Anonymous
2009-08-16 23:14
>>1
U MENA
BINARY DICKS TREE ?
5
Name:
Anonymous
2009-08-16 23:18
6
Name:
Anonymous
2009-08-16 23:39
<3
7
Name:
Anonymous
2009-08-16 23:42
What does (binary_dicks_tree)<(fibonacci_butt_sort) evaluate to?
8
Name:
Anonymous
2009-08-17 0:15
9
Name:
Anonymous
2009-08-17 2:33
a,b = 0,1
while 1:
print b,
a,b = b,a+b
10
Name:
Anonymous
2009-08-17 11:03
11
Name:
Anonymous
2009-08-17 15:26
>>10
ANUSES[10] = {ANUS, ANUS, ANUS, ANUS, ANUS, ANUS, ANUS, ANUS, ANUS, ANUS, } ;
12
Name:
Anonymous
2009-08-17 15:42
From this point forward, if anyone on /prog/ asks about data structures, I'm going to reply F I B O N A C C I B U T T S O R T
13
Name:
Anonymous
2009-08-17 15:43
>>1,12
Will you GPL your BBCode?
14
Name:
Anonymous
2009-08-17 15:43
>>12
Don't you mean Haskell?
15
Name:
Anonymous
2009-08-17 15:44
[b][i][u]F[/u][o]I[/o][u]B[/u][o]O[/o][u]N[/u][o]A[/o][u]C[/u][o]C[/o][u]I[/u] [o]B[/o][u]U[/u][o]T[/o][u]T[/u] [o]S[/o][u]O[/u][o]R[/o][u]T[/u][/i][/b]
16
Name:
Anonymous
2009-08-17 15:48
Im writing a 'butt sorter' in J A V A to output the FBSorted BBCode for any text.
17
Name:
Anonymous
2009-08-17 15:50
>>16
BUTT SORT FAILURE
J A V A
18
Name:
Anonymous
2009-08-17 15:52
>>16
I hope you are going to use Fibonacci tail recursion to do it...
19
Name:
Anonymous
2009-08-17 16:14
F I B O N A C C I B U T T S O R T
20
Name:
Anonymous
2009-08-17 16:25
21
Name:
Anonymous
2009-08-17 16:47
>>15
Did you mean:
FIBONACCIBUTTSORT
Hint:
BBCode tags don't work inside the [code] tag.
22
Name:
Anonymous
2009-08-17 16:49
>>21
Your implementation needs work. Try skipping spaces
23
Name:
Anonymous
2009-08-17 16:57
>>21
Did you mean to read the fucking thread?
24
Name:
Anonymous
2009-08-17 17:05
>>21
lol no, that was just the source code.
25
Name:
Anonymous
2009-08-17 17:11
>>1
WTF is this shit? And how do I implement it to my advantage?
26
Name:
Anonymous
2009-08-17 17:32
( d e f u n w r i t e - t a g ( t a g s t r i n g )
( i f ( n u l l t a g )
" "
( f o r m a t n i l " [ ~ a ] ~ a [ / ~ a ] " t a g s t r i n g t a g ) ) )
( d e f u n b b - b u t t s o r t ( s )
" F I B O N A C C I B U T T S O R T "
( w r i t e - t a g " i "
( w r i t e - t a g " b "
( a p p l y # ' c o n c a t e n a t e ' s t r i n g
( l o o p f o r c a c r o s s s
a n d p a r i t y = n i l t h e n ( n o t p a r i t y )
c o l l e c t ( w r i t e - t a g ( i f p a r i t y " o " " u " ) c ) ) ) ) ) )
(defun write-tag (tag string)
(if (null tag)
""
(format nil "[~a]~a[/~a]" tag string tag)))
(defun bb-buttsort (s)
(write-tag "i"
(write-tag "b"
(apply #'concatenate 'string
(loop for c across s
and parity = nil then (not parity)
collect (write-tag (if parity "o" "u") c))))))
27
Name:
Anonymous
2009-08-17 17:33
F I B O N A C C I B U T T S O R T
28
Name:
>>26
2009-08-17 17:34
>>26
S e e m s i t n e e d s s o m e m o r e w o r k : ( B u t a t l e a s t F I B O N A C C I B U T T S O R T w o r k s
29
Name:
Anonymous
2009-08-17 17:58
Here's my implementation:
buttSort = b . i . unwords . map concat $ map xmap fbf `xmap` fbs
where fbf = cycle [u, o] : cycle [cycle [o, u]]
fbs = map tacnoc . words $ "FIBONACCI BUTT SORT"
xmap = zipWith ($)
tacnoc = map (:[])
A bit of a kludge, to be honest. What I ought to have done is written a custom iterator function instead of juggling map and xmap, so it would be intrinsically aware of the space-skipping requirement and I wouldn't have to fuck with fbf.
F I B O N A C C I B U T T S O R T
30
Name:
Anonymous
2009-08-17 18:16
>>29
Like this?
buttSort = b . i . go (cycle [u, o])
where go fs (' ':xs) = " " ++ go fs xs
go (f:fs) (x:xs) = f [x] ++ go fs xs
go _ [] = []
31
Name:
Anonymous
2009-08-17 18:18
>>30
I T H I N K T H E O U T P U T O F T H I S V E R S I O N I S A B S O L U T E L Y P E R F E C T
32
Name:
Anonymous
2009-08-17 18:37
>>30
buttSort = b . i . go (cycle [u, o]) where go fs (' ':xs) = " " ++ go fs xs go (f:fs) (x:xs) = f [x] ++ go fs xs go _ [] = []
33
Name:
Anonymous
2009-08-17 19:00
T e s t i n g m y k l u d g y s c h e m e b u t t s o r t
34
Name:
Anonymous
2009-08-17 19:01
>>33
Whoops, used
[sup] /
[sub] instead of
[o] /
[u]
T e s t i n g m y k l u d g y s c h e m e b u t t s o r t
35
Name:
Anonymous
2009-08-17 19:06
This works in PLT scheme. It's not the best solution, but I wanted to use unfold.
[code] (require srfi/1)
(define (make-cycle x)
(let ((clist (apply circular-list x)))
(lambda ()
(begin0
(car clist)
(set! clist (cdr clist))))))
(define bbcode-select
(let ((c (make-cycle (list o u))))
(lambda (x)
(if (string=? x " ")
" "
((c) x)))))
(define (buttsort x)
(b (i (apply string-append (unfold null? (lambda (y) (bbcode-select (car y))) cdr (regexp-split #rx"" x))))))[code]
36
Name:
Anonymous
2009-08-17 19:16
>>35
EXPERT BBC O D E F A I L U R E
37
Name:
Anonymous
2009-08-17 19:20
>>36
AmIforgiven? Am I forgiven?
AmIforgiven? Am I forgiven?
How abou t n o w ?
38
Name:
Anonymous
2009-08-17 19:29
>>37
No.
39
Name:
Anonymous
2009-08-17 19:30
40
Name:
Anonymous
2009-08-17 19:53
dicks
/ \
/ \
dicks dicks
/ \ / \
/ * / \
dicks dicks dicks
/ \ / \ / \
* dicks * * * dicks
41
Name:
Anonymous
2009-08-17 19:55
>>40
DICK TOWER is superior
42
Name:
Anonymous
2009-08-17 20:21
>>41
NO ITS NOT!
A Dick Tower has a growth complexity of N, whereas a Binary Dicks Tree has an average growth complexity of only log(N).
43
Name:
Anonymous
2009-08-17 20:23
Hello, /prog/, How are you this fine, fin e evening? I'll just leave th is here...
import java.io.IOException;
import java.util.*;
class Tag
{
private static Random generator = new Random(new Date().getTime());
private static Tag[] tags = new Tag[]
{
new Tag("b"), new Tag("i"), new Tag("u"), new Tag("o"),
};
private String name;
static Tag getRandomTag()
{
return tags[generator.nextInt(tags.length)];
}
private Tag(String name)
{
this.name = name;
}
public String getOpenForm()
{
return "[" + name + "]";
}
public String getClosedForm()
{
return "[/" + name + "]";
}
}
public class Progifier
{
public static void main(String[] args) throws IOException
{
Stack<Tag> tags = new Stack<Tag>();
Random generator = new Random(new Date().getTime());
while(System.in.available() > 0)
{
int b = System.in.read();
if(generator.nextInt(10) == 0)
System.out.print(tags.push(Tag.getRandomTag()).getOpenForm());
System.out.write(b);
if(generator.nextInt(50) == 0 && !tags.empty())
System.out.print(tags.pop().getClosedForm());
}
while(!tags.empty())
System.out.print(tags.pop().getClosedForm());
}
}
44
Name:
Anonymous
2009-08-17 20:29
>>43
Finally, something useful written in Java
It's still too verbose
45
Name:
Xarn
2009-08-17 20:29
>>42
If I enter 100 into my
ENTERPRISE DICKS MACHINE I want 100 delicious dicks to come out, not 2.
46
Name:
Anonymous
2009-08-17 20:32
>>43
Ne[i]w and imp[u]roved[o] [code]wit[o]h more[spoiler] tags![m]
[/m][/spoiler][/o][/code][/o][/u][/i]
diff
[m]
9a10
new Tag("spoiler"), new Tag("m"), new Tag("code")
[/m]
47
Name:
Anonymous
2009-08-17 21:15
Gentlemen, have you heard of the magical spirit conjuring technology called a M E T A C I R C U L A R B O O B U L A T O R ?
48
Name:
Anonymous
2009-08-17 22:07
>>47
The Pleasure of being Metacircularly Boobulated inside.
49
Name:
Anonymous
2009-08-18 0:11
50
Name:
Anonymous
2009-08-18 0:11
51
Name:
Anonymous
2009-08-18 4:34
Ne[i]w and imp[u]roved[o] [code]wit[o]h more[spoiler] tags![m]
[/m][/spoiler][/o][/code][/o][/u][/i]
52
Name:
Anonymous
2009-08-18 4:51
GENTLEMEN
53
Name:
Anonymous
2009-08-18 13:01
>>1
Is it Butt Sort or Buttsort?
54
Name:
Anonymous
2009-08-18 13:04
BUTTSORT
55
Name:
Anonymous
2009-08-18 15:31
F I B O N A C C I B U T T S O R T
56
Name:
Anonymous
2009-08-18 17:24
>>53
You're confusing it with a buttburst.
57
Name:
Anonymous
2009-08-19 3:56
58
Name:
Anonymous
2009-08-19 4:32
>>56
You're confusing sage with age.
59
Name:
Anonymous
2009-08-19 4:47
60
Name:
Anonymous
2009-08-23 22:23
jjjj
61
Name:
Anonymous
2009-08-24 12:12
Anybody have the source code for a buttsorter yet?
62
Name:
Anonymous
2009-08-24 12:32
63
Name:
/prog/ announcer
2009-08-24 12:46
>>61
Please read the threads before contributing, thank you.
64
Name:
Anonymous
2009-08-24 14:24
>>63
Sorry about that, I finally found the "Read entire thread" link. I thought the old posts were gone or something.
66
Name:
Anonymous
2009-08-24 18:30
67
Name:
Anonymous
2009-08-25 3:48
Guize I have written an implementation in C with UNICODE support.
[m] [b] [i] # i n c l u d e < s t d i o . h >
# i n c l u d e < w c h a r . h >
# i n c l u d e < s t r i n g . h >
# i n c l u d e < l o c a l e . h >
# i n c l u d e < e r r n o . h >
F I L E * f f f f f f f i b o n a c c i _ b u t t _ s o r t ( F I L E * s , s i z e _ t n )
{
s i z e _ t i = 0 ;
w i n t _ t t a g s [ ] = { L ' u ' , L ' o ' } ;
w i n t _ t c = W E O F ;
f o r ( i = 0 ; i < n ; + + i )
{
i f ( ( c = f g e t w c ( s ) ) = = L ' [u][/u]n ' )
{
f p u t w c ( L ' [u][/u]n ' , s t d o u t ) ;
r e t u r n s ;
}
e l s e i f ( i s w s p a c e ( c ) )
{
f p u t w c ( c , s t d o u t ) ;
}
e l s e i f ( c ! = W E O F )
{
w p r i n t f ( L " [ % l c ] % l c [ / % l c ] " , t a g s [ ( i % 2 ) ] , c , t a g s [ ( i % 2 ) ] ) ;
}
e l s e
{
r e t u r n N U L L ;
}
}
r e t u r n s ;
}
i n t m a i n ( )
{
i f ( ! s e t l o c a l e ( L C _ C T Y P E , N U L L ) )
{
f w p r i n t f ( s t d e r r , L " W a r n i n g : L o c a l e n o t s p e c i f i e d . [o] [/o]n " ) ;
}
c o n s t s i z e _ t B U F F A _ S I Z E = 4 0 9 6 ;
w i n t _ t c = W E O F ;
f p u t w s ( L " [ b ] [ i ] " , s t d o u t ) ;
w h i l e ( ( c = f g e t w c ( s t d i n ) ) ! = W E O F )
{
i f ( u n g e t w c ( c , s t d i n ) = = W E O F )
{
f p u t w s ( L " F a i l e d t o u n g e t w c <span class="o">. [u][/u]n " , s t d e r r ) ;
b r e a k ;
}
i f ( ! f f f f f f f i b o n a c c i _ b u t t _ s o r t ( s t d i n , B U F F A _ S I Z E ) )
{
b r e a k ;
}
}
f p u t w s ( L " [ / i ] [ / b <span class="o">] [u][/u]n " , s t d o u t ) ;
i f ( f e r r o r ( s t d i n ) )
{
p e r r o r ( s t r e r r o r ( e r r n o ) ) ;
f p u t w s ( L " I n p u t e r r o r o c c u r e d . O u t p u t p r o b a b l y c o r r u p t e d . "
" S h i t f u c k i n g s u c k s . [u] [/u]n " , s t d e r r ) ;
}
r e t u r n 0 ;
}
[/i] [/b] [/m]
[code]#include <stdio.h>
#include <wchar.h>
#include <string.h>
#include <locale.h>
#include <errno.h>
FILE* fffffffibonacci_butt_sort(FILE *s, size_t n)
{
size_t i = 0;
wint_t tags[] = {L'u', L'o'};
wint_t c = WEOF;
for(i = 0; i < n; ++i)
{
if((c = fgetwc(s)) == L'\n')
{
fputwc(L'\n', stdout);
return s;
}
else if(iswspace(c))
{
fputwc(c, stdout);
}
else if(c != WEOF)
{
wprintf(L"[%lc]%lc[/%lc]", tags[(i%2)], c, tags[(i%2)]);
}
else
{
return NULL;
}
}
return s;
}
int main()
{
if(!setlocale(LC_CTYPE, NULL))
{
fwprintf(stderr, L"Warning: Locale not specified.\n");
}
const size_t BUFFA_SIZE = 4096;
wint_t c = WEOF;
fputws(L"[b][i]", stdout);
while((c = fgetwc(stdin)) != WEOF)
{
if(ungetwc(c, stdin) == WEOF)
{
fputws(L"Failed to ungetwc.\n", stderr);
break;
}
if(!fffffffibonacci_butt_sort(stdin, BUFFA_SIZE))
{
break;
}
}
fputws(L"[/i][/b]\n", stdout);
if(ferror(stdin))
{
perror(strerror(errno));
fputws(L"Input error occured. Output probably corrupted."
"Shit fucking sucks.\n", stderr);
}
return 0;
}[/code]
Here's an example for UTF-8 input:
[spoiler]Invalid or incomplete multibyte or wide character: Invalid or incomplete multibyte or wide character[/spoiler]
68
Name:
Anonymous
2009-08-25 3:52
69
Name:
Anonymous
2009-08-25 4:15
>>67
BBCode corruption? Lesse why did it fail.
F I B O N A C C I B U T T S O R T
70
Name:
Anonymous
2009-08-25 4:17
>>69
Looks like Shii-chan doesn't like Standard See in BBCode as in
>>67 . :(
71
Name:
Anonymous
2009-08-30 2:59
Bootstrapping my Directed Acyclic Buttsorter .
Here we go!
[b] [i] import java.util.StringTokenizer; import javax.swing.JOptionPane; public class starter { public static void main(String args[]) { StringTokenizer st = new StringTokenizer(" "); String input = ""; String output = [u] "[b] [i] ";[/u] String next; int i = 1; input = JOptionPane.showInputDialog("Enter Text"); try { st = new StringTokenizer(input); } catch(Exception e) { } while(st.hasMoreTokens()) { i = i * -1; next = st.nextToken(); if(i > 0) { next = "" + next + " "; } else { next = [u] "[o] "[/u] + next + "[/o] "; } output = output + " " + next; } output = output + "[/i] [/b] "; System.out.println(output); JOptionPane.showInputDialog( null, "Enjoy your buttsort", "Buttsorter", JOptionPane.PLAIN_MESSAGE, null, null, output); } } [/i] [/b]
72
Name:
Anonymous
2009-08-30 3:12
What would the Sussman think about FBS?
73
Name:
Anonymous
2009-08-30 4:57
Sometimes I wonder if The Sussman is actually tsundere for /prog/ and whenever I read a weird thread, I imagine him reading it and wincing and wondering what the fuck is this.
74
Name:
Anonymous
2009-08-30 6:27
I am 12 Sussmans old and what is this
75
Name:
Anonymous
2009-08-30 6:42
>>74
[u][o][i]Back to /b/, please.[/i][/o][/u]
76
Name:
Anonymous
2009-08-30 10:10
F I B O N A C C I B U T T S O R T
77
Name:
Anonymous
2009-08-30 12:10
>>76
My
F I B O N A C C I B U T T hurts :(
78
Name:
Anonymous
2009-08-30 13:15
79
Name:
Anonymous
2009-08-30 13:50
>>78
T h e o f f i c i a l S I u n i t f o r F I B O N A C C I B U T T S O R T
80
Name:
Anonymous
2009-08-30 14:44
>>79
The background level is 50Hz. This value must be subtracted from all readings to estimate the real one.
81
Name:
Anonymous
2009-08-30 14:54
>>80
So that means that I am being buttsorted at a minimum of 50Hz right now at this very moment?
82
Name:
Anonymous
2009-08-30 15:07
>>81
Without a shadow of a doubt yes. Don't worry it's entirely normal.
83
Name:
Anonymous
2009-08-30 17:02
>>82
Unless of course, a second buttsort was being propagated in his proximity at 50Hz with an identical amplitude and 90 degree phase offset from the backround nose. Thus canceling out all active buttsorting.
84
Name:
Anonymous
2009-08-30 17:04
85
Name:
Anonymous
2009-08-30 17:10
>>84
Wave polarisation was a high school physics topic
86
Name:
Anonymous
2009-08-30 18:21
>>85
I just realised that I misread
>>83, he is talking about interference not polarisation
I'm a retard :(
87
Name:
Anonymous
2009-08-30 21:48
>>85
Interference was also a high school physics topic.
88
Name:
Anonymous
2009-08-31 4:37
>>86
Don't be too hard on yourself. Buttsort is hard at first.
89
Name:
Anonymous
2009-09-02 22:53
I A M A F R A I D T H A T I A C C I D E N T L Y M A D E A B U T T S O R T E R
90
Name:
Anonymous
2009-09-02 22:56
>>89
O H M Y , O H M Y
void buttsort(char* out,char* in){
strcpy(out,"[b][i]");
out += 6;
int i,c=0;
for(i=0;i<strlen(in);++i){
if(c%2){
strcpy(out,"[u]?[/u]");
}else{
strcpy(out,"[o]?[/o]");
}
out[3] = toupper(in[i]);
out += 8;
if(!isspace(in[i])) ++c;
}
strcpy(out,"[/i][/b]");
}
91
Name:
Anonymous
2009-09-03 1:32
>>90
Now rewrite it in OCaml
92
Name:
Anonymous
2009-09-03 1:38
93
Name:
Anonymous
2009-09-03 1:50
I thought we already had H A S K A L and Common Lisp i m p l e m e n t a t i o n s ?
94
Name:
Anonymous
2009-09-03 1:56
>>90
BUTT-UGLY
Testing:
t e s t i n g b u t t s o r t
95
Name:
Anonymous
2009-09-03 2:01
>>94
Providing a mIRC implementation.
Usage: /bs testing buttsort
Can be used as an identifier, e.g. $buttsort(testing buttsort)
Caveat: Will not function well at all if the output ends up being > 900 characters. This means that you can only do roughly 90 characters worth of input text.
alias bs { say $buttsort($$1-) }
alias bbcode { return $+($chr(91), $1, $chr(93)) }
alias endbbcode { return $bbcode($+($chr(47), $1)) }
alias buttsort {
var %text = $$1-
var %output = $bbcode(b) $+ $bbcode(i)
var %i = 1
var %ctr = 1
var %t = $len(%text)
while (%i <= %t) {
var %g = $mid(%text, %i, 1)
var %spacequantity = 0
while (%i <= %t && %g == $chr(32)) {
inc %i
inc %spacequantity
var %g = $mid(%text, %i, 1)
}
if (%i > %t && %spacequantity > 0) { break }
if (%ctr == 1) {
var %output = %output $+ $str($chr(32), %spacequantity) $+ $bbcode(u) $+ %g $+ $endbbcode(u)
var %ctr = 0
}
else {
var %output = %output $+ $str($chr(32), %spacequantity) $+ $bbcode(o) $+ %g $+ $endbbcode(o)
var %ctr = 1
}
inc %i
}
var %output = %output $+ $endbbcode(i) $+ $endbbcode(b)
return %output
}
96
Name:
Anonymous
2009-09-03 2:23
>>95
Thank you sir. I will be using this often.
97
Name:
Anonymous
2009-09-03 2:26
T e s t i n g t h r e e w o r d s
98
Name:
Anonymous
2009-09-03 2:39
T e s t i n g P o l y n o m i a l B u t t s o r t
99
Name:
Anonymous
2009-09-03 2:42
P B S = P o l y n om i a l B u t t s o rt ( TE S T 2 )
100
Name:
Anonymous
2009-09-03 2:44
No w f e at u rin g S P O I L E RS !
101
Name:
Anonymous
2009-09-03 2:48
>>98
Kinda cool
>>99
Getting retarded
>>100
Diarrhea Buttsort
Newer Posts