| name | correct guesses | games together | ratio |
|---|---|---|---|
| seshoumara | 9 | 10 | 0.900 |
| Olek Sabak | 9 | 13 | 0.692 |
| yui | 4 | 6 | 0.667 |
| Moja | 5 | 8 | 0.625 |
| Olivia | 5 | 8 | 0.625 |
| chirk | 5 | 9 | 0.556 |
| kimapr | 12 | 23 | 0.522 |
| ponydork | 3 | 6 | 0.500 |
| yeti | 4 | 8 | 0.500 |
| Indigo | 5 | 10 | 0.500 |
| essaie | 9 | 18 | 0.500 |
| LyricLy | 8 | 19 | 0.421 |
| Makefile_dot_in | 4 | 10 | 0.400 |
| luatic | 4 | 11 | 0.364 |
| taswelll | 4 | 11 | 0.364 |
| oleander | 5 | 15 | 0.333 |
| rrebbbbeca | 2 | 7 | 0.286 |
| haru~ | 1 | 4 | 0.250 |
| *Ada | 1 | 4 | 0.250 |
| hyacinth | 1 | 5 | 0.200 |
| olive | 1 | 7 | 0.143 |
| JJRubes | 0 | 6 | 0.000 |
| name | correct guesses | games together | ratio |
|---|---|---|---|
| LyricLy | 10 | 20 | 0.500 |
| oleander | 7 | 15 | 0.467 |
| kimapr | 9 | 22 | 0.409 |
| Olivia | 3 | 9 | 0.333 |
| seshoumara | 3 | 10 | 0.300 |
| luatic | 3 | 11 | 0.273 |
| chirk | 2 | 8 | 0.250 |
| haru~ | 1 | 4 | 0.250 |
| Olek Sabak | 3 | 13 | 0.231 |
| hyacinth | 1 | 5 | 0.200 |
| taswelll | 2 | 11 | 0.182 |
| ponydork | 1 | 6 | 0.167 |
| yui | 1 | 6 | 0.167 |
| JJRubes | 1 | 6 | 0.167 |
| olive | 1 | 6 | 0.167 |
| essaie | 3 | 18 | 0.167 |
| Moja | 1 | 7 | 0.143 |
| rrebbbbeca | 1 | 7 | 0.143 |
| Indigo | 1 | 10 | 0.100 |
| yeti | 0 | 5 | 0.000 |
| Makefile_dot_in | 0 | 10 | 0.000 |
| *Ada | 0 | 4 | 0.000 |
submitted at
0 likes
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 | package main import ( // "fmt" "fmt" "strings" ) type ExprType int func getPadding(depth int) string { if depth == 0 { return "" } return strings.Repeat("│ ", depth-1) + "└── " } const ( EXPR_NOT = iota EXPR_OR EXPR_AND EXPR_ORLIST EXPR_ANDLIST EXPR_PAREN EXPR_VAR ) type Expression interface { temp_evaluate() bool print(depth int) string is_equal(rhs Expression) bool optimize_stage1() (Expression, bool) optimize_stage2() (Expression, bool) pre_compile(temp_counter int) ([]Operation, int) } // NOT EXPRESSION type NotExpr struct { expr Expression } func (e *NotExpr) temp_evaluate() bool { return !e.expr.temp_evaluate() } func (e *NotExpr) print(depth int) string { return getPadding(depth) + "NOT\n" + e.expr.print(depth+1) } func (e *NotExpr) is_equal(rhs Expression) bool { rhs_not, ok := rhs.(*NotExpr) if !ok { return false } return e.expr.is_equal(rhs_not.expr) } func (e *NotExpr) optimize_stage1() (Expression, bool) { var has_change bool e.expr, has_change = e.expr.optimize_stage1() // NOT NOT X === X if inner_not, ok := e.expr.(*NotExpr); ok { return inner_not.expr, true } // NOT (X) === NOT X if inner_paren, ok := e.expr.(*ParenExpr); ok { return &NotExpr{ expr: inner_paren.expr, }, true } return e, has_change } func (e *NotExpr) optimize_stage2() (Expression, bool) { var has_change bool e.expr, has_change = e.expr.optimize_stage2() // NOT (X OR Y) = (NOT X) AND (NOT Y) if inner_or, ok := e.expr.(*OrExpr); ok { return &AndExpr{ lhs: &NotExpr{inner_or.lhs}, rhs: &NotExpr{inner_or.rhs}, }, true } // NOT (X AND Y) = (NOT X) OR (NOT Y) if inner_and, ok := e.expr.(*AndExpr); ok { return &OrExpr{ lhs: &NotExpr{inner_and.lhs}, rhs: &NotExpr{inner_and.rhs}, }, true } // NOT ORLIST(X1, X2, ..., XN) = ANDLIST(NOT X1, NOT X2, ..., NOT XN) if inner_orlist, ok := e.expr.(*OrListExpr); ok { for i := range len(inner_orlist.exprs) { inner_orlist.exprs[i] = &NotExpr{ expr: inner_orlist.exprs[i], } } return &AndListExpr{ exprs: inner_orlist.exprs, }, true } // NOT ANDLIST(X1, X2, ..., XN) = ORLIST(NOT X1, NOT X2, ..., NOT XN) if inner_andlist, ok := e.expr.(*AndListExpr); ok { for i := range len(inner_andlist.exprs) { inner_andlist.exprs[i] = &NotExpr{ expr: inner_andlist.exprs[i], } } return &OrListExpr{ exprs: inner_andlist.exprs, }, true } return e, has_change } func (e *NotExpr) pre_compile(temp_counter int) ([]Operation, int) { var ops []Operation ops, temp_counter = e.expr.pre_compile(temp_counter) ops = append(ops, Operation{ result_var: "*" + fmt.Sprint(temp_counter), op_type: OP_NOT, operands: []string{ops[len(ops) - 1].result_var}, }) return ops, temp_counter + 1 } // OR EXPRESSION type OrExpr struct { lhs Expression rhs Expression } func (e *OrExpr) temp_evaluate() bool { return e.lhs.temp_evaluate() || e.rhs.temp_evaluate() } func (e *OrExpr) print(depth int) string { return getPadding(depth) + "OR\n" + e.lhs.print(depth+1) + "\n" + e.rhs.print(depth+1) } func (e *OrExpr) is_equal(rhs Expression) bool { rhs_or, ok := rhs.(*OrExpr) if !ok { return false } return e.lhs.is_equal(rhs_or.lhs) && e.rhs.is_equal(rhs_or.rhs) } func (e *OrExpr) optimize_stage1() (Expression, bool) { var has_change bool = false var c1 bool var c2 bool e.lhs, c1 = e.lhs.optimize_stage1() e.rhs, c2 = e.rhs.optimize_stage1() has_change = (c1 || c2) // X OR X === X if e.lhs.is_equal(e.rhs) { return e.lhs, true } // 0 OR X === X if lhs_var, ok := e.lhs.(*VarExpr); ok && lhs_var.name == "0" { return e.rhs, true } // X OR 0 === X if rhs_var, ok := e.rhs.(*VarExpr); ok && rhs_var.name == "0" { return e.lhs, true } // 1 OR X === 1 if lhs_var, ok := e.lhs.(*VarExpr); ok && lhs_var.name == "1" { return e.lhs, true } // X OR 1 === 1 if rhs_var, ok := e.rhs.(*VarExpr); ok && rhs_var.name == "1" { return e.rhs, true } // X OR NOT X === 1 if rhs_not, ok := e.rhs.(*NotExpr); ok && e.lhs.is_equal(rhs_not.expr) { return &VarExpr{name: "1"}, true } // NOT X OR X === 1 if lhs_not, ok := e.lhs.(*NotExpr); ok && e.rhs.is_equal(lhs_not.expr) { return &VarExpr{name: "1"}, true } return e, has_change } func (e *OrExpr) optimize_stage2() (Expression, bool) { var has_change bool var c1 bool var c2 bool e.lhs, c1 = e.lhs.optimize_stage2() e.rhs, c2 = e.rhs.optimize_stage2() has_change = (c1 || c2) lhs := e.lhs rhs := e.rhs // Ignore redundant parenthesis if lhs_paren, ok := lhs.(*ParenExpr); ok { lhs = lhs_paren.expr } if rhs_paren, ok := rhs.(*ParenExpr); ok { rhs = rhs_paren.expr } // OR // / \ // OR Z // / \ // X Y // Is equivalent to ORLIST(X, Y, Z) if lhs_or, ok := lhs.(*OrExpr); ok { return &OrListExpr{ exprs: []Expression{lhs_or.lhs, lhs_or.rhs, rhs}, }, true } // OR // / \ // X OR // / \ // Y Z // Is equivalent to ORLIST(X, Y, Z) if rhs_or, ok := rhs.(*OrExpr); ok { return &OrListExpr{ exprs: []Expression{lhs, rhs_or.lhs, rhs_or.rhs}, }, true } // OR // / \ // ORLIST Z // Is equivalent to adding one more element to the orlist if lhs_orlist, ok := lhs.(*OrListExpr); ok { lhs_orlist.exprs = append(lhs_orlist.exprs, rhs) return lhs_orlist, true } // OR // / \ // X ORLIST // / \ // Y Z // Is equivalent to adding one more element to the orlist if rhs_orlist, ok := rhs.(*OrListExpr); ok { rhs_orlist.exprs = append(rhs_orlist.exprs, lhs) return rhs_orlist, true } return e, has_change } func (e *OrExpr) pre_compile(temp_counter int) ([]Operation, int) { var ops_left []Operation var ops_right []Operation ops_left, temp_counter = e.lhs.pre_compile(temp_counter) ops_right, temp_counter = e.rhs.pre_compile(temp_counter) left_operand := ops_left[len(ops_left) - 1].result_var right_operand := ops_right[len(ops_right) - 1].result_var ops_left = append(ops_left, ops_right...) ops_left = append(ops_left, Operation{ result_var: "*"+fmt.Sprint(temp_counter), op_type: OP_OR, operands: []string{left_operand, right_operand}, }) return ops_left, temp_counter + 1 } // AND EXPRESSION type AndExpr struct { lhs Expression rhs Expression } func (e *AndExpr) temp_evaluate() bool { return e.lhs.temp_evaluate() && e.rhs.temp_evaluate() } func (e *AndExpr) print(depth int) string { return getPadding(depth) + "AND\n" + e.lhs.print(depth+1) + "\n" + e.rhs.print(depth+1) } func (e *AndExpr) is_equal(rhs Expression) bool { rhs_and, ok := rhs.(*AndExpr) if !ok { return false } return e.lhs.is_equal(rhs_and.lhs) && e.rhs.is_equal(rhs_and.rhs) } func (e *AndExpr) optimize_stage1() (Expression, bool) { var has_change bool = false var c1 bool var c2 bool e.lhs, c1 = e.lhs.optimize_stage1() e.rhs, c2 = e.rhs.optimize_stage1() has_change = (c1 || c2) // X AND X === X if e.lhs.is_equal(e.rhs) { return e.lhs, true } // 0 AND X === 0 if lhs_var, ok := e.lhs.(*VarExpr); ok && lhs_var.name == "0" { return e.lhs, true } // X AND 0 === 0 if rhs_var, ok := e.rhs.(*VarExpr); ok && rhs_var.name == "0" { return e.rhs, true } // 1 AND X === X if lhs_var, ok := e.lhs.(*VarExpr); ok && lhs_var.name == "1" { return e.rhs, true } // X AND 1 === X if rhs_var, ok := e.rhs.(*VarExpr); ok && rhs_var.name == "1" { return e.lhs, true } // X AND NOT X === 0 if rhs_not, ok := e.rhs.(*NotExpr); ok && e.lhs.is_equal(rhs_not.expr) { return &VarExpr{name: "0"}, true } // NOT X AND X === 0 if lhs_not, ok := e.lhs.(*NotExpr); ok && e.rhs.is_equal(lhs_not.expr) { return &VarExpr{name: "0"}, true } return e, has_change } func (e *AndExpr) optimize_stage2() (Expression, bool) { var has_change bool var c1 bool var c2 bool e.lhs, c1 = e.lhs.optimize_stage2() e.rhs, c2 = e.rhs.optimize_stage2() has_change = (c1 || c2) lhs := e.lhs rhs := e.rhs // Ignore redundant parenthesis if lhs_paren, ok := lhs.(*ParenExpr); ok { lhs = lhs_paren.expr } if rhs_paren, ok := rhs.(*ParenExpr); ok { rhs = rhs_paren.expr } // AND // / \ // AND Z // / \ // X Y // Is equivalent to ANDLIST(X, Y, Z) if lhs_and, ok := lhs.(*AndExpr); ok { return &AndListExpr{ exprs: []Expression{lhs_and.lhs, lhs_and.rhs, rhs}, }, true } // AND // / \ // X AND // / \ // Y Z // Is equivalent to ORLIST(X, Y, Z) if rhs_and, ok := rhs.(*AndExpr); ok { return &AndListExpr{ exprs: []Expression{lhs, rhs_and.lhs, rhs_and.rhs}, }, true } // AND // / \ // ANDLIST Z // Is equivalent to adding one more element to the orlist if lhs_andlist, ok := lhs.(*AndListExpr); ok { lhs_andlist.exprs = append(lhs_andlist.exprs, rhs) return lhs_andlist, true } // AND // / \ // X ANDLIST // / \ // Y Z // Is equivalent to adding one more element to the orlist if rhs_andlist, ok := rhs.(*AndListExpr); ok { rhs_andlist.exprs = append(rhs_andlist.exprs, lhs) return rhs_andlist, true } return e, has_change } func (e *AndExpr) pre_compile(temp_counter int) ([]Operation, int) { var ops_left []Operation var ops_right []Operation ops_left, temp_counter = e.lhs.pre_compile(temp_counter) ops_right, temp_counter = e.rhs.pre_compile(temp_counter) left_operand := ops_left[len(ops_left) - 1].result_var right_operand := ops_right[len(ops_right) - 1].result_var ops_left = append(ops_left, ops_right...) ops_left = append(ops_left, Operation{ result_var: "*" + fmt.Sprint(temp_counter), op_type: OP_AND, operands: []string{left_operand, right_operand}, }) return ops_left, temp_counter + 1 } // OR LIST EXPRESSION type OrListExpr struct { exprs []Expression } func (e *OrListExpr) temp_evaluate() bool { for _, ee := range e.exprs { if ee.temp_evaluate() { return true } } return false } func (e *OrListExpr) print(depth int) string { var out strings.Builder out.WriteString(getPadding(depth) + "ORLIST\n") for idx, item := range e.exprs { out.WriteString(item.print(depth + 1)) if idx != len(e.exprs)-1 { out.WriteString("\n") } } return out.String() } func (e *OrListExpr) is_equal(rhs Expression) bool { rhs_orlist, ok := rhs.(*OrListExpr) if !ok { return false } if len(rhs_orlist.exprs) != len(e.exprs) { return false } for i := range len(e.exprs) { if !e.exprs[i].is_equal(rhs_orlist.exprs[i]) { return false } } return true } func (e *OrListExpr) optimize_stage1() (Expression, bool) { has_change := false if len(e.exprs) == 1 { return e.exprs[0].optimize_stage1() } for i := range len(e.exprs) { c := false e.exprs[i], c = e.exprs[i].optimize_stage1() has_change = has_change || c } for i := range len(e.exprs) { current := e.exprs[i] // If an ORLIST contains 1 it should evaluate to true if current_var, ok := current.(*VarExpr); ok && current_var.name == "1" { return current_var, true } // If an ORLIST contains 0 it should be removed if current_var, ok := current.(*VarExpr); ok && current_var.name == "0" { e.exprs = remove_at_index(e.exprs, i) return e, true } for j := i + 1; j < len(e.exprs); j++ { other := e.exprs[j] // X OR X === X if current.is_equal(other) { e.exprs = remove_at_index(e.exprs, j) return e, true } // X OR NOT X === 1 if other_not, ok := other.(*NotExpr); ok && other_not.expr.is_equal(current) { return &VarExpr{name: "1"}, true } // NOT X OR X === 1 if current_not, ok := current.(*NotExpr); ok && current_not.expr.is_equal(other) { return &VarExpr{name: "1"}, true } } } return e, has_change } func (e *OrListExpr) optimize_stage2() (Expression, bool) { has_change := false for i := range len(e.exprs) { c := false e.exprs[i], c = e.exprs[i].optimize_stage2() has_change = has_change || c } for i := range len(e.exprs) { current := e.exprs[i] if current_paren, ok := current.(*ParenExpr); ok { current = current_paren.expr } // Nested OR in ORLIST if current_or, ok := current.(*OrExpr); ok { e.exprs = remove_at_index(e.exprs, i) e.exprs = append(e.exprs, current_or.lhs) e.exprs = append(e.exprs, current_or.rhs) return e, true } // Nested ORLIST in ORLIST if current_orlist, ok := current.(*OrListExpr); ok { e.exprs = remove_at_index(e.exprs, i) e.exprs = append(e.exprs, current_orlist.exprs...) return e, true } } return e, has_change } func (e *OrListExpr) pre_compile(temp_counter int) ([]Operation, int) { var ops []Operation var operands []string for _, e := range e.exprs { var expr_ops []Operation expr_ops, temp_counter = e.pre_compile(temp_counter) ops = append(ops, expr_ops...) operands = append(operands, expr_ops[len(expr_ops) - 1].result_var) } ops = append(ops, Operation{ result_var: "*" + fmt.Sprint(temp_counter), op_type: OP_OR, operands: operands, }) return ops, temp_counter + 1 } // AND LIST EXPORESSION type AndListExpr struct { exprs []Expression } func (e *AndListExpr) temp_evaluate() bool { for _, ee := range e.exprs { if !ee.temp_evaluate() { return false } } return true } func (e *AndListExpr) print(depth int) string { var out strings.Builder out.WriteString(getPadding(depth) + "ANDLIST\n") for idx, item := range e.exprs { out.WriteString(item.print(depth + 1)) if idx != len(e.exprs)-1 { out.WriteString("\n") } } return out.String() } func (e *AndListExpr) is_equal(rhs Expression) bool { rhs_andlist, ok := rhs.(*AndListExpr) if !ok { return false } if len(rhs_andlist.exprs) != len(e.exprs) { return false } for i := range len(e.exprs) { if !e.exprs[i].is_equal(rhs_andlist.exprs[i]) { return false } } return true } func (e *AndListExpr) optimize_stage1() (Expression, bool) { if len(e.exprs) == 1 { return e.exprs[0].optimize_stage1() } has_change := false for i := range len(e.exprs) { c := false e.exprs[i], c = e.exprs[i].optimize_stage1() has_change = has_change || c } for i := range len(e.exprs) { current := e.exprs[i] // If an ANDLIST contains 0 it should evaluate to false if current_var, ok := current.(*VarExpr); ok && current_var.name == "0" { return current_var, true } // If an ANDLIST contains 1 it should be removed if current_var, ok := current.(*VarExpr); ok && current_var.name == "1" { e.exprs = remove_at_index(e.exprs, i) return e, true } for j := i + 1; j < len(e.exprs); j++ { other := e.exprs[j] // X AND X === X if current.is_equal(e.exprs[j]) { e.exprs = remove_at_index(e.exprs, j) return e, true } // X AND NOT X === 0 if other_not, ok := other.(*NotExpr); ok && other_not.expr.is_equal(current) { return &VarExpr{name: "0"}, true } // NOT X AND X === 0 if current_not, ok := current.(*NotExpr); ok && current_not.expr.is_equal(other) { return &VarExpr{name: "0"}, true } } } return e, has_change } func (e *AndListExpr) optimize_stage2() (Expression, bool) { has_change := false for i := range len(e.exprs) { c := false e.exprs[i], c = e.exprs[i].optimize_stage2() has_change = has_change || c } for i := range len(e.exprs) { current := e.exprs[i] if current_paren, ok := current.(*ParenExpr); ok { current = current_paren.expr } // Nested AND in ANDLIST if current_and, ok := current.(*AndExpr); ok { e.exprs = remove_at_index(e.exprs, i) e.exprs = append(e.exprs, current_and.lhs) e.exprs = append(e.exprs, current_and.rhs) return e, true } // Nested ANDLIST in ANDLIST if current_andlist, ok := current.(*AndListExpr); ok { e.exprs = remove_at_index(e.exprs, i) e.exprs = append(e.exprs, current_andlist.exprs...) return e, true } } return e, has_change } func (e *AndListExpr) pre_compile(temp_counter int) ([]Operation, int) { var ops []Operation var operands []string for _, e := range e.exprs { var expr_ops []Operation expr_ops, temp_counter = e.pre_compile(temp_counter) ops = append(ops, expr_ops...) operands = append(operands, expr_ops[len(expr_ops) - 1].result_var) } ops = append(ops, Operation{ result_var: "*" + fmt.Sprint(temp_counter), op_type: OP_AND, operands: operands, }) return ops, temp_counter + 1 } // PAREN EXPRESSION type ParenExpr struct { expr Expression } func (e *ParenExpr) temp_evaluate() bool { return e.expr.temp_evaluate() } func (e *ParenExpr) print(depth int) string { return getPadding(depth) + "PAREN\n" + e.expr.print(depth+1) } func (e *ParenExpr) is_equal(rhs Expression) bool { rhs_paren, ok := rhs.(*ParenExpr) if !ok { return false } return e.expr.is_equal(rhs_paren.expr) } func (e *ParenExpr) optimize_stage1() (Expression, bool) { var has_change bool e.expr, has_change = e.expr.optimize_stage1() // (VAR) === VAR if inner_var, ok := e.expr.(*VarExpr); ok { return inner_var, true } // (NOT) === NOT if inner_not, ok := e.expr.(*NotExpr); ok { return inner_not, true } // ((X)) === (X) if inner_paren, ok := e.expr.(*ParenExpr); ok { return inner_paren, true } return e, has_change } func (e *ParenExpr) optimize_stage2() (Expression, bool) { var has_change bool e.expr, has_change = e.expr.optimize_stage2() return e, has_change } func (e *ParenExpr) pre_compile(temp_counter int) ([]Operation, int) { return e.expr.pre_compile(temp_counter) } // VAR EXPRESSION type VarExpr struct { name string } func (e *VarExpr) temp_evaluate() bool { return temp_env[e.name] } func (e *VarExpr) print(depth int) string { return getPadding(depth) + "VAR(" + e.name + ")" } func (e *VarExpr) is_equal(rhs Expression) bool { rhs_var, ok := rhs.(*VarExpr) if !ok { return false } return e.name == rhs_var.name } func (e *VarExpr) optimize_stage1() (Expression, bool) { return e, false } func (e *VarExpr) optimize_stage2() (Expression, bool) { return e, false } func (e *VarExpr) pre_compile(temp_counter int) ([]Operation, int) { return []Operation{ Operation{ result_var: e.name, op_type: OP_NOP, operands: []string{}, }, }, temp_counter } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | package main import ( "bufio" "fmt" "os" ); func main() { reader := bufio.NewReader(os.Stdin) fmt.Print("> ") input, err := reader.ReadString('\n') if err != nil { fmt.Println("Error reading input:", err) return } // TOKENIZE & PARSE tokenizer := Tokenizer{ str: input, current_pos: 0, } tokens := tokenizer.tokenize() p := Parser{ tokens: tokens, current_pos: 0, } expr_tree := p.parse() // OPTIMIZE has_change := true for has_change { expr_tree, has_change = expr_tree.optimize_stage1() if has_change { continue } expr_tree, has_change = expr_tree.optimize_stage2() } // COMPILE pre_compiled, _ := expr_tree.pre_compile(0) compiled, environment := compile_and_build_environment(pre_compiled) // SAT SOLVE true_env, sat := sat_solve(compiled, environment) if sat { fmt.Println("Given expression is satisfiable with these values:") for var_name := range true_env.env { if var_name[0] != '*' { fmt.Printf("%v = %v\n", var_name, true_env.get(var_name)) } } } else { fmt.Println("Given expression is unsatisfiable.") } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | package main type OperationType int const ( OP_NOP = iota OP_NOT OP_AND OP_OR OP_RET ) type Operation struct { result_var string op_type OperationType operands []string } type Environment struct { env map[string]bool } func (environment *Environment) get(name string) bool { switch name { case "1": return true case "0": return false } return environment.env[name] } func (environment *Environment) set(name string, value bool) { if name == "1" || name == "0" { return } environment.env[name] = value } func compile_and_build_environment(pre_compiled []Operation) ([]Operation, Environment) { var compiled []Operation var env Environment = Environment{ env: make(map[string]bool), } var final_var string for _, e := range pre_compiled { if e.op_type != OP_NOP { compiled = append(compiled, e) } else { env.set(e.result_var, false) } final_var = e.result_var } compiled = append(compiled, Operation{ result_var: final_var, op_type: OP_RET, operands: []string{}, }) return compiled, env } func execute(ops []Operation, env Environment) bool { if len(ops) == 0 { panic("Nothing to execute!") } for _, op := range ops { switch op.op_type { case OP_NOT: env.set(op.result_var, !env.get(op.operands[0])) case OP_OR: initial := false for _, elem := range op.operands { initial = (initial || env.get(elem)) } env.set(op.result_var, initial) case OP_AND: initial := true for _, elem := range op.operands { initial = (initial && env.get(elem)) } env.set(op.result_var, initial) case OP_RET: return env.get(op.result_var) case OP_NOP: panic("Compile your code first!") } } panic("Unreachable") } func sat_solve(code []Operation, env Environment) (Environment, bool) { keys := make([]string, 0, len(env.env)) for k := range env.env { keys = append(keys, k) } for i := 0; i < (1 << len(keys)); i++ { env_copy := Environment{env: make(map[string]bool)} for j, name := range keys { env_copy.set(name, (i>>j)&1 == 1) } if execute(code, env_copy) { return env_copy, true } } return env, false } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | package main import "fmt" var temp_env map[string]bool = map[string]bool{"1": true, "0": false}; type Parser struct { tokens []Token current_pos int } // PARSE func (p *Parser) expect(t TokenType) { tt := p.tokens[p.current_pos].token_type if tt == t { p.current_pos++ return } panic(fmt.Errorf("Expected token type \"%v\". Got \"%v\"!", t, tt)) } func (p *Parser) is_finished() bool { return p.current_pos >= len(p.tokens) || p.tokens[p.current_pos].token_type == TOK_EOF } func (p *Parser) parse() Expression { return p.parse_expr() } func (p *Parser) parse_expr() Expression { return p.parse_conj() } func (p *Parser) parse_conj() Expression { e1 := p.parse_disj() if p.is_finished() { return e1 } if p.tokens[p.current_pos].token_type == TOK_OR { p.current_pos++ e2 := p.parse_expr() return &OrExpr { lhs: e1, rhs: e2, } } return e1 } func (p *Parser) parse_disj() Expression { e1 := p.parse_other() if p.is_finished() { return e1 } if p.tokens[p.current_pos].token_type == TOK_AND { p.current_pos++ e2 := p.parse_expr() return &AndExpr { lhs: e1, rhs: e2, } } return e1 } func (p *Parser) parse_other() Expression { t := p.tokens[p.current_pos] switch t.token_type { case TOK_NOT: p.current_pos++ return &NotExpr{ expr: p.parse_expr(), } case TOK_LPAREN: p.current_pos++ expr := p.parse_expr() p.expect(TOK_RPAREN) return &ParenExpr{ expr: expr, } case TOK_VARIABLE, TOK_TRUE, TOK_FALSE: p.current_pos++ temp_env[t.lexime] = (t.token_type == TOK_TRUE) return &VarExpr{ name: t.lexime, } default: panic(fmt.Errorf("Unexpected token type \"%v\"!", t.token_type)) } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 | package main import "fmt" type TokenType int const ( TOK_NOT TokenType = iota TOK_OR TOK_AND TOK_TRUE TOK_FALSE TOK_LPAREN TOK_RPAREN TOK_VARIABLE TOK_EOF ) type Token struct { token_type TokenType lexime string position int } type Tokenizer struct { str string current_pos int } func is_valid_first_char(c byte) bool { return ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z') || c == '_' } func is_valid_char(c byte) bool { return is_valid_first_char(c) || ('0' <= c && c <= '9') } func is_whitespace(c byte) bool { return c == ' ' || c == '\t' || c == '\n' } func (t *Tokenizer) check(s string) (bool, string, error) { if t.current_pos+len(s) > len(t.str) { return false, "a", fmt.Errorf("Expected token \"%v\" is too long!", s) } substr := t.str[t.current_pos : t.current_pos+len(s)] return substr == s, substr, nil } func (t *Tokenizer) consume(l int) { t.current_pos += l } func (t *Tokenizer) expect(s string) error { got, substr, err := t.check(s) if err != nil { return err } if !got { return fmt.Errorf("Expected string \"%v\". Got \"%v\"!", s, substr) } t.consume(len(s)) return nil } func (t *Tokenizer) tokenize() []Token { tokens := make([]Token, 0) for t.current_pos < len(t.str) { c := t.str[t.current_pos] if c == ' ' || c == '\t' || c == '\n' { t.current_pos++ } else if got, _, _ := t.check("NOT"); got { t.expect("NOT") tokens = append(tokens, Token{ token_type: TOK_NOT, lexime: "NOT", }) } else if got, _, _ := t.check("OR"); got { t.expect("OR") tokens = append(tokens, Token{ token_type: TOK_OR, lexime: "OR", }) } else if got, _, _ := t.check("AND"); got { t.expect("AND") tokens = append(tokens, Token{ token_type: TOK_AND, lexime: "AND", }) } else if c == '1' { tokens = append(tokens, Token{ token_type: TOK_TRUE, lexime: "1", }) t.consume(1) } else if c == '0' { tokens = append(tokens, Token{ token_type: TOK_FALSE, lexime: "0", }) t.consume(1) } else if c == '(' { t.current_pos++ tokens = append(tokens, Token{ token_type: TOK_LPAREN, lexime: "(", }) } else if c == ')' { t.current_pos++ tokens = append(tokens, Token{ token_type: TOK_RPAREN, lexime: ")", }) } else { if is_valid_first_char(c) { start_pos := t.current_pos t.current_pos++ for t.current_pos < len(t.str) { cc := t.str[t.current_pos] if !is_valid_char(cc) { break } t.current_pos++ } end_pos := t.current_pos tokens = append(tokens, Token{ token_type: TOK_VARIABLE, lexime: string(t.str[start_pos:end_pos]), }) } else { panic(fmt.Errorf("Variable names cannot start with \"%v\"", string(c))) } } } tokens = append(tokens, Token{ token_type: TOK_EOF, lexime: "", }) return tokens } |
1 2 3 4 5 6 7 8 | package main func remove_at_index[T any](s []T, i int) []T { if i < 0 || i >= len(s) { return s } return append(s[:i], s[i+1:]...) } |
submitted at
1 like
1 | https://mega.nz/file/Yc4D3KAa#P4DPTURjrw5ssIGKijzCbK-Jg1fROX1X3q9vJ2YSbcE |
submitted at
0 likes
1 2 | def banana(x): return "banana" |
submitted at
1 like

submitted at
0 likes
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | def entry(): seq = set() n = 0 prev = 0 while True: if n == 0: seq.add(0) prev = 0 elif prev - n > 0 and prev - n not in seq: seq.add(prev - n) prev = prev - n else: seq.add(prev + n) prev = prev + n yield prev n += 1 |
submitted at
0 likes


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | #include "raylib.h" #include <stdbool.h> #include <stdio.h> #define MIN(x, y) ((x) < (y) ? (x) : (y)) #define MAX(x, y) ((x) > (y) ? (x) : (y)) typedef struct { int x; int y; int width; int height; Color color; } Box; bool aabb_collision(Box* a, Box* b) { return a->x < b->x + b->width && a->x + a->width > b->x && a->y < b->y + b->height && a->y + a->height > b->y; } int main() { const int screenWidth = 1280; const int screenHeight = 720; InitWindow(screenWidth, screenHeight, "Yaoi"); Box box1 = { .x = 20, .y = 300, .width = 128, .height = 128, .color = BLUE, }; Box box2 = { .x = 1100, .y = 300, .width = 128, .height = 128, .color = RED }; int spamton_frames = 0; int tenna_frames = 0; Image spamton = LoadImageAnim("spamton.png", &spamton_frames); ImageResize(&spamton, box1.width, box1.height); Image tenna = LoadImageAnim("tenna.png", &tenna_frames); ImageResize(&tenna, box2.width, box2.height); Texture2D spamton_texture = LoadTextureFromImage(spamton); Texture2D tenna_texture = LoadTextureFromImage(tenna); SetTargetFPS(60); const int SPD = 10; while (!WindowShouldClose()) { int dx1 = 0, dy1 = 0, dx2 = 0, dy2 = 0; if (IsKeyDown(KEY_LEFT)) { dx1 = -SPD; } if (IsKeyDown(KEY_RIGHT)) { dx1 = SPD; } if (IsKeyDown(KEY_UP)) { dy1 = -SPD; } if (IsKeyDown(KEY_DOWN)) { dy1 = SPD; } if (IsKeyDown(KEY_A)) { dx2 = -SPD; } if (IsKeyDown(KEY_D)) { dx2 = SPD; } if (IsKeyDown(KEY_W)) { dy2 = -SPD; } if (IsKeyDown(KEY_S)) { dy2 = SPD; } box1.x += dx1; box1.y += dy1; box2.x += dx2; box2.y += dy2; if(aabb_collision(&box1, &box2)) { int overlap_x = MIN(box1.x + box1.width, box2.x + box2.width) - MAX(box1.x, box2.x); int overlap_y = MIN(box1.y + box1.height, box2.y + box2.height) - MAX(box1.y, box2.y); Vector2 mtv = {.x = 0, .y = 0}; if (overlap_x < overlap_y) { mtv.x = overlap_x * (box1.x < box2.x ? -1 : 1); } else { mtv.y = overlap_y * (box1.y < box2.y ? -1 : 1); } if (dx1 != 0 || dy1 != 0) { box1.x += mtv.x; box1.y += mtv.y; } if(dx2 != 0 || dy2 != 0) { box2.x -= mtv.x; box2.y -= mtv.y; } } BeginDrawing(); ClearBackground(BLACK); DrawTexture(spamton_texture, box1.x, box1.y, WHITE); DrawTexture(tenna_texture, box2.x, box2.y, WHITE); EndDrawing(); } CloseWindow(); return 0; } |
submitted at
1 like
1 2 3 | input: _"input goes here" morse: ("a";"b";"c";"d";"e";"f";"g";"h";"i";"j";"k";"l";"m";"n";"o";"p";"q";"r";"s";"t";"u";"v";"w";"x";"y";"z";" ")!(".-";"-...";"-.-.";"-..";".";"..-.";"--.";"....";"..";".---";"-.-";".-..";"--";"-.";"---";".--.";"--.-";".-.";"...";"-";"..-";"...-";".--";"-..-";"-.--";"--..";"/") ` 0:" "/morse @ input |
submitted at
0 likes

submitted at
0 likes
1 2 3 4 5 6 7 8 9 10 | #include <unordered_map> using namespace std; int entry(int x) { static std::unordered_map<int, int> table = {{1, 1}}; if(table.count(x)) return table[x]; return (table[x] = 1 + entry(x - entry(entry(x - 1)))); } |
1 2 3 4 5 6 7 8 9 | int entry(int x) { static int[int] table; table[1] = 1; if(auto p = x in table) { return *p; } return (table[x] = 1 + entry(x - entry(entry(x - 1)))); } |
1 2 3 4 5 6 7 8 9 10 11 | var table = make(map[int]int) func entry(x int) int { table[1] = 1 val, ok := table[x] if ok { return val } table[x] = 1 + entry(x-entry(entry(x-1))) return table[x] } |
1 2 3 | entry :: Int -> Int entry 1 = 1 entry n = (1+) <$> entry $ (n-) <$> entry $ entry $ n - 1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | import java.util.HashMap; class Main { private static int entry(int x) { final HashMap<Integer, Integer> table = new HashMap<Integer, Integer>(); table.put(1, 1); if(table.get(x) != null) { return table.get(x); } int y = 1 + entry(x - entry(entry(x - 1))); table.put(x, y); return y; } } |
1 2 3 4 5 6 7 8 9 | const table = {1:1} function entry(x) { if(x in table) { return table[x]; } table[x] = 1 + entry(x - entry(entry(x - 1))); return table[x]; } |
1 2 3 4 5 6 7 8 9 | tbl = {[1]=1} function entry(x) if tbl[x] ~= nil then return tbl[x] end tbl[x] = 1 + entry(x - entry(entry(x - 1))) return tbl[x] end |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | <?php $table = array(); $table[1] = 1; function entry($x) { global $table; if(array_key_exists($x, $table)) { return $table[$x]; } $table[$x] = 1 + entry($x - entry(entry($x - 1))); return $table[$x]; } ?> |
1 2 3 4 5 6 7 | table = {1:1} def entry(x): if x in table: return table[x] table[x] = 1 + entry(x - entry(entry(x - 1))) return table[x] |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | use std::collections::HashMap; fn entry(table: &mut HashMap<i32, i32>, x: i32) -> i32 { if let Some(&v) = table.get(&x) { return v; } let a = entry(table, x - 1); let b = entry(table, a); let val = 1 + entry(table, x - b); table.insert(x, val); val } |
submitted at
0 likes
1 2 3 4 5 6 | print("---- AM I GAY QUIZ ----") yn = input("Are you gay? (Y/n): ") if yn == 'y' or yn == 'Y': print("You are gay") else: print("Don't lie to me, you are gay.") |
1 2 3 4 5 6 7 | # You shouldn't be looking here ;) QUESTION "Which one is the best drink according to LyricLy?" ANSWERS "Coca-Cola" "Sprite" "Corona" "Dr. Pepper" CORRECT 4 QUESTION "Will LyricLy ever implement macron?" ANSWERS "Yes" "No" CORRECT 2 QUESTION "Which type of genre LyricLy hates the most?" ANSWERS "Sokoban" "RPG" "Platformer" "Sandbox" CORRECT 1 QUESTION "What is LyricLy's birthday?" ANSWERS "Oct 29th" "Oct 30th" "Nov 29th" "Nov 30th" CORRECT 4 QUESTION "Which game LyricLy plays the most?" ANSWERS "Minecraft" "Overwatch 2" "Town of Salem 2" "Terraria" CORRECT 3 QUESTION "As of now, when did LyricLy's oldest public video got uploaded to YouTube?" ANSWERS "Feb 12 2015" "March 12 2015" "Feb 12 2016" "March 12 2016" CORRECT 1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 | function skip_ws(line, i) while true do local c = line:sub(i, i) if c == ' ' or c == '\t' then i = i + 1 else break end end return i end function expect(line, phrase, i, lineno) local start_i = i local phrase_len = #phrase for idx=1,phrase_len do local c1 = phrase:sub(idx, idx) local c2 = line:sub(i + idx - 1, i + idx - 1) if c1 ~= c2 then error("Expected \"" .. phrase .. "\" on ".. lineno .. ":" .. i) end end return i + phrase_len end function parse_quoted(line, i, lineno) i = expect(line, "\"", i, lineno) local content = "" local idx = 1 while true do local c = line:sub(i + idx - 1, i + idx - 1) if c == "\"" then i = i + idx break elseif c == "\\" then local nextc = line:sub(i + idx, i + idx) local ch = "" if nextc == "\\" then ch = "\\" elseif nextc == "\"" then ch = "\"" elseif nextc == "t" then ch = "\t" elseif nextc == "n" then ch = "\n" else error("Unknown escape sequence \"\\" .. nextc .. "\" on " .. (i + idx) .. ":" .. lineno) end content = content .. ch idx = idx + 1 else content = content .. c end idx = idx + 1 end return content, i end function parse_num(line, i) local final_num = "" while true do local c = line:sub(i, i) local b = string.byte(c) if not b then break end if b >= string.byte('0') and b <= string.byte('9') then final_num = final_num .. c i = i + 1 else break end end return tonumber(final_num), i end function parse_ending(line, i, lineno) while true do local c = line:sub(i, i) if c == "\0" or c == nil or c == "#" or #c == 0 then break elseif c ~= " " and c ~= "\t" then error("Unexpected character '" .. c .. "' at " .. lineno .. ":" .. i) end i = i + 1 end return i end function parse_line(line, lineno) local line_index = 1 line_index = skip_ws(line, line_index) local first_char = line:sub(line_index, line_index) if first_char == '#' or #first_char == 0 then return nil end local question_body = "" local answers = {} local correct_idx = 0 line_index = expect(line, "QUESTION", line_index, lineno) line_index = skip_ws(line, line_index) question_body, line_index = parse_quoted(line, line_index, lineno) line_index = skip_ws(line, line_index) line_index = expect(line, "ANSWERS", line_index, lineno) line_index = skip_ws(line, line_index) while true do local c = line:sub(line_index, line_index) if c ~= "\"" then break end local answer = "" answer, line_index = parse_quoted(line, line_index, lineno) table.insert(answers, answer) line_index = skip_ws(line, line_index) end line_index = expect(line, "CORRECT", line_index, lineno) line_index = skip_ws(line, line_index) correct_idx, line_index = parse_num(line, line_index) line_index = parse_ending(line, line_index, lineno) return { question = question_body, answers = answers, correct_idx = correct_idx } end function read_file(filename) local file = io.open(filename, "r") if not file then error("Unable to load file") end local quiz_list = {} local lineno = 1 for line in file:lines() do local quiz = parse_line(line, lineno) if not quiz then goto continue end table.insert(quiz_list, quiz) lineno = lineno + 1 ::continue:: end file:close() return quiz_list end print("LyricLy quiz") print() local quiz_list = read_file("data.txt") local total = #quiz_list local correct = 0 local alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" for i,quiz in ipairs(quiz_list) do print(quiz.question) for j,answer in ipairs(quiz.answers) do print(alphabet:sub(j,j) .. ") " .. answer) end ::take_input:: io.write("> ") local ans = io.read("*l"):upper() if #ans ~=1 or not (string.byte(ans) >= string.byte("A") and string.byte(ans) <= string.byte("Z")) then print("Invalid input!") goto take_input end local idx = string.byte(ans) - string.byte('A') + 1 if idx == quiz.correct_idx then correct = correct + 1 end end print("Quiz is over, you got " .. correct .. " out of " .. total .. " correct.") |
submitted at
0 likes
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | mn="";t=true;c=false;buf="";h="Herobrine";wm=(m,nl)=>{pi=3.14; o=process.stdout;dn="disconnect";o.clearLine(0);o.cursorTo(0); o.write(m);if(nl)o.write('\n');};cn="connect";s=new WebSocket( 'wss://codeguessing.gay/73/ws:443');q=1;wp=()=>{wm(`> ${buf}`) ;};wlw=()=>{wm(`My name is "${mn}" ^_^`,t);};j=2;ws=(u,c)=>{wm (`${u}: ${c}`,t);};s.onmessage=(e)=>{try{j=JSON.parse(e.data); r=j.reason;n=j.name;if(r===cn){b=25;if(!c){c=t;mn=n;wlw();wp() ;}else{sn=Math.random()<1e-3?h:n;le="boobs";a="APRIL FOOLS";wm (`${sn} has joined`,t);wp();}}else if(r==="message"){if(n!==mn ){c=j.content;ws(n,c);wp();}}else if(r===dn){wm(`${n} has left `);wp();}else{wm(`${e.data}`,t);wp();}}catch(e){h="HAHAHAHAHA" ;wm(`${e}`);s.close();}};p=process;auth="SoundOfSpouting#6980" ;i=p.stdin;i.setRawMode(t);g=10;e=3;uid="151149148639330304";i .resume();i.setEncoding('utf8');ip=(k)=>{chir=k.charCodeAt(0); return(chir>=32&&chir<=126)||(chir>=160&&chir<=55295)||(chir>= 57344&&chir<=1114111);};i.on('data',(k)=>{chir=k.charCodeAt(0) ;if(k==='\u0003'){s.close();p.exit();}else if(chir===13){qwd=2 ;if(!t||buf===""||!c)return;buf=buf.replace('"','\\"');qwd<3;s .send(`{"content": "${buf}"}`);ws(mn,buf);buf="";wp();}else if (chir===127){buf=buf.substr(0,buf.length-1);wp();}if(ip(k)==!t )return;buf+=k;wp();});i.on('end',()=>{p.exit();});// Weeeeeee |
submitted at
0 likes
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 | #include <stdio.h> #include <string.h> #include "vector.h" typedef struct HuffmanNode { char c; int freq; struct HuffmanNode *left; struct HuffmanNode *right; } HuffmanNode; DEFINE_VEC(HuffmanNode); IMPLEMENT_VEC(HuffmanNode); void count_freqs(const char *str, size_t len, vector_HuffmanNode *out) { for (size_t i = 0; i < len; ++i) { char c = str[i]; int found = 0; FORV(i, *out) { HuffmanNode *node = vector_HuffmanNode_atp(out, i); if (node->c == c) { ++node->freq; found = 1; } } if (!found) { vector_HuffmanNode_push( out, (HuffmanNode){.c = c, .freq = 1, .left = NULL, .right = NULL}); } } } void free_tree(HuffmanNode *node) { if (node->c == '\0') { free_tree(node->left); free_tree(node->right); } free(node); } void swap_nodes(HuffmanNode *const a, HuffmanNode *const b) { HuffmanNode temp = *a; *a = *b; *b = temp; } void min_heapify(vector_HuffmanNode *const vec, size_t idx) { size_t left = 2 * idx + 1; size_t right = 2 * idx + 2; size_t smallest = idx; if (left < vec->len && vector_HuffmanNode_at(vec, left).freq < vector_HuffmanNode_at(vec, smallest).freq) smallest = left; if (right < vec->len && vector_HuffmanNode_at(vec, right).freq < vector_HuffmanNode_at(vec, smallest).freq) smallest = right; if (smallest != idx) { swap_nodes(vector_HuffmanNode_atp(vec, idx), vector_HuffmanNode_atp(vec, smallest)); min_heapify(vec, smallest); } } void build_min_heap(vector_HuffmanNode *const vec) { for (int i = vec->len / 2 - 1; i >= 0; --i) { min_heapify(vec, i); } } void build_tree(vector_HuffmanNode *const vec, HuffmanNode *out) { build_min_heap(vec); while (vec->len > 1) { swap_nodes(vector_HuffmanNode_atp(vec, 0), vector_HuffmanNode_atp(vec, vec->len - 1)); HuffmanNode right = vector_HuffmanNode_pop(vec); min_heapify(vec, 0); swap_nodes(vector_HuffmanNode_atp(vec, 0), vector_HuffmanNode_atp(vec, vec->len - 1)); HuffmanNode left = vector_HuffmanNode_pop(vec); min_heapify(vec, 0); HuffmanNode *rightp = malloc(sizeof(HuffmanNode)); HuffmanNode *leftp = malloc(sizeof(HuffmanNode)); *rightp = right; *leftp = left; HuffmanNode new = (HuffmanNode){ .c = '\0', .freq = left.freq + right.freq, .left = leftp, .right = rightp, }; vector_HuffmanNode_push(vec, new); size_t i = vec->len - 1; while (i > 0) { size_t parent = (i - 1) / 2; if (vector_HuffmanNode_at(vec, i).freq >= vector_HuffmanNode_at(vec, parent).freq) break; swap_nodes(vector_HuffmanNode_atp(vec, i), vector_HuffmanNode_atp(vec, parent)); i = parent; } *out = new; } } void generate_table(HuffmanNode *const node, char **const table, char *text) { if (node->c != '\0') { size_t len = strlen(text); table[node->c] = malloc((len + 1) * sizeof(char)); strncpy(table[node->c], text, len); table[node->c][len] = '\0'; return; } size_t len = strlen(text); char *left_text = malloc((len + 2) * sizeof(char)); char *right_text = malloc((len + 2) * sizeof(char)); strncpy(left_text, text, len); strncpy(right_text, text, len); left_text[len] = '0'; right_text[len] = '1'; left_text[len + 1] = right_text[len + 1] = '\0'; generate_table(node->left, table, left_text); generate_table(node->right, table, right_text); free(left_text); free(right_text); } void entry(char *const message, char **const out_encoded, char ***const out_table, size_t *out_len) { vector_HuffmanNode frequencies; vector_HuffmanNode_init(&frequencies); size_t message_len = strlen(message); count_freqs(message, message_len, &frequencies); HuffmanNode *tree = malloc(sizeof(HuffmanNode)); build_tree(&frequencies, tree); char *text = malloc(sizeof(char)); text = "\0"; char *table[256] = {0}; generate_table(tree, table, text); // encode char output[16384] = {0}; size_t total_len = 0; for (size_t i = 0; i < message_len; ++i) { char c = message[i]; size_t current_len = strlen(table[c]); strncpy(output + total_len, table[c], current_len); total_len += current_len; } output[total_len] = '\0'; vector_HuffmanNode_free(&frequencies); *out_encoded = output; *out_table = table; *out_len = total_len; free_tree(tree); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | #ifndef __VECTOR_H__ #define __VECTOR_H__ #include <assert.h> #include <stddef.h> #include <stdlib.h> #define FORV(i, vec) for (size_t i = 0; i < (vec).len; ++i) #define DEFINE_VEC(T) \ typedef struct { \ T *arr; \ size_t len; \ size_t cap; \ } vector_##T; \ \ void vector_##T##_init(vector_##T *const); \ void vector_##T##_free(vector_##T *const); \ void vector_##T##_push(vector_##T *const, T); \ void vector_##T##_insert(vector_##T *const, T, size_t); \ T vector_##T##_at(vector_##T *const, size_t); \ T *vector_##T##_atp(vector_##T *const, size_t); \ T vector_##T##_pop(vector_##T *const); #define IMPLEMENT_VEC(T) \ void vector_##T##_init(vector_##T *const vec) { \ vec->arr = NULL; \ vec->len = 0; \ vec->cap = 0; \ } \ \ void vector_##T##_free(vector_##T *const vec) { free(vec->arr); } \ \ void vector_##T##_push(vector_##T *const vec, T x) { \ if (vec->len >= vec->cap) { \ vec->cap = (vec->cap ? (vec->cap * 2) : 8); \ vec->arr = realloc(vec->arr, vec->cap * sizeof(T)); \ } \ \ vec->arr[vec->len] = x; \ ++vec->len; \ } \ \ void vector_##T##_insert(vector_##T *const vec, T item, size_t pos) { \ if (pos > vec->len + 1) \ return; \ if (pos == vec->len) { \ vector_##T##_push(vec, item); \ return; \ } \ \ if (vec->len >= vec->cap) { \ vec->cap = (vec->cap ? (vec->cap * 2) : 8); \ vec->arr = realloc(vec->arr, vec->cap * sizeof(T)); \ } \ \ for (size_t i = vec->len - 1; i >= pos; --i) { \ vec->arr[i + 1] = vec->arr[i]; \ } \ vec->arr[pos] = item; \ ++vec->len; \ } \ \ T vector_##T##_at(vector_##T *const vec, size_t idx) { \ return *vector_##T##_atp(vec, idx); \ } \ \ T *vector_##T##_atp(vector_##T *const vec, size_t idx) { \ assert(idx < vec->len); \ \ return &vec->arr[idx]; \ } \ \ T vector_##T##_pop(vector_##T *const vec) { \ T elem = vector_##T##_at(vec, vec->len - 1); \ --vec->len; \ if (vec->cap > 8 && vec->len < vec->cap / 2) { \ vec->cap /= 2; \ vec->arr = (T *)realloc(vec->arr, vec->cap * sizeof(T)); \ } \ \ return elem; \ } #endif // !__VECTOR_H__ |
submitted at
0 likes
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | # solver? # i just,, cant import requests import heapq from math import fabs, sqrt session_token = "" with open('./session.txt', 'r') as f: session_token = f.read() url = "https://codeguessing.gay/extra/game70" headers = {"Content-Type": "application/json"} cookies = {"session": session_token} def distance(p1, p2): return fabs(p1[0] - p2[0]) + fabs(p1[1] - p2[1]) + sqrt((p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2) def map_(func, l): return list(map(func, l)) def diff(path): diff_list = [] for i in range(len(path) - 1): diff_list.append( (path[i + 1][0] - path[i][0], path[i + 1][1] - path[i][1]) ) return diff_list def direction(d): match d: case (-1, 0): return "left" case (1, 0): return "right" case (0, -1): return "up" case (0, 1): return "down" raise RuntimeError("le boobs") def solve(): while True: r = requests.get(url, cookies=cookies) if r.status_code != 200: raise RuntimeError(f"server issue {r.status_code}") resp = r.json() grid = resp['grid'] s = resp['s'] score = resp['score'] print(f"score: {score}") print(f"s: {s}") print(grid, end='\n\n') grid = grid.split('\n') ylimit = len(grid) xlimit = len(grid[0]) x = 0 y = 0 player = (0, 0) bomb = (-1, -1) target = (0, 0) for y, line in enumerate(grid): for x, c in enumerate(line): if c == '@': player = (x, y) elif c == '+': target = (x, y) elif c == '*': bomb = (x, y) # i cant be bothered to implement a good pathfinding algorithm # diff = [target[0] - player[0], target[1] - player[1]] # vert_movement = 0 # hrzt_movement = 0 # # if diff[0] < 0: # hrzt_movement = 1 # diff[0] = -diff[0] # if diff[1] > 0: # vert_movement = 1 # else: # diff[1] = -diff[1] # # dirs = [] # dirs += ['rliegfhtt'[hrzt_movement::2]] * diff[0] # cool trick # dirs += [('down' if vert_movement == 1 else 'up')] * diff[1] # not so cool trick # the code above keeps hitting bombs # this is intentional by lyly's server code # literally 1984 pq = [] d = distance(player, target) heapq.heappush(pq, (d, player)) path = [] while True: if len(pq) == 0: break _, (x, y) = heapq.heappop(pq) path.append((x, y)) if x == target[0] and y == target[1]: break for dx, dy in [(-1, 0), (1, 0), (0, -1), (0, 1)]: _x = x + dx _y = y + dy if (_x == bomb[0] and _y == bomb[1]) or not (_x >= 0 and _x < xlimit) or not (_y >= 0 and _y < ylimit): continue d = distance((_x, _y), target) heapq.heappush(pq, (d, (_x, _y))) path = diff(path) dirs = map_(direction, path) for dir in dirs: r = requests.post(url, json={'dir': dir}, headers=headers, cookies=cookies) if score >= 2024: break solve() |
submitted at
0 likes
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | from math import * # security :D x = eval(input("Target number: ")) print(f"x + 69 = {x + 69}") print(f"x - 69 = {x - 69}") print(f"x / 69 = {x / 69}") print(f"x * 69 = {x * 69}") print(f"x^69 = {x ** 69}") print(f"x^(1 / 69) = {x ** (1 / 69)}") if x != 0: print(f"69 / x = {69 / x}") if x > 0: print(f"log_69(x) = {log(x, 69)}") |
submitted at
0 likes
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | def get_permutation_data(s): out_str = '' out_table = {} i = 0 for c in s: if c not in out_table.keys(): out_table[c] = i i += 1 out_str = out_str + str(out_table[c]) return out_str, out_table def entry(text, all_words): text = text.lower() words = text.split() table = entry_helper(words, all_words, {}) if table is None: return None inv_table = {v: k for k, v in table.items()} inv_table = {ord(k): ord(v) for k, v in inv_table.items()} return text.translate(inv_table) def entry_helper(words, all_words, table): if len(words) == 0: return table word = words[0] rest = words[1:] word_id, word_mapping = get_permutation_data(word) word_inv = {v: k for k, v in word_mapping.items()} for w in all_words: if len(w) != len(word): continue w_id, w_mapping = get_permutation_data(w) if w_id == word_id: w_inv = {v: k for k, v in w_mapping.items()} new_mapping = {} for i in range(len(w_inv.keys())): new_mapping[w_inv[i]] = word_inv[i] for k, v in new_mapping.items(): if k in table.keys(): if table[k] != v: break else: if v in table.values(): break else: old_table = table.copy() for k, v in new_mapping.items(): table[k] = v result = entry_helper(rest, all_words, table) if result is not None: return result table = old_table return None |
submitted at
0 likes
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | def longest_seq(arr, block_size): rev = arr[::-1] block = rev[:block_size] size = 1 while block == rev[block_size * size : block_size * (size + 1)]: size += 1 return size def elem_next(arr): block_len = len(arr) // 2 return max([1] + [ longest_seq(arr, i) for i in range(1, block_len + 1) ]) def entry(n): arr = [1] while len(arr) < n: x = elem_next(arr) arr.append(x) return arr |
submitted at
1 like
1 | https://esolangs.org/wiki/Olus2000 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | "" olus2oOo OLUS2OOO "" "" olus2o0O olus2OoO "ERROR" olus2o0o olus2OoO "3" olus2oO0 olus2oo0 olus2oOo OLUS2ooo olus2o0O 0lus2000! olus200O olus2000! olus20O0 OLUS2OOO olus2o0o olus2OoO "2" olus2oO0 olus2oo0 olus2oOo OLUS2000 olus2o0O "" 0lus2000! olus200O olus2000! olus20O0 OLUS2ooo olus2o0o olus2OoO "1" olus2oO0 olus2oo0 olus2oOo
OLUS200O 0lus2000! olus200O olus2000! olus20O0 OLUS2000 olus2oo0 olus2oOo OLUS20O0 "" olus2OOo olus2Ooo olus2Oo0 olus2OOo olus2Ooo olus2O00 olus2o0O olus2OoO 0lus2000! olus2000 olus2000! "" olus2ooO 0lus2000! olus200O olus2000! olus200o 0lus2000! olus2000 olus2000! olus2Oo0 olus2ooo olus2OoO "" olus2o0o olus2OoO olus2OOo 0lus2000! olus2000
olus2000! olus2Oo0 olus2ooo 0lus2000! olus2000 olus2000! 0lus2000! olus200O olus2000! olus2ooo olus2Oo0 "" olus2OoO olus2oO0 olus2oo0 olus2oOo OLUS20OO olus2Oo0 olus2OOo 0lus2ooo! olus200O olus2000! olus2O0O "" olus2oOO olus2OoO olus2Oo0 OLUS20O0 olus2Oo0 "" olus2OOo 0lus2ooo! olus200O olus2000! olus2O0O olus2oO0 olus2OoO olus2Oo0 olus2OoO olus2OoO ""
olus2oo0 olus2oOo OLUS20Oo OLUS20OO olus2OOO olus2o00 olus2oOO olus2Oo0 olus2OOo OLUS200O "" 0lus2000! olus2000 olus2000! olus2Oo0 olus2ooo 0lus2000! olus200O olus2000! olus20O0 olus2oO0 "\n" olus2OoO "" "" 0lus2ooo! olus200O olus2000! olus2OOO 0lus2000! olus2000 olus2000! olus2oo0 0lus2ooo! olus200O olus2000! 0lus2000! olus200O olus2000! 0lus2000! olus2000
olus2000! "" 0lus2000! olus200O olus2000! "" OLUS200O " \n" "" 0lus2000! olus200O olus2000! olus2oOO "" olus2OoO OLUS20Oo 0lus2000! olus200O olus2000! olus2oO0 olus2000 Olus2000! olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 Olus2000!!
olus2000 " " olus2000 olus2000 "" olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 " " olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 Olus2000! olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 Olus2000!!
olus2000 olus2000 "" olus2000 olus2000 "" olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 " " olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 Olus2000! olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 Olus2000!!
olus2000 olus2000 "" olus2000 olus2000 "" olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 " " olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 Olus2000! olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 Olus2000!!
olus2000 olus2000 "" olus2000 olus2000 "" olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 " " olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 Olus2000! olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 Olus2000!!
olus2000 olus2000 "" olus2000 olus2000 "" olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 " " olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 Olus2000! olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 Olus2000!!
olus2000 olus2000 "" olus2000 olus2000 "" olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 " " olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 Olus2000! olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 Olus2000!!
olus2000 olus2000 "" olus2000 olus2000 "" olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 " " olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 " " olus2000 olus2000 olus2000 Olus2000! olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 Olus2000!!
olus2000 olus2000 "" olus2000 olus2000 "" olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 " " olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 " " olus2000 olus2000 olus2000 Olus2000! olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 Olus2000!!
olus2000 olus2000 "" olus2000 olus2000 "" olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 " " olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 " " olus2000 olus2000 olus2000 Olus2000! olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 Olus2000!!
olus2000 olus2000 "" olus2000 olus2000 "" olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 " " olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 " " olus2000 olus2000 olus2000 Olus2000! olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 Olus2000!!
olus2000 olus2000 "" olus2000 olus2000 "" olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 " " olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 " " olus2000 olus2000 olus2000 Olus2000! olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 Olus2000!!
olus2000 olus2000 "" olus2000 olus2000 "" olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 " " olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 Olus2000! olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 Olus2000!!
olus2000 olus2000 "" olus2000 olus2000 "" olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 " " olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 Olus2000! olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 Olus2000!!
olus2000 olus2000 "" olus2000 olus2000 "" olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 " " olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 Olus2000! olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 Olus2000!!
olus2000 olus2000 "" olus2000 olus2000 "" olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 " " olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 Olus2000! olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 Olus2000!!
olus2000 olus2000 "" olus2000 olus2000 "" olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 " " olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 Olus2000! olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 Olus2000!!
olus2000 " " olus2000 olus2000 "" olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 " " olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 " " olus2000 olus2000 olus2000 Olus2000! olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 Olus2000!!
Olus2000! "" 0lus2000! olus200O Olus2000! "" olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 " " olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 " " olus2000 olus2000 olus2000 Olus2000! olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 Olus2000!!
olus2oo0 olus2oOo OLUS20Oo OLUS20OO olus2OOO olus2o00 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 " " olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 " " olus2000 olus2000 Olus2000! olus2000 Olus2000! olus2000 Olus2000! Olus2000! olus2000 olus2000 olus2000 Olus2000! Olus2000! olus2000 Olus2000!!
Olus2000! olus2Oo0 olus2ooo 0lus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 "" "" "" olus2000 olus2000 " " olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 " " olus2000 olus2000 Olus2000! olus2000 Olus2000! olus2000 Olus2000! Olus2000! olus2000 olus2000 olus2000 Olus2000! Olus2000! olus2000 Olus2000!!
OLUS200O 0lus2000! olus200O Olus2000! olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 "" olus2000 olus2000 " " olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 " " olus2000 olus2000 Olus2000! olus2000 Olus2000! olus2000 Olus2000! Olus2000! olus2000 olus2000 olus2000 Olus2000! Olus2000! olus2000 Olus2000!!
"" olus2oOo OLUS2OOO "" "" olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 olus2000 " " olus2000 olus2000 Olus2000! olus2000 Olus2000! olus2000 Olus2000! Olus2000! olus2000 olus2000 olus2000 Olus2000! Olus2000! olus2000 olus2000!
|
submitted at
0 likes
1 | # All functions are no ops
|
submitted at
0 likes
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 | module CommandParser ( Command(..), Action(..), Parser, parseCommand, currentLine, lastLine, runParser ) where import Control.Applicative import Data.Char (isNumber) data Command = Plus Int | Minus Int | File | SetFile FilePath | Write | WriteFile FilePath | Quit | ForceQuit | Slice { getSliceBegin :: Int, getSliceEnd :: Int, getSliceAction :: Action} | Num Int | LastError deriving (Show, Eq) data Action = Print | LineNumber | Line | Append | Insert | Change | Delete deriving (Show, Eq) newtype Parser a = Parser { runParser :: String -> Maybe (String, a) } instance Functor Parser where fmap :: (a -> b) -> Parser a -> Parser b fmap f (Parser p) = Parser $ \s -> case p s of Nothing -> Nothing (Just (rest, x)) -> Just (rest, f x) instance Applicative Parser where pure :: a -> Parser a pure x = Parser $ \s -> Just (s, x) (<*>) :: Parser (a -> b) -> Parser a -> Parser b (Parser pf) <*> (Parser pa) = Parser $ \s -> do (rest, f) <- pf s (rest', a) <- pa rest return (rest', f a) instance Alternative Parser where empty :: Parser a empty = Parser $ const Nothing (<|>) :: Parser a -> Parser a -> Parser a (Parser p1) <|> (Parser p2) = Parser $ \s -> p1 s <|> p2 s parseChar :: Char -> Parser Char parseChar c = Parser f where f [] = Nothing f (x:xs) | x == c = Just (xs, c) | otherwise = Nothing parseCommandHelper :: Char -> Command -> (Char -> Command) parseCommandHelper c cmd = \ch -> if ch == c then cmd else undefined parseActionHelper :: Char -> Action -> (Char -> Action) parseActionHelper c act = \ch -> if ch == c then act else undefined currentLine :: Int currentLine = -2 lastLine :: Int lastLine = -1 parseQuit :: Parser Command parseQuit = parseCommandHelper 'q' Quit <$> parseChar 'q' parseForceQuit :: Parser Command parseForceQuit = parseCommandHelper 'Q' ForceQuit <$> parseChar 'Q' parseLastError :: Parser Command parseLastError = parseCommandHelper 'h' LastError <$> parseChar 'h' parseWriteFile :: Parser Command parseWriteFile = f <$> (parseChar 'w' *> parseWs *> parseNonWs) where f [] = Write f str = WriteFile str parseSetFile :: Parser Command parseSetFile = f <$> (parseChar 'f' *> parseWs *> parseNonWs) where f [] = File f str = SetFile str parsePlusNum :: Parser Command parsePlusNum = Plus <$> (parseChar '+' *> parseWs *> parseNumber) parsePlusses :: Parser Command parsePlusses = Plus . (+1) . length <$> (parseChar '+' *> spanP (=='+')) parseMinusNum :: Parser Command parseMinusNum = Minus <$> (parseChar '-' *> parseWs *> parseNumber) parseMinuses :: Parser Command parseMinuses = Minus . (+1) . length <$> (parseChar '-' *> spanP (=='-')) parseComma :: Parser Command parseComma = Parser $ \s -> do (rest, num1) <- runParser (parseNumber <|> pure 1) s (rest', _) <- runParser (parseWs *> parseChar ',') rest (rest'', num2) <- runParser (parseNumber <|> pure lastLine) rest' (rest''', act) <- runParser (parseWs *> parseAction) rest'' return (rest''', Slice num1 num2 act) parseSemicolon :: Parser Command parseSemicolon = Parser $ \s -> do (rest, num1) <- runParser (parseNumber <|> pure currentLine) s (rest', _) <- runParser (parseWs *> parseChar ';') rest (rest'', num2) <- runParser (parseNumber <|> pure lastLine) rest' (rest''', act) <- runParser (parseWs *> parseAction) rest'' return (rest''', Slice num1 num2 act) parseSingleSlice :: Parser Command parseSingleSlice = Parser $ \s -> do (rest, num) <- runParser parseNumber s (rest', act) <- runParser (parseWs *> parseAction) rest return (rest', Slice num num act) parseNumberCommand :: Parser Command parseNumberCommand = Num <$> parseNumber parsePrint :: Parser Action parsePrint = parseActionHelper 'p' Print <$> parseChar 'p' parseDelete :: Parser Action parseDelete = parseActionHelper 'd' Delete <$> parseChar 'd' parseLine :: Parser Action parseLine = parseActionHelper 'l' Line <$> parseChar 'l' parseAppend :: Parser Action parseAppend = parseActionHelper 'a' Append <$> parseChar 'a' parseInsert :: Parser Action parseInsert = parseActionHelper 'i' Insert <$> parseChar 'i' parseChange :: Parser Action parseChange = parseActionHelper 'c' Change <$> parseChar 'c' parseLineNumber :: Parser Action parseLineNumber = parseActionHelper 'n' LineNumber <$> parseChar 'n' stringToInt :: String -> Int stringToInt s | s == "$" = lastLine | s == "." = currentLine | otherwise = read s isNumberPred :: Char -> Bool isNumberPred c | c == '.' = True | c == '$' = True | otherwise = isNumber c parseNumber :: Parser Int parseNumber = Parser $ \s -> case span isNumberPred s of ("", _) -> Nothing (digits, rest) -> Just (rest, stringToInt digits) spanP :: (Char -> Bool) -> Parser String spanP f = Parser $ \input -> do let (str, rest) = span f input return (rest, str) isWhiteSpace :: Char -> Bool isWhiteSpace c | c == ' ' = True | c == '\t' = True | otherwise = False parseWs :: Parser String parseWs = spanP isWhiteSpace parseNonWs :: Parser String parseNonWs = spanP (not . isWhiteSpace) parseAction :: Parser Action parseAction = parsePrint <|> parseDelete <|> parseLine <|> parseAppend <|> parseInsert <|> parseChange <|> parseLineNumber makeSlice :: Action -> Command makeSlice = Slice currentLine currentLine parseActionCommand :: Parser Command parseActionCommand = makeSlice <$> parseAction parseCommand :: Parser Command parseCommand = parseWs *> ( parseQuit <|> parseForceQuit <|> parseActionCommand <|> parseWriteFile <|> parseSetFile <|> parsePlusNum <|> parsePlusses <|> parseMinusNum <|> parseMinuses <|> parseComma <|> parseSemicolon <|> parseSingleSlice <|> parseNumberCommand <|> parseLastError ) <* parseWs |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | module Main where import qualified CommandParser as C import qualified Program as P import qualified Control.Monad.Trans.State as ST import System.Environment import System.Directory runProgram :: P.Program -> IO () runProgram p@(P.Program buf cl fname chg qs lastError) = do line <- getLine let command = C.runParser C.parseCommand line case command of Nothing -> do putStrLn "?" runProgram $ P.Program buf cl fname chg qs "Invalid command suffix" (Just (rest, cmd)) -> do if null rest then do (_, next) <- ST.runStateT (P.runCommand cmd) p if P.getQuitState next == P.QuitForcefully then return () else runProgram next else do putStrLn "?" runProgram $ P.Program buf cl fname chg qs "Invalid command suffix" main :: IO () main = do args <- getArgs if null args then runProgram P.defaultProgram else do let fname = head args e <- doesFileExist fname if e then do content <- readFile fname let bytes = length content let buf = lines content print bytes runProgram $ P.Program buf (length buf) (Just fname) False P.NoQuit "" else do putStr fname putStrLn " No such file or directory" runProgram $ P.Program [] 0 Nothing False P.NoQuit "Cannot open input file" |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 | module Program where import CommandParser qualified as C import Control.Monad.State import System.IO import qualified Control.Monad.Trans.State as ST data QuitState = NoQuit | HasChanges | QuitForcefully deriving (Show, Eq, Enum) data Program = Program { getBuffer :: [String], getCurrentLine :: Int, getFilename :: Maybe FilePath, hasUnsavedchanges :: Bool, getQuitState :: QuitState, getLastError :: String } defaultProgram :: Program defaultProgram = Program [] 0 Nothing False NoQuit "" type ProgramStateT = ST.StateT Program IO sliceToIndex :: Program -> Int -> Int sliceToIndex (Program buf cl _ _ _ _) x | x == C.currentLine = cl - 1 | x == C.lastLine = length buf - 1 | otherwise = x - 1 slicesToIndices :: Program -> Int -> Int -> (Int, Int) slicesToIndices p x y = (sliceToIndex p x, sliceToIndex p y) sliceList :: [a] -> Int -> Int -> [a] sliceList l beg end = take (end - beg + 1) $ drop beg l takeInput :: IO String takeInput = do input <- getLine if input /= "." then do i2 <- takeInput return $ input ++ "\n" ++ i2 else return "" runCommand :: C.Command -> ProgramStateT () runCommand (C.Plus n) = do (Program buf cl fname chg qs lastError) <- get if (cl + n) > length buf then do put $ Program buf cl fname chg NoQuit "Invalid address" liftIO $ putStrLn "?" else do put $ Program buf (cl + n) fname chg NoQuit lastError liftIO . putStrLn $ buf !! (cl + n) runCommand (C.Minus n) = do (Program buf cl fname chg qs lastError) <- get if (cl - n) < 1 then do put $ Program buf cl fname chg NoQuit "Invalid address" liftIO $ putStrLn "?" else do put $ Program buf (cl - n) fname chg NoQuit lastError liftIO . putStrLn $ buf !! (cl - n) runCommand C.File = do p@(Program buf cl fname chg qs lastError) <- get case fname of Nothing -> do put $ Program buf cl fname chg NoQuit "No current filename" liftIO $ putStrLn "?" (Just f) -> do put $ Program buf cl fname chg NoQuit lastError liftIO $ putStrLn f runCommand (C.SetFile path) = do (Program buf cl fname chg qs lastError) <- get put $ Program buf cl (Just path) chg NoQuit lastError liftIO $ putStrLn path runCommand C.Write = do (Program buf cl fname chg qs lastError) <- get case fname of Nothing -> do put $ Program buf cl fname chg NoQuit "No current filename" liftIO $ putStrLn "?" (Just filename) -> do let str = foldr (\a acc -> a ++ "\n" ++ acc) "" buf let bytes = length str liftIO $ do writeFile filename str print bytes put $ Program buf cl fname False NoQuit lastError runCommand (C.WriteFile path) = do (Program buf cl fname chg qs lastError) <- get put $ Program buf cl (Just path) chg NoQuit lastError runCommand C.Write runCommand C.Quit = do (Program buf cl fname chg qs lastError) <- get if qs == HasChanges then put $ Program buf cl fname chg QuitForcefully lastError else if chg then do liftIO $ putStrLn "?" put $ Program buf cl fname True HasChanges "Warning: buffer modified" else do put $ Program buf cl fname True QuitForcefully lastError runCommand C.ForceQuit = do (Program buf cl fname chg qs lastError) <- get put $ Program buf cl fname chg QuitForcefully lastError runCommand (C.Slice beg end C.Print) = do p@(Program buf cl fname chg qs lastError) <- get let (sbeg, send) = slicesToIndices p beg end if sbeg > send || send >= length buf then do put $ Program buf cl fname chg NoQuit "Invalid address" liftIO $ putStrLn "?" else do put $ Program buf (send + 1) fname chg NoQuit lastError liftIO . mapM_ putStrLn $ sliceList buf sbeg send runCommand (C.Slice beg end C.LineNumber) = do p@(Program buf cl fname chg qs lastError) <- get let (sbeg, send) = slicesToIndices p beg end if sbeg > send || send >= length buf then do put $ Program buf cl fname chg NoQuit "Invalid address" liftIO $ putStrLn "?" else do put $ Program buf (send + 1) fname chg NoQuit lastError liftIO $ mapM_ putStrLn $ enumerateLines sbeg send $ sliceList buf sbeg send where enumerateLines _ _ [] = [] enumerateLines sbeg send (x:xs) = (show (sbeg + 1) ++ "\t"++x):enumerateLines (sbeg + 1) send xs runCommand (C.Slice beg end C.Line) = do p@(Program buf cl fname chg qs lastError) <- get let (sbeg, send) = slicesToIndices p beg end if sbeg > send || send >= length buf then do put $ Program buf cl fname chg NoQuit "Invalid address" liftIO $ putStrLn "?" else do put $ Program buf (send + 1) fname chg NoQuit lastError liftIO $ mapM_ (putStrLn . (++"$")) $ sliceList buf sbeg send runCommand (C.Slice beg end C.Append) = do p@(Program buf cl fname chg qs lastError) <- get let (sbeg, send) = slicesToIndices p beg end if sbeg > send || send >= length buf then do put $ Program buf cl fname chg NoQuit "Invalid address" liftIO $ putStrLn "?" else do inputLines <- liftIO takeInput let newText = lines inputLines let newBuf = take (send + 1) buf ++ newText ++ drop (send + 1) buf put $ Program newBuf (send + 1 + length newText) fname True NoQuit lastError runCommand (C.Slice beg end C.Insert) = do p@(Program buf cl fname chg qs lastError) <- get let (sbeg, send) = slicesToIndices p beg end if sbeg > send || send >= length buf then do put $ Program buf cl fname chg NoQuit "Invalid address" liftIO $ putStrLn "?" else do inputLines <- liftIO takeInput let newText = lines inputLines let newBuf = take send buf ++ newText ++ drop send buf put $ Program newBuf (send + 1) fname True NoQuit lastError runCommand (C.Slice beg end C.Change) = do runCommand (C.Slice beg end C.Delete) runCommand (C.Slice beg beg C.Insert) runCommand (C.Slice beg end C.Delete) = do p@(Program buf cl fname chg NoQuit lastError) <- get let (sbeg, send) = slicesToIndices p beg end if sbeg > send || send >= length buf then do put $ Program buf cl fname chg NoQuit "Invalid address" liftIO $ putStrLn "?" else do put $ Program (take sbeg buf ++ drop (send + 1) buf) (sbeg + 1) fname True NoQuit lastError runCommand (C.Num n) = do p@(Program buf cl fname chg qs lastError) <- get let sn = sliceToIndex p n if (sn < 0) || (sn >= length buf) then do put $ Program buf cl fname chg NoQuit "Invalid address" liftIO $ putStrLn "?" else do put $ Program buf (sn + 1) fname chg NoQuit lastError liftIO . putStrLn $ buf !! sn runCommand C.LastError = do (Program buf cl fname chg qs lastError) <- get if null lastError then return () else do liftIO $ putStrLn lastError put $ Program buf cl fname chg NoQuit lastError |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | cabal-version: 3.0
name: subsed
version: 0.1.0.0
description: A subset of ed
license: NONE
build-type: Simple
common warnings
ghc-options: -Wall
executable subsed
import: warnings
main-is: Main.hs
other-modules: CommandParser
, Program
build-depends: base ^>=4.17.2.1
, mtl ^>= 2.2.2
, transformers ^>= 0.5.6.2
, directory ^>= 1.3.7.1
hs-source-dirs: app
default-language: GHC2021
|
submitted at
0 likes
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | import random for _ in range(9): input() P = 0.2 M = 0.45 I = 0.35 M_4 = M / 4 I_4 = I / 4 l = ['P', 'M\nU', 'M\nD', 'M\nL', 'M\nR', 'I\nU', 'I\nD', 'I\nL', 'I\nR'] w = [P, M_4, M_4, M_4, M_4, I_4, I_4, I_4, I_4] print(*random.choices(l, w, k=1)) |
submitted at
2 likes
no im really sorry
actually, i'm the one who should be apologizing more :bottom:
1 2 3 4 5 6 7 8 9 10 | def imsorry(really, sorry): i = sorry while really[i] == 0 and i >= 0: really[i] = 2 i -= 1 i = sorry + 1 while really[i] == 0 and i < len(really): really[i] = 2 i += 1 return really |
submitted at
0 likes
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 | local function gen_array(n, x) local l = {} for i=1,n do l[i] = x end return l end local function clone_table(original) local copy = {} for key, value in pairs(original) do if type(value) == "table" then copy[key] = clone_table(value) else copy[key] = value end end return copy end local function push_table(dest, src) for i=1,#src do dest[#dest + 1] = src[i] end end local MAX_DEPTH = 10 local finished_interpreters = {} local new_interpreters = {} local function make_interpreter() local interpreter = { stack = {}, random_access_memory = gen_array(30000, 0), depth = 0, bounds = {}, loops = {}, idx = 1, has_finished = false, coe = 1.0, code = '', } function interpreter.pop_stack(i) if #i.stack == 0 then return 0 end local x = i.stack[#i.stack] table.remove(i.stack) return x end function interpreter.push_stack(i, x) table.insert(i.stack, x) end function interpreter.clone(i, upto) if i.depth >= MAX_DEPTH then return {} end local clones = {} for idx=0,upto do local new_interpreter = clone_table(i) new_interpreter.depth = i.depth + 1 new_interpreter.coe = i.coe / (upto + 1) new_interpreter:push_stack(idx) table.insert(clones, new_interpreter) end return clones end function interpreter.step(i) if i.has_finished then return false end if i.idx > #i.code or i.depth >= MAX_DEPTH then table.insert(finished_interpreters, i) i.has_finished = true return false end local chr = string.sub(i.code, i.idx, i.idx) i.idx = i.idx + 1 if chr == '#' then i:push_stack(0) elseif chr == '+' then local x = i:pop_stack() i:push_stack(x + 1) elseif chr == '@' then local address = i:pop_stack() + 1 i:push_stack(i.random_access_memory[address]) elseif chr == '!' then local address = i:pop_stack() + 1 local value = i:pop_stack() i.random_access_memory[address] = value elseif chr == '?' then local number = i:pop_stack() push_table(new_interpreters, i:clone(number)) return false elseif chr == '[' then local bound = i:pop_stack() table.insert(i.bounds, bound) table.insert(i.loops, i.idx) elseif chr == '|' then local condition = i:pop_stack() if condition == 0 or i.bounds[#i.bounds] == 0 then table.remove(i.loops, #i.loops) table.remove(i.bounds, #i.bounds) local lc = 0 while true do local char = string.sub(i.code, i.idx, i.idx) if char == '[' then lc = lc + 1 elseif char == ']' then if lc == 0 then break end lc = lc - 1 end i.idx = i.idx + 1 end i.idx = i.idx + 1 end elseif chr == ']' then i.bounds[#i.bounds] = i.bounds[#i.bounds] - 1 i.idx = i.loops[#i.loops] end return true end return interpreter end function entry(code) local interpreter = make_interpreter() interpreter.code = code local interpreters = {interpreter} finished_interpreters = {} new_interpreters = {} local stepped = true while stepped or #new_interpreters ~= 0 do new_interpreters = {} stepped = false local idx = 1 while idx <= #interpreters do local i = interpreters[idx] if i:step() == false then table.remove(interpreters, idx) else stepped = true idx = idx + 1 end end push_table(interpreters, new_interpreters) end local outputs = {} for _,i in ipairs(finished_interpreters) do local top = i:pop_stack() if outputs[top] == nil then outputs[top] = i.coe else outputs[top] = outputs[top] + i.coe end end local most_probable_outcomes = {} local high = 0 for k,v in pairs(outputs) do if v > high then most_probable_outcomes = {k} high = v elseif v == high then table.insert(most_probable_outcomes, k) end end return most_probable_outcomes end |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 | local function gen_array(n, x) local l = {} for i=1,n do l[i] = x end return l end local function clone_table(original) local copy = {} for key, value in pairs(original) do if type(value) == "table" then copy[key] = clone_table(value) else copy[key] = value end end return copy end local interpreter = { stack = {}, random_access_memory = gen_array(30000, 0), pop_stack = function (i) if #i.stack == 0 then return 0 end local x = i.stack[#i.stack] table.remove(i.stack) return x end, push_stack = function (i, x) table.insert(i.stack, x) end, execute = function (i, stmts) for _, v in ipairs(stmts) do v:run(i) end end, clone = function (i, upto) local clones = {} for idx=0,upto do local new_interpreter = clone_table(i) new_interpreter:push_stack(idx) table.insert(clones, new_interpreter) end return clones end } local function instruction_new(exec) return { run = exec, } end local function loop_new(c, b) return { cond = c, body = b, run = function (self, i) local bound = i:pop_stack() while bound ~= 0 do i:execute(self.cond) local num = i:pop_stack() if num == 0 or bound == 0 then break end i:execute(self.body) bound = bound - 1 end end, } end local instructions = { h = instruction_new(function (_, i) i:push_stack(0) end), p = instruction_new(function (_, i) local x = i:pop_stack() i:push_stack(x + 1) end), a = instruction_new(function (_, i) local address = i:pop_stack() + 1 i:push_stack(i.random_access_memory[address]) end), e = instruction_new(function (_, i) local address = i:pop_stack() + 1 local value = i:pop_stack() i.random_access_memory[address] = value end), q = instruction_new(function (_, i) local number = i:pop_stack() i:push_stack(math.random(number + 1) - 1) end), } local function parse(code, idx) local stmts = {} while idx <= #code do local char = string.sub(code, idx, idx) if char == '#' then table.insert(stmts, instructions.h) elseif char == '+' then table.insert(stmts, instructions.p) elseif char == '@' then table.insert(stmts, instructions.a) elseif char == '!' then table.insert(stmts, instructions.e) elseif char == '?' then table.insert(stmts, instructions.q) elseif char == '|' or char == ']' then return stmts, idx elseif char == '[' then local body local condition condition, idx = parse(code, idx + 1) char = string.sub(code, idx, idx) if char ~= '|' then print("Expected '|', got '"..char.."'") os.exit(1) end body, idx = parse(code, idx + 1) char = string.sub(code, idx, idx) if char ~= ']' then print("Expected ']', got '"..char.."'") os.exit(1) end table.insert(stmts, loop_new(condition, body)) end idx = idx + 1 end return stmts, idx end function entry(code) local parsed = parse(code, 1) local N = 10000 local dict = {} for _=1,N do interpreter:execute(parsed) local outcome = interpreter:pop_stack() if dict[outcome] == nil then dict[outcome] = 1 else dict[outcome] = dict[outcome] + 1 end end local max = 0 local max_k = 0 for k,v in pairs(dict) do if v > max then max_k = k max = v end end return max_k end |
0 likes
1 | ↓?κ⍒⏚⋆ⓏDⒽ⍕¯qI⌈⍳⁰δc⟃⍄ϸ⍹γ∧⏦⊗⍣⍙⊂PGB⁴⍬⍲⌷④⍟Ⓓ⍱ⒺⒾ8υ⌊⊑ |
submitted at
1 like
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | #include <stdio.h> #include <time.h> #include <math.h> #include "activation.h" #include "loss.h" #include "matrix.h" #include "model.h" #include "optimizer.h" #include "sgd.h" #include "util.h" int main(int argc, char** argv) { srand(time(NULL)); Activation* act_id = activation_init("identity", identity, one); Activation* act_relu = activation_init("relu", relu, relu_derivative); Activation* act_softmax = activation_init("softmax", softmax, softmax_derivative); Activation* act_sigmoid = activation_init("sigmoid", sigmoid, sigmoid_derivative); SGD* sgd = sgd_init("SGD", 0.001, 0, 1); const size_t BATCH_SIZE = 16; // if you are lucky it gets up to 60% accuracy, but it is 45-50% accurate most of the time. // which is terrible for a neural network, perhaps ive done something wrong in the implementation. // it somehow got 85% accuracy once. Model* m = model_init(); model_add_dense(m, 784, act_relu, 0.33); model_add_dense(m, 128, act_relu, 0.33); model_add_dense(m, 64, act_softmax, 0); model_add_dense(m, 10, act_id, 0); model_compile(m, (Optimizer*)sgd, mse, mse_derivative, BATCH_SIZE); const size_t example_count = 60000; const size_t test_count = 10000; const size_t pixel_count = 784; const size_t epochs = 300; Matrix* in = matrix_init(example_count, pixel_count); Matrix* test_in = matrix_init(test_count, pixel_count); Matrix* out = matrix_init(example_count, 1); Matrix* test_out = matrix_init(test_count, 1); FILE* mnist = fopen("mnist_train.csv", "r"); for(size_t y = 0; y < example_count; ++y) { fscanf(mnist, "%lf", matrix_atp(out, y, 0)); for(size_t x = 0; x < pixel_count; ++x) { fscanf(mnist, "%lf", matrix_atp(in, y, x)); *matrix_atp(in, y, x) /= 255.0; } } fclose(mnist); printf("Loaded the MNIST dataset!\n"); FILE* mnist_test = fopen("mnist_test.csv", "r"); for(size_t y = 0; y < test_count; ++y) { fscanf(mnist_test, "%lf", matrix_atp(test_out, y, 0)); for(size_t x = 0; x < pixel_count; ++x) { fscanf(mnist, "%lf", matrix_atp(test_in, y, x)); *matrix_atp(test_in, y, x) /= 255.0; } } fclose(mnist_test); printf("Loaded tests!\n"); model_fit(m, in, out, epochs); printf("Fit done!\n"); Matrix* prediction = matrix_init(test_count, 10); size_t accuracy = 0; model_predict(m, test_in, prediction); for(size_t y = 0; y < test_count; ++y) { if(matrix_at(prediction, y, matrix_at(test_out, y, 0)) > 0.5) { ++accuracy; } } matrix_free(prediction); printf("Model accuracy: %lf\n", (cell_t)accuracy / (cell_t)test_count); model_free(m); matrix_free(test_in); matrix_free(out); matrix_free(test_out); activation_free(act_id); activation_free(act_relu); activation_free(act_softmax); activation_free(act_sigmoid); sgd->base.free((Optimizer*)sgd); return 0; } |
1 | https://gofile.io/d/WHH7HK |
submitted at
1 like
1 2 3 4 5 6 7 8 9 10 11 12 | #include "olus2000.h" HELLO I AM OLUS2000 AND I WROTE THIS ENTRY. SO MAKE YOUR GUESSES WITH THAT IN MIND. YOU DON/*'*/T BELIEVE ME? BUT WHY? HAVE I LIED TO YOU BEFORE? PLEASE, JUST DRAG MY NICK TO THE APPROPRIATE PLACE. YOU WOULDN/*'*/T WANT TO SEE ME SAD WOULD YOU? YOU STILL DONT BELIEVE ME? FINE... MY FULL NAME IS ALEKSANDER SABAK. I STUDIED COMPUTER SCIENCE IN WARSAW UNIVERSITY OF TECHNOLOGY. I LOVE PICO8, ESOLANGS, AND CONCATANATIVE PROGRAMMING. UMM... OH YEAH AND ALSO TOKI PONA. UHH... IM FROM POLAND. YOU PROBABLY KNOW IT ALREADY, I JUST WANTED TO POINT IT OUT... YOU NOW BELIEVE ME, RIGHT? :PLEADING_FACE: I SWEAR, THIS CODE REALLY DOES BELONG TO ME, I AM NOT IMPERSONATING HIM. AND BY HIM, I MEAN ME OF COURSE. IVE GIVEN A LOT OF PERSONAL DETAILS SO YOU ARE CONVINCED, R-RIGHT? HAVE A NICE CODE GUESSING |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | #define I #define ESOLANGS UV Hs){YM l=UP(Hs);YM qq #define STILL 0:0;TC(!(e->s-124)){TC(T)ep(ME[0],to);QH;} #define IM ){}THAT pt(P*p){TC(pe(p))QH 0;TC(!ph(p, #define TJ while #define IT #define SM break #define GN(i,s,m)UQ(i,s,m,1) #define PLACE ME=a;e->sa*=2;}ME[T]=s;++T;}EA th(){B b;b #define WANT )QH;ek(ME[j]);GN(i,j,T-1){ #define OO free #define HAVE 0:0; #define PICO8 QH 0;QH(!(c-pu(p)));}YM ph(P*p #define AM #define MY #define DETAILS EA gt(){b. #define ES exit #include <string.h> #define YOU #define HELLO WD GF #define WD typedef #define SAD [i]=ME[i+1];}ME[T-1]=0;T--;} #define ZC memset #define RIGHT (THAT)ME);THAT a=0;TJ((a=pt(p))){TJ(!(pm(p,"*")-1))a->s=42;0 #define NICK {THAT*a=OL(JK(THAT)*e->sa*2);GN(i,0,T){ #define UQ(i,s,m,a)for(IZ i=s;i<m;i+=a) #define NOW ){}THAT pk(P*p){THAT e=ei(95,2);YM qq #define YEAH QH p->st[p->c-1];}QP pa #define IMPERSONATING TT(!(c->st-2)){YM r=0;GN(j,0,c->ns){THAT cc=c->se[j];B b;b #define WANTED "Unclosed\'(\'!");QH e;}LV:{TC((cc-41)&&(cc-124)) #define UHH x=0;pa(p);}QH c;}EA qo(YM n, #define A #define PONA YM c=ph(p,Hs);TC(c){B b;b #define BELONG ef(THAT e){TC(e->s-124)QH e;ca((THAT) #define CONVINCED EA yaf(IZ x #define COMPUTER ){PI(UD,"%s",m);pf(p); #define KNOW TC(pa(p)-93)pn(p,"Character classes must be empty!"); #define UP strlen #define NICE }} EA bo(){P*p;THAT x;x=( #define WITH }P; #define PLEADING_FACE es(e,a);}0? #define JK sizeof #define WHY ek(THAT e){ME #define UNIVERSITY pu(P*p){TC(pe(p))QH 0;QH #define AND #define BELIEVE = 0;ca((THAT) #define CONCATANATIVE pp;GN(i,0,l){TC(pc(p,Hs[i]))QH 1;} #define TC if #define DON x=0;E*e=OL(JK(E));e->s=c;e->sa=1; #define FROM "\\*|()[]")){QP c=pa(p);TC(!c)QH 0;QH #define YM int #define THAT E* #define MIND ei(QP c,YM st){b #define THE #define QH return #include <stdlib.h> #define OLUS2000 E{QP s; #define PROBABLY x){BL 92:{QH ei(pa(p),0);}BL 91:{ #define IS #define WOULD EA ep(THAT e,QP*to){IZ t=0;t #define UV QP const* #define ENTRY }E;WD GF{YM x;}B;B b;EA ca(THAT x, THAT y){b #define BYE }} #define BY x=0;TC(!(cc->st-1)){sr(e,i);r=1;SM;}TC(!(cc->s-42)){ek(cc);YM foo #define IZ size_t #define GIVEN QP*o=OL(JK(QP)*BM);ZC(o,0,BM);ep(p->x,o);pf(p);QH o;} #define IN #define DRAG THAT y){}EA es(THAT e,THAT s){TC(!(T+1-e->sa)) #define THIS #define BUT (THAT)ME:(THAT)ME,(THAT)ME);ME=OL(JK(THAT));e->se[0]=0;e->st=st;QH e;}EA #define MAKE UV st;IZ l; #define BM 1024 #define ME e->se #define ARE } GN; #define CODE 0);THAT l=pk(p);es(x,l);TJ(pm(p,"|")) #define TL strncat #define T e->ns #define ALSO (P*p){QP c=pu(p);++p->c; #define OF #define BEFORE ek(ME[i]);}OO(ME);IZ wm;wm #define PROGRAMMING QH 0;}EA uw(){B b;b #define WROTE GF THAT*se;IZ ns;IZ sa;YM st; #define DOES THAT pr(P*p){p->x=pp(p);QH p->x;}THAT #define TO #define APPROPRIATE a[i]=ME[i];}OO(ME); #define FULL ){}P*pi(UV s){P*p=OL(JK(P)); #define LIED GN(i,0,T){ #define UMM x=0;}EA am(YM n, #define OH ){}QP pv(P*p){TC(!(p->c-0)||(p->c>p->l))QH 0; #define LV default #define FINE (THAT)0:(THAT)0, 0);}THAT pp(P*p);EA ox(IZ n, #define PLEASE 0:0;}EA db(THAT x #define POLAND ei(c,0);}QP cc=pa(p);B b;b.x=0;XH(cc+b #define ROUND #define GUESSING {}} #define ALREADY QH ei(71,1);}BL 40:{THAT e=pp(p);TC(pa(p)-41)pn(p #define R YM y){THAT e;P*p; x=((THAT)x #include <stdio.h> #define XH switch #define MEAN bar;c->se[j]=ei(95,2);}}TC(r)GW;}TC(!(c->s-42)){ek( #define SCIENCE ES(1);}YM pe(P* p){ #define HIM #define NAME p->st=s;p->c=0;p->l=UP(s);p->x=0;QH p;} #define UD stderr #define LOVE x=0;}YM pc(P*p,QP c){TC(pe(p)) #define SEE #define SWEAR 0;QH e;}THAT pp(P*p){THAT x=ei(124 #define GUESSES THAT x; #define EA void #define GW continue #define PERSONAL #define POINT pn(p,"Unexpected Character");p->c-=1;QH 0;}}QH 0;} #define OUT EA jr(int s, #define LOT #define QP char #define STUDIED x=0;}EA pn(P*p,UV m #define TT else TC #define IVE x=0;} QP*entry(UV r){P*p=pi(r);pr(p);ef(p->x); #define BL case #define NOT (THAT)ME);UQ(i,0,T,0){THAT c=ME[i];TC(!(c->s-124))ef(c->se[i]); #define DONT TC(!(e->st-2)){GN(i,0,T){ep(ME[i],to);}QH;}TL(to,&e->s,1);IZ x #define PI fprintf #define YOUR IZ c; #define WOULDN x=0;}EA sr(THAT e,IZ j){TC(j>= #define SABAK TC(p->x)ek(p->x);OO(p);B b;b #define SO x=0;}WD GF{ #define REALLY {THAT r=pk(p);es(x,r);}QH x;} #define JUST #define GF struct #define TECHNOLOGY p->st[p->c];}EA zl(){B b;b #define TOKI QH c;}YM pm(P*p,UV Hs){ #define ALEKSANDER EA pf(P*p){ #define COURSE [i]);ME[i]=ei(95,2);}++i;}QH e;}EA nh(){B b;b #define OL malloc #define WARSAW QH(p->c>=p->l);}QP |
submitted at
1 like
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 | import antigravity # :O from copy import deepcopy as shallow_copy # >:D MALE = 0 ASEXUAL = 1 FEMALE = 2 POLYGENDER = 3 CIS = 0 TRANS = 1 HE_HIM = 0 SHE_HER = 1 THEY_THEM = 2 def transition(gender): return (gender + 2) % 4 class Queer: def __init__(self, femininity, masculinity, t) -> None: self.femininity = femininity self.masculinity = masculinity self.down_gender_identity = int(POLYGENDER in femininity) self.up_gender_identity = int(ASEXUAL in femininity) self.left_gender_identity = int(FEMALE in femininity) self.right_gender_identity = int(MALE in femininity) self.pronouns = t plus_1 = Queer([POLYGENDER, ASEXUAL], [FEMALE, MALE], HE_HIM) plus_2 = Queer([FEMALE, MALE], [POLYGENDER, ASEXUAL], HE_HIM) forward_1 = Queer([FEMALE, ASEXUAL], [MALE, POLYGENDER], SHE_HER) forward_2 = Queer([MALE, POLYGENDER], [FEMALE, ASEXUAL], SHE_HER) backward_1 = Queer([MALE, ASEXUAL], [FEMALE, POLYGENDER], THEY_THEM) backward_2 = Queer([FEMALE, POLYGENDER], [MALE, ASEXUAL], THEY_THEM) # Wave function collapse! class Tile: def __init__(self, grid) -> None: self.possible_genders = [] self.gender = None self.grid = grid self.x = 0 self.y = 0 self.gay_checks = [False, False] def collapse(self, abusive_parents=False): if self.gender: return if len(self.possible_genders) == 0: return genders = self.possible_genders right = None if self.x == len(self.grid[0]) - 1 else self.grid[self.y][self.x + 1] down = None if self.y == len(self.grid) - 1 else self.grid[self.y + 1][self.x] left = None if self.x == 0 else self.grid[self.y][self.x - 1] up = None if self.y == 0 else self.grid[self.y - 1][self.x] if abusive_parents: self.gender = self.possible_genders[0] if left: left.collapse() if right: right.collapse() if up: up.collapse() if down: down.collapse() return if left and left.gender: genders = [gender for gender in genders if gender.left_gender_identity == left.gender.right_gender_identity] if right and right.gender: genders = [gender for gender in genders if gender.right_gender_identity == right.gender.left_gender_identity] if up and up.gender: genders = [gender for gender in genders if gender.up_gender_identity == up.gender.down_gender_identity] if down and down.gender: genders = [gender for gender in genders if gender.down_gender_identity == down.gender.up_gender_identity] self.possible_genders = genders if len(genders) == 0: raise Exception("B-but y-you said t-that all entries w-would be va-valid :(") if len(genders) == 1: self.gender = genders[0] if left: left.collapse() if right: right.collapse() if up: up.collapse() if down: down.collapse() def make_possible_genders(self, strgrid, x, y): self.x = x self.y = y if strgrid[y][x] == '+': self.possible_genders.append(plus_1) self.possible_genders.append(plus_2) elif strgrid[y][x] == '/': self.possible_genders.append(forward_1) self.possible_genders.append(forward_2) elif strgrid[y][x] == '\\': self.possible_genders.append(backward_1) self.possible_genders.append(backward_2) def get_next_direction_to_move(tile, current_dir, color): inv_dir = transition(current_dir) dirs = [] if color == TRANS: dirs = shallow_copy(tile.gender.femininity) else: dirs = shallow_copy(tile.gender.masculinity) dirs = [d for d in dirs if d != inv_dir] return dirs[0] def get_wall_hit(grid, current_dir, color, x, y, w, h): i_cant_find_name_for_this_variable = False while True: tile = grid[y][x] if not tile.gender: return None if i_cant_find_name_for_this_variable: current_dir = get_next_direction_to_move(tile, current_dir, color) if current_dir == MALE and x == w - 1: return current_dir elif current_dir == FEMALE and x == 0: return current_dir elif current_dir == ASEXUAL and y == 0: return current_dir elif current_dir == POLYGENDER and y == h - 1: return current_dir if current_dir == MALE: x += 1 elif current_dir == FEMALE: x -= 1 elif current_dir == ASEXUAL: y -= 1 elif current_dir == POLYGENDER: y += 1 i_cant_find_name_for_this_variable = True def check_for_straight_wins(grid): height = len(grid) width = len(grid[0]) for i in range(height): tile = grid[i][0] if not tile.gender: continue x = 0 y = i start_dir = None if tile.gender.pronouns == HE_HIM: start_dir = MALE elif tile.gender.pronouns == SHE_HER: start_dir = ASEXUAL elif tile.gender.pronouns == THEY_THEM: start_dir = POLYGENDER color = int(start_dir in tile.gender.femininity) if start_dir is not None: wall_dir = get_wall_hit(grid, start_dir, color, x, y, width, height) if wall_dir == MALE: return True for i in range(width): tile = grid[0][i] if not tile.gender: continue x = i y = 0 start_dir = None if tile.gender.pronouns == HE_HIM: start_dir = POLYGENDER elif tile.gender.pronouns == SHE_HER: start_dir = FEMALE elif tile.gender.pronouns == THEY_THEM: start_dir = MALE color = int(start_dir in tile.gender.femininity) if start_dir is not None: wall_dir = get_wall_hit(grid, start_dir, color, x, y, width, height) if wall_dir == POLYGENDER: return True return False def check_gay(grid, w, h, x, y, color): tile = grid[y][x] if not tile.gender: return False if tile.gay_checks[color]: return False dirs = None if color == TRANS: dirs = tile.gender.femininity else: dirs = tile.gender.masculinity def trans(_grid, _x, _y, _startdir): _tile = _grid[_y][_x] if not _tile.gender: return False if _tile.gay_checks[color]: return False _dir = _startdir i_cant_find_name_for_this_variable = False while not _tile.gay_checks[color]: _tile.gay_checks[color] = True if i_cant_find_name_for_this_variable: _dir = get_next_direction_to_move(_tile, _dir, color) if _dir == MALE and _x == w - 1: return False elif _dir == FEMALE and _x == 0: return False elif _dir == ASEXUAL and _y == 0: return False elif _dir == POLYGENDER and _y == h - 1: return False if _dir == MALE: _x += 1 elif _dir == FEMALE: _x -= 1 elif _dir == ASEXUAL: _y -= 1 elif _dir == POLYGENDER: _y += 1 i_cant_find_name_for_this_variable = True _tile = _grid[_y][_x] if not _tile.gender: return False return True if trans(grid, x, y, dirs[0]): return True tile.gay_checks[color] = False return trans(grid, x, y, dirs[1]) def check_for_gay_wins(grid): height = len(grid) width = len(grid[0]) for y in range(height): for x in range(width): if check_gay(grid, width, height, x, y, TRANS) or check_gay(grid, width, height, x, y, CIS): return True return False def parse(input_grid): input_grid = input_grid.split('\n') height = len(input_grid) width = max([len(line) for line in input_grid]) for y in range(height): input_grid[y] += (width - len(input_grid[y])) * ' ' grid = [] for y in range(height): grid.append([]) for x in range(width): grid[-1].append(Tile(grid)) grid[-1][-1].make_possible_genders(input_grid, x, y) for y in range(height): for x in range(width): if len(grid[y][x].possible_genders) != 0: grid[y][x].collapse(True) return grid def are_ya_winnin_son(board): board = parse(board) return check_for_straight_wins(board) or check_for_gay_wins(board) |
submitted at
0 likes

submitted at
1 like
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 | from typing import Tuple from dataclasses import dataclass from enum import Enum class Direction(Enum): RIGHT = 0 UP = 1 LEFT = 2 DOWN = 3 @dataclass class BoxInfo: x: int y: int width: int height: int @dataclass class ConnectionInfo: x: int y: int direction: Direction box_index: int VALID_CHARACTERS = '─│┌┐└┘├┤┬┴ \n' def get_box_info(input: list[str], x: int, y: int) -> BoxInfo | None | bool: if input[y][x] != '┌': return None width = 1 height = 1 try: while input[y][x + width] in ('─', '┴'): width += 1 except: pass try: while input[y + height][x] in ('│', '┤'): height += 1 except: pass try: if input[y + height][x] in ('├', '┬', '┤') or input[y][x + width] in ('├', '┬', '┤') or input[y + height][x + width] in ('├', '┬', '┤'): return False if input[y + height][x] != '└' or input[y][x + width] != '┐': return None except: return None for i in range(width): if input[y + height][x + i] not in ('└', '─', '┬', '┘'): return False for i in range(height): if input[y + i][x + width] not in ('┐', '│', '├', '┘'): return False return BoxInfo(x, y, width + 1, height + 1) def find_connections(input: list[str], box: BoxInfo, box_index) -> list[ConnectionInfo]: x, y = box.x, box.y w, h = box.width, box.height result = [] for i in range(w): if input[y][x + i] == '┴': result.append(ConnectionInfo(x + i, y, Direction.UP, box_index)) if input[y + h - 1][x + i] == '┬': result.append(ConnectionInfo(x + i, y + h - 1, Direction.DOWN, box_index)) for i in range(h): if input[y + i][x] == '┤': result.append(ConnectionInfo(x, y + i, Direction.LEFT, box_index)) if input[y + i][x + w - 1] == '├': result.append(ConnectionInfo(x + w - 1, y + i, Direction.RIGHT, box_index)) return result def char_to_directions(c) -> set[Direction] | None: match c: case '─': return {Direction.LEFT, Direction.RIGHT} case '│': return {Direction.DOWN, Direction.UP} case '┌': return {Direction.DOWN, Direction.RIGHT} case '┐': return {Direction.DOWN, Direction.LEFT} case '└': return {Direction.UP, Direction.RIGHT} case '┘': return {Direction.UP, Direction.LEFT} case '├': return {Direction.RIGHT} case '┤': return {Direction.LEFT} case '┬': return {Direction.DOWN} case '┴': return {Direction.UP} return None def direction_to_delta_pos(d: Direction) -> Tuple[int, int]: match d: case Direction.LEFT: return (-1, 0) case Direction.RIGHT: return (1, 0) case Direction.UP: return (0, -1) case Direction.DOWN: return (0, 1) def invert(d: Direction) -> Direction: i = d.value return Direction((i + 2) % 4) def follow_connection(input: list[str], conn: ConnectionInfo) -> ConnectionInfo | None: LINES = '─│┌┐└┘├┤┬┴' pointer_x = conn.x pointer_y = conn.y pointer_d = conn.direction while True: dx, dy = direction_to_delta_pos(pointer_d) pointer_x += dx pointer_y += dy c = input[pointer_y][pointer_x] directions = char_to_directions(c) if directions is None: return None if len(directions) == 1: return ConnectionInfo(pointer_x, pointer_y, list(directions)[0], -1) if invert(pointer_d) not in directions: return None directions.remove(invert(pointer_d)) pointer_d = list(directions)[0] def entry(input: str): if any(char not in VALID_CHARACTERS for char in input): return "nahhh" input_as_list: list[str] = input.split('\n') boxes: list[BoxInfo] = [] # Find boxes for y, line in enumerate(input_as_list): index = -1 while (index := line.find('┌', index + 1)) != -1: box_info = get_box_info(input_as_list, index, y) if box_info is None: continue if box_info == False: return "nahhh" boxes.append(box_info) for i in range(len(boxes)): for j in range(len(boxes)): if i == j: continue b1 = boxes[i] b2 = boxes[j] if b1.x < b2.x and b2.x < b1.x + b1.width and b1.y < b2.y and b2.y < b1.y + b1.height: return "nahhh" # Find connections connections: list[ConnectionInfo] = [] for i, box in enumerate(boxes): connections.extend(find_connections(input_as_list, box, i)) formed_connections = [] while len(connections) != 0: first_connection = connections[0] end_connection = follow_connection(input_as_list, first_connection) if end_connection is None: return "nahhh" for c in connections: if c.x == end_connection.x and c.y == end_connection.y and c.direction == end_connection.direction: end_connection.box_index = c.box_index break if end_connection.box_index == -1: return "nahhh" if end_connection.box_index == connections[0].box_index: return "nahhh" if (connections[0].box_index, end_connection.box_index) in formed_connections or (end_connection.box_index, connections[0].box_index) in formed_connections: return "nahhh" formed_connections.append((connections[0].box_index, end_connection.box_index)) connections.remove(end_connection) del connections[0] return "legit frfr" |
submitted at
0 likes
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | import java.lang.StringBuilder; class Entry { public static String entry(int n) { StringBuilder sb = new StringBuilder(); int len = (int)Math.pow(2, n); for(int i = 0; i < len; i++) { int popcnt = Integer.bitCount(i); if((popcnt & 1) == 0) { sb.append('0'); } else { sb.append('1'); } } return sb.toString(); } } |
submitted at
0 likes
if you are on lower altitudes or have an ecc ram the algorithm may take a bit longer than average
umm actually len neednt be stored in ram at all its probably stored in a register meaning it will be more robust than ram (and less likely to suffer from bit flips) ecc ram wont make a difference then
but dont worry
umm actually i do worry that the probability that this algorithm terminates with an incorrect result is much higher than the probability that it terminates with the correct result because the more random bit flips happen the more zeros you will get (the string which resides in memory will converge towards 1/256th zeros) so at some point the probability that you accidentally land on a character which was turned into a zero by cosmic radiation is higher than the probability that you actually land on the null terminator (and this is ignoring various other important things like the return address etc that could be corrupted)
this does not work because its undefined behavior
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 | #include <stdio.h> #include <string.h> #include <limits.h> #define SIZE (USHRT_MAX + 1) // Calculate string length by utilizing cosmic ray bit flipping // Recommended to run in space. Scroll down for more detailed description int find_length(char* str) { unsigned short len = 0; while(1) { if(str[len] == 0) break; } return len; } int main() { char input[SIZE]; memset(input, -1, SIZE); scanf("%[^\n]", input); int len = find_length(input); printf("The length of the string is: %d", len); return 0; } /* This algorithm continuously checks whether a bit flip caused by cosmic rays (or any other noise, really) sets the value of len to the length of the input string. The speed of the algorithm heavily depends on your altitude and hardware. If you are on lower altitudes or have an ECC RAM, the algorithm may take a bit longer than average. But don't worry, no matter what your circumstances are, there is always a non-zero chance! Also, here's the entire bee movie script to keep you entertained while you wait: NARRATOR: (Black screen with text; The sound of buzzing bees can be heard) According to all known laws of aviation, : there is no way a bee should be able to fly. : Its wings are too small to get its fat little body off the ground. : The bee, of course, flies anyway : because bees don't care what humans think is impossible. BARRY BENSON: (Barry is picking out a shirt) Yellow, black. Yellow, black. Yellow, black. Yellow, black. : Ooh, black and yellow! Let's shake it up a little. JANET BENSON: Barry! Breakfast is ready! BARRY: Coming! : Hang on a second. (Barry uses his antenna like a phone) : Hello? ADAM FLAYMAN: (Through phone) - Barry? BARRY: - Adam? ADAM: - Can you believe this is happening? BARRY: - I can't. I'll pick you up. (Barry flies down the stairs) : MARTIN BENSON: Looking sharp. JANET: Use the stairs. Your father paid good money for those. BARRY: Sorry. I'm excited. MARTIN: Here's the graduate. We're very proud of you, son. : A perfect report card, all B's. JANET: Very proud. (Rubs Barry's hair) BARRY= Ma! I got a thing going here. JANET: - You got lint on your fuzz. BARRY: - Ow! That's me! JANET: - Wave to us! We'll be in row 118,000. - Bye! (Barry flies out the door) JANET: Barry, I told you, stop flying in the house! (Barry drives through the hive,and is waved at by Adam who is reading a newspaper) BARRY== - Hey, Adam. ADAM: - Hey, Barry. (Adam gets in Barry's car) : - Is that fuzz gel? BARRY: - A little. Special day, graduation. ADAM: Never thought I'd make it. (Barry pulls away from the house and continues driving) BARRY: Three days grade school, three days high school... ADAM: Those were awkward. BARRY: Three days college. I'm glad I took a day and hitchhiked around the hive. ADAM== You did come back different. (Barry and Adam pass by Artie, who is jogging) ARTIE: - Hi, Barry! BARRY: - Artie, growing a mustache? Looks good. ADAM: - Hear about Frankie? BARRY: - Yeah. ADAM== - You going to the funeral? BARRY: - No, I'm not going to his funeral. : Everybody knows, sting someone, you die. : Don't waste it on a squirrel. Such a hothead. ADAM: I guess he could have just gotten out of the way. (The car does a barrel roll on the loop-shaped bridge and lands on the highway) : I love this incorporating an amusement park into our regular day. BARRY: I guess that's why they say we don't need vacations. (Barry parallel parks the car and together they fly over the graduating students) Boy, quite a bit of pomp... under the circumstances. (Barry and Adam sit down and put on their hats) : - Well, Adam, today we are men. ADAM: - We are! BARRY= - Bee-men. =ADAM= - Amen! BARRY AND ADAM: Hallelujah! (Barry and Adam both have a happy spasm) ANNOUNCER: Students, faculty, distinguished bees, : please welcome Dean Buzzwell. DEAN BUZZWELL: Welcome, New Hive Oity graduating class of... : ...9: : That concludes our ceremonies. : And begins your career at Honex Industries! ADAM: Will we pick our job today? (Adam and Barry get into a tour bus) BARRY= I heard it's just orientation. (Tour buses rise out of the ground and the students are automatically loaded into the buses) TOUR GUIDE: Heads up! Here we go. ANNOUNCER: Keep your hands and antennas inside the tram at all times. BARRY: - Wonder what it'll be like? ADAM: - A little scary. TOUR GUIDE== Welcome to Honex, a division of Honesco : and a part of the Hexagon Group. Barry: This is it! BARRY AND ADAM: Wow. BARRY: Wow. (The bus drives down a road an on either side are the Bee's massive complicated Honey-making machines) TOUR GUIDE: We know that you, as a bee, have worked your whole life : to get to the point where you can work for your whole life. : Honey begins when our valiant Pollen Jocks bring the nectar to the hive. : Our top-secret formula : is automatically color-corrected, scent-adjusted and bubble-contoured : into this soothing sweet syrup : with its distinctive golden glow you know as... EVERYONE ON BUS: Honey! (The guide has been collecting honey into a bottle and she throws it into the crowd on the bus and it is caught by a girl in the back) ADAM: - That girl was hot. BARRY: - She's my cousin! ADAM== - She is? BARRY: - Yes, we're all cousins. ADAM: - Right. You're right. TOUR GUIDE: - At Honex, we constantly strive : to improve every aspect of bee existence. : These bees are stress-testing a new helmet technology. (The bus passes by a Bee wearing a helmet who is being smashed into the ground with fly-swatters, newspapers and boots. He lifts a thumbs up but you can hear him groan) : ADAM== - What do you think he makes? BARRY: - Not enough. TOUR GUIDE: Here we have our latest advancement, the Krelman. (They pass by a turning wheel with Bees standing on pegs, who are each wearing a finger-shaped hat) Barry: - Wow, What does that do? TOUR GUIDE: - Catches that little strand of honey : that hangs after you pour it. Saves us millions. ADAM: (Intrigued) Can anyone work on the Krelman? TOUR GUIDE: Of course. Most bee jobs are small ones. But bees know that every small job, if it's done well, means a lot. : But choose carefully : because you'll stay in the job you pick for the rest of your life. (Everyone claps except for Barry) BARRY: The same job the rest of your life? I didn't know that. ADAM: What's the difference? TOUR GUIDE: You'll be happy to know that bees, as a species, haven't had one day off : in 27 million years. BARRY: (Upset) So you'll just work us to death? : We'll sure try. (Everyone on the bus laughs except Barry. Barry and Adam are walking back home together) ADAM: Wow! That blew my mind! BARRY: "What's the difference?" How can you say that? : One job forever? That's an insane choice to have to make. ADAM: I'm relieved. Now we only have to make one decision in life. BARRY: But, Adam, how could they never have told us that? ADAM: Why would you question anything? We're bees. : We're the most perfectly functioning society on Earth. BARRY: You ever think maybe things work a little too well here? ADAM: Like what? Give me one example. (Barry and Adam stop walking and it is revealed to the audience that hundreds of cars are speeding by and narrowly missing them in perfect unison) BARRY: I don't know. But you know what I'm talking about. ANNOUNCER: Please clear the gate. Royal Nectar Force on approach. BARRY: Wait a second. Check it out. (The Pollen jocks fly in, circle around and landing in line) : - Hey, those are Pollen Jocks! ADAM: - Wow. : I've never seen them this close. BARRY: They know what it's like outside the hive. ADAM: Yeah, but some don't come back. GIRL BEES: - Hey, Jocks! - Hi, Jocks! (The Pollen Jocks hook up their backpacks to machines that pump the nectar to trucks, which drive away) LOU LO DUVA: You guys did great! : You're monsters! You're sky freaks! I love it! (Punching the Pollen Jocks in joy) I love it! ADAM: - I wonder where they were. BARRY: - I don't know. : Their day's not planned. : Outside the hive, flying who knows where, doing who knows what. : You can't just decide to be a Pollen Jock. You have to be bred for that. ADAM== Right. (Barry and Adam are covered in some pollen that floated off of the Pollen Jocks) BARRY: Look at that. That's more pollen than you and I will see in a lifetime. ADAM: It's just a status symbol. Bees make too much of it. BARRY: Perhaps. Unless you're wearing it and the ladies see you wearing it. (Barry waves at 2 girls standing a little away from them) ADAM== Those ladies? Aren't they our cousins too? BARRY: Distant. Distant. POLLEN JOCK #1: Look at these two. POLLEN JOCK #2: - Couple of Hive Harrys. POLLEN JOCK #1: - Let's have fun with them. GIRL BEE #1: It must be dangerous being a Pollen Jock. BARRY: Yeah. Once a bear pinned me against a mushroom! : He had a paw on my throat, and with the other, he was slapping me! (Slaps Adam with his hand to represent his scenario) GIRL BEE #2: - Oh, my! BARRY: - I never thought I'd knock him out. GIRL BEE #1: (Looking at Adam) What were you doing during this? ADAM: Obviously I was trying to alert the authorities. BARRY: I can autograph that. (The pollen jocks walk up to Barry and Adam, they pretend that Barry and Adam really are pollen jocks.) POLLEN JOCK #1: A little gusty out there today, wasn't it, comrades? BARRY: Yeah. Gusty. POLLEN JOCK #1: We're hitting a sunflower patch six miles from here tomorrow. BARRY: - Six miles, huh? ADAM: - Barry! POLLEN JOCK #2: A puddle jump for us, but maybe you're not up for it. BARRY: - Maybe I am. ADAM: - You are not! POLLEN JOCK #1: We're going 0900 at J-Gate. : What do you think, buzzy-boy? Are you bee enough? BARRY: I might be. It all depends on what 0900 means. (The scene cuts to Barry looking out on the hive-city from his balcony at night) MARTIN: Hey, Honex! BARRY: Dad, you surprised me. MARTIN: You decide what you're interested in? BARRY: - Well, there's a lot of choices. - But you only get one. : Do you ever get bored doing the same job every day? MARTIN: Son, let me tell you about stirring. : You grab that stick, and you just move it around, and you stir it around. : You get yourself into a rhythm. It's a beautiful thing. BARRY: You know, Dad, the more I think about it, : maybe the honey field just isn't right for me. MARTIN: You were thinking of what, making balloon animals? : That's a bad job for a guy with a stinger. : Janet, your son's not sure he wants to go into honey! JANET: - Barry, you are so funny sometimes. BARRY: - I'm not trying to be funny. MARTIN: You're not funny! You're going into honey. Our son, the stirrer! JANET: - You're gonna be a stirrer? BARRY: - No one's listening to me! MARTIN: Wait till you see the sticks I have. BARRY: I could say anything right now. I'm gonna get an ant tattoo! (Barry's parents don't listen to him and continue to ramble on) MARTIN: Let's open some honey and celebrate! BARRY: Maybe I'll pierce my thorax. Shave my antennae. : Shack up with a grasshopper. Get a gold tooth and call everybody "dawg"! JANET: I'm so proud. (The scene cuts to Barry and Adam waiting in line to get a job) ADAM: - We're starting work today! BARRY: - Today's the day. ADAM: Come on! All the good jobs will be gone. BARRY: Yeah, right. JOB LISTER: Pollen counting, stunt bee, pouring, stirrer, front desk, hair removal... BEE IN FRONT OF LINE: - Is it still available? JOB LISTER: - Hang on. Two left! : One of them's yours! Congratulations! Step to the side. ADAM: - What'd you get? BEE IN FRONT OF LINE: - Picking crud out. Stellar! (He walks away) ADAM: Wow! JOB LISTER: Couple of newbies? ADAM: Yes, sir! Our first day! We are ready! JOB LISTER: Make your choice. (Adam and Barry look up at the job board. There are hundreds of constantly changing panels that contain available or unavailable jobs. It looks very confusing) ADAM: - You want to go first? BARRY: - No, you go. ADAM: Oh, my. What's available? JOB LISTER: Restroom attendant's open, not for the reason you think. ADAM: - Any chance of getting the Krelman? JOB LISTER: - Sure, you're on. (Puts the Krelman finger-hat on Adam's head) (Suddenly the sign for Krelman closes out) : I'm sorry, the Krelman just closed out. (Takes Adam's hat off) Wax monkey's always open. ADAM: The Krelman opened up again. : What happened? JOB LISTER: A bee died. Makes an opening. See? He's dead. Another dead one. : Deady. Deadified. Two more dead. : Dead from the neck up. Dead from the neck down. That's life! ADAM: Oh, this is so hard! (Barry remembers what the Pollen Jock offered him and he flies off) Heating, cooling, stunt bee, pourer, stirrer, : humming, inspector number seven, lint coordinator, stripe supervisor, : mite wrangler. Barry, what do you think I should... Barry? (Adam turns around and sees Barry flying away) : Barry! POLLEN JOCK: All right, we've got the sunflower patch in quadrant nine... ADAM: (Through phone) What happened to you? Where are you? BARRY: - I'm going out. ADAM: - Out? Out where? BARRY: - Out there. ADAM: - Oh, no! BARRY: I have to, before I go to work for the rest of my life. ADAM: You're gonna die! You're crazy! (Barry hangs up) Hello? POLLEN JOCK #2: Another call coming in. : If anyone's feeling brave, there's a Korean deli on 83rd : that gets their roses today. BARRY: Hey, guys. POLLEN JOCK #1 == - Look at that. POLLEN JOCK #2: - Isn't that the kid we saw yesterday? LOU LO DUVA: Hold it, son, flight deck's restricted. POLLEN JOCK #1: It's OK, Lou. We're gonna take him up. (Puts hand on Barry's shoulder) LOU LO DUVA: (To Barry) Really? Feeling lucky, are you? BEE WITH CLIPBOARD: (To Barry) Sign here, here. Just initial that. : - Thank you. LOU LO DUVA: - OK. : You got a rain advisory today, : and as you all know, bees cannot fly in rain. : So be careful. As always, watch your brooms, : hockey sticks, dogs, birds, bears and bats. : Also, I got a couple of reports of root beer being poured on us. : Murphy's in a home because of it, babbling like a cicada! BARRY: - That's awful. LOU LO DUVA: (Still talking through megaphone) - And a reminder for you rookies, : bee law number one, absolutely no talking to humans! : All right, launch positions! POLLEN JOCKS: (The Pollen Jocks run into formation) : Buzz, buzz, buzz, buzz! Buzz, buzz, buzz, buzz! Buzz, buzz, buzz, buzz! LOU LU DUVA: Black and yellow! POLLEN JOCKS: Hello! POLLEN JOCK #1: (To Barry)You ready for this, hot shot? BARRY: Yeah. Yeah, bring it on. POLLEN JOCK's: Wind, check. : - Antennae, check. - Nectar pack, check. : - Wings, check. - Stinger, check. BARRY: Scared out of my shorts, check. LOU LO DUVA: OK, ladies, : let's move it out! : Pound those petunias, you striped stem-suckers! : All of you, drain those flowers! (The pollen jocks fly out of the hive) BARRY: Wow! I'm out! : I can't believe I'm out! : So blue. : I feel so fast and free! : Box kite! (Barry flies through the kite) : Wow! : Flowers! (A pollen jock puts on some high tech goggles that shows flowers similar to heat sink goggles.) POLLEN JOCK: This is Blue Leader. We have roses visual. : Bring it around 30 degrees and hold. : Roses! POLLEN JOCK #1: 30 degrees, roger. Bringing it around. : Stand to the side, kid. It's got a bit of a kick. (The pollen jock fires a high-tech gun at the flower, shooting tubes that suck up the nectar from the flower and collects it into a pouch on the gun) BARRY: That is one nectar collector! POLLEN JOCK #1== - Ever see pollination up close? BARRY: - No, sir. POLLEN JOCK #1: (Barry and the Pollen jock fly over the field, the pollen jock sprinkles pollen as he goes) : I pick up some pollen here, sprinkle it over here. Maybe a dash over there, : a pinch on that one. See that? It's a little bit of magic. BARRY: That's amazing. Why do we do that? POLLEN JOCK #1: That's pollen power. More pollen, more flowers, more nectar, more honey for us. BARRY: Cool. POLLEN JOCK #1: I'm picking up a lot of bright yellow. could be daisies. Don't we need those? POLLEN JOCK #2: Copy that visual. : Wait. One of these flowers seems to be on the move. POLLEN JOCK #1: Say again? You're reporting a moving flower? POLLEN JOCK #2: Affirmative. (The Pollen jocks land near the "flowers" which, to the audience are obviously just tennis balls) KEN: (In the distance) That was on the line! POLLEN JOCK #1: This is the coolest. What is it? POLLEN JOCK #2: I don't know, but I'm loving this color. : It smells good. Not like a flower, but I like it. POLLEN JOCK #1: Yeah, fuzzy. (Sticks his hand on the ball but it gets stuck) POLLEN JOCK #3== Chemical-y. (The pollen jock finally gets his hand free from the tennis ball) POLLEN JOCK #1: Careful, guys. It's a little grabby. (The pollen jocks turn around and see Barry lying his entire body on top of one of the tennis balls) POLLEN JOCK #2: My sweet lord of bees! POLLEN JOCK #3: Candy-brain, get off there! POLLEN JOCK #1: (Pointing upwards) Problem! (A human hand reaches down and grabs the tennis ball that Barry is stuck to) BARRY: - Guys! POLLEN JOCK #2: - This could be bad. POLLEN JOCK #3: Affirmative. (Vanessa Bloome starts bouncing the tennis ball, not knowing Barry is stick to it) BARRY== Very close. : Gonna hurt. : Mama's little boy. (Barry is being hit back and forth by two humans playing tennis. He is still stuck to the ball) POLLEN JOCK #1: You are way out of position, rookie! KEN: Coming in at you like a MISSILE! (Barry flies past the pollen jocks, still stuck to the ball) BARRY: (In slow motion) Help me! POLLEN JOCK #2: I don't think these are flowers. POLLEN JOCK #3: - Should we tell him? POLLEN JOCK #1: - I think he knows. BARRY: What is this?! KEN: Match point! : You can start packing up, honey, because you're about to EAT IT! (A pollen jock coughs which confused Ken and he hits the ball the wrong way with Barry stuck to it and it goes flying into the city) BARRY: Yowser! (Barry bounces around town and gets stuck in the engine of a car. He flies into the air conditioner and sees a bug that was frozen in there) BARRY: Ew, gross. (The man driving the car turns on the air conditioner which blows Barry into the car) GIRL IN CAR: There's a bee in the car! : - Do something! DAD DRIVING CAR: - I'm driving! BABY GIRL: (Waving at Barry) - Hi, bee. (Barry smiles and waves at the baby girl) GUY IN BACK OF CAR: - He's back here! : He's going to sting me! GIRL IN CAR: Nobody move. If you don't move, he won't sting you. Freeze! (Barry freezes as well, hovering in the middle of the car) : GRANDMA IN CAR== He blinked! (The grandma whips out some bee-spray and sprays everywhere in the car, climbing into the front seat, still trying to spray Barry) GIRL IN CAR: Spray him, Granny! DAD DRIVING THE CAR: What are you doing?! (Barry escapes the car through the air conditioner and is flying high above the ground, safe.) BARRY: Wow... the tension level out here is unbelievable. (Barry sees that storm clouds are gathering and he can see rain clouds moving into this direction) : I gotta get home. : Can't fly in rain. : Can't fly in rain. (A rain drop hits Barry and one of his wings is damaged) : Can't fly in rain. (A second rain drop hits Barry again and he spirals downwards) Mayday! Mayday! Bee going down! (WW2 plane sound effects are played as he plummets, and he crash-lands on a plant inside an apartment near the window) VANESSA BLOOME: Ken, could you close the window please? KEN== Hey, check out my new resume. I made it into a fold-out brochure. : You see? (Folds brochure resume out) Folds out. (Ken closes the window, trapping Barry inside) BARRY: Oh, no. More humans. I don't need this. (Barry tries to fly away but smashes into the window and falls again) : What was that? (Barry keeps trying to fly out the window but he keeps being knocked back because the window is closed) Maybe this time. This time. This time. This time! This time! This... : Drapes! (Barry taps the glass. He doesn't understand what it is) That is diabolical. KEN: It's fantastic. It's got all my special skills, even my top-ten favorite movies. ANDY: What's number one? Star Wars? KEN: Nah, I don't go for that... (Ken makes finger guns and makes "pew pew pew" sounds and then stops) : ...kind of stuff. BARRY: No wonder we shouldn't talk to them. They're out of their minds. KEN: When I leave a job interview, they're flabbergasted, can't believe what I say. BARRY: (Looking at the light on the ceiling) There's the sun. Maybe that's a way out. (Starts flying towards the lightbulb) : I don't remember the sun having a big 75 on it. (Barry hits the lightbulb and falls into the dip on the table that the humans are sitting at) KEN: I predicted global warming. : I could feel it getting hotter. At first I thought it was just me. (Andy dips a chip into the bowl and scoops up some dip with Barry on it and is about to put it in his mouth) : Wait! Stop! Bee! (Andy drops the chip with Barry in fear and backs away. All the humans freak out) : Stand back. These are winter boots. (Ken has winter boots on his hands and he is about to smash the bee but Vanessa saves him last second) VANESSA: Wait! : Don't kill him! (Vanessa puts Barry in a glass to protect him) KEN: You know I'm allergic to them! This thing could kill me! VANESSA: Why does his life have less value than yours? KEN: Why does his life have any less value than mine? Is that your statement? VANESSA: I'm just saying all life has value. You don't know what he's capable of feeling. (Vanessa picks up Ken's brochure and puts it under the glass so she can carry Barry back to the window. Barry looks at Vanessa in amazement) KEN: My brochure! VANESSA: There you go, little guy. (Vanessa opens the window and lets Barry out but Barry stays back and is still shocked that a human saved his life) KEN: I'm not scared of him. It's an allergic thing. VANESSA: Put that on your resume brochure. KEN: My whole face could puff up. ANDY: Make it one of your special skills. KEN: Knocking someone out is also a special skill. (Ken walks to the door) Right. Bye, Vanessa. Thanks. : - Vanessa, next week? Yogurt night? VANESSA: - Sure, Ken. You know, whatever. : (Vanessa tries to close door) KEN== - You could put carob chips on there. VANESSA: - Bye. (Closes door but Ken opens it again) KEN: - Supposed to be less calories. VANESSA: - Bye. (Closes door) (Fast forward to the next day, Barry is still inside the house. He flies into the kitchen where Vanessa is doing dishes) BARRY== (Talking to himself) I gotta say something. : She saved my life. I gotta say something. : All right, here it goes. (Turns back) Nah. : What would I say? : I could really get in trouble. : It's a bee law. You're not supposed to talk to a human. : I can't believe I'm doing this. : I've got to. (Barry disguises himself as a character on a food can as Vanessa walks by again) : Oh, I can't do it. Come on! : No. Yes. No. : Do it. I can't. : How should I start it? (Barry strikes a pose and wiggles his eyebrows) "You like jazz?" No, that's no good. (Vanessa is about to walk past Barry) Here she comes! Speak, you fool! : ...Hi! (Vanessa gasps and drops the dishes in fright and notices Barry on the counter) : I'm sorry. VANESSA: - You're talking. BARRY: - Yes, I know. VANESSA: (Pointing at Barry) You're talking! BARRY: I'm so sorry. VANESSA: No, it's OK. It's fine. I know I'm dreaming. : But I don't recall going to bed. BARRY: Well, I'm sure this is very disconcerting. VANESSA: This is a bit of a surprise to me. I mean, you're a bee! BARRY: I am. And I'm not supposed to be doing this, (Pointing to the living room where Ken tried to kill him last night) but they were all trying to kill me. : And if it wasn't for you... : I had to thank you. It's just how I was raised. (Vanessa stabs her hand with a fork to test whether she's dreaming or not) : That was a little weird. VANESSA: - I'm talking with a bee. BARRY: - Yeah. VANESSA: I'm talking to a bee. And the bee is talking to me! BARRY: I just want to say I'm grateful. I'll leave now. (Barry turns to leave) VANESSA: - Wait! How did you learn to do that? BARRY: (Flying back) - What? VANESSA: The talking...thing. BARRY: Same way you did, I guess. "Mama, Dada, honey." You pick it up. VANESSA: - That's very funny. BARRY: - Yeah. : Bees are funny. If we didn't laugh, we'd cry with what we have to deal with. : Anyway... VANESSA: Can I... : ...get you something? BARRY: - Like what? VANESSA: I don't know. I mean... I don't know. Coffee? BARRY: I don't want to put you out. VANESSA: It's no trouble. It takes two minutes. : - It's just coffee. BARRY: - I hate to impose. (Vanessa starts making coffee) VANESSA: - Don't be ridiculous! BARRY: - Actually, I would love a cup. VANESSA: Hey, you want rum cake? BARRY: - I shouldn't. VANESSA: - Have some. BARRY: - No, I can't. VANESSA: - Come on! BARRY: I'm trying to lose a couple micrograms. VANESSA: - Where? BARRY: - These stripes don't help. VANESSA: You look great! BARRY: I don't know if you know anything about fashion. : Are you all right? VANESSA: (Pouring coffee on the floor and missing the cup completely) No. (Flash forward in time. Barry and Vanessa are sitting together at a table on top of the apartment building drinking coffee) : BARRY== He's making the tie in the cab as they're flying up Madison. : He finally gets there. : He runs up the steps into the church. The wedding is on. : And he says, "Watermelon? I thought you said Guatemalan. : Why would I marry a watermelon?" (Barry laughs but Vanessa looks confused) VANESSA: Is that a bee joke? BARRY: That's the kind of stuff we do. VANESSA: Yeah, different. : So, what are you gonna do, Barry? (Barry stands on top of a sugar cube floating in his coffee and paddles it around with a straw like it's a gondola) BARRY: About work? I don't know. : I want to do my part for the hive, but I can't do it the way they want. VANESSA: I know how you feel. BARRY: - You do? VANESSA: - Sure. : My parents wanted me to be a lawyer or a doctor, but I wanted to be a florist. BARRY: - Really? VANESSA: - My only interest is flowers. BARRY: Our new queen was just elected with that same campaign slogan. : Anyway, if you look... (Barry points to a tree in the middle of Central Park) : There's my hive right there. See it? VANESSA: You're in Sheep Meadow! BARRY: Yes! I'm right off the Turtle Pond! VANESSA: No way! I know that area. I lost a toe ring there once. BARRY: - Why do girls put rings on their toes? VANESSA: - Why not? BARRY: - It's like putting a hat on your knee. VANESSA: - Maybe I'll try that. (A custodian installing a lightbulb looks over at them but to his perspective it looks like Vanessa is talking to a cup of coffee on the table) CUSTODIAN: - You all right, ma'am? VANESSA: - Oh, yeah. Fine. : Just having two cups of coffee! BARRY: Anyway, this has been great. Thanks for the coffee. VANESSA== Yeah, it's no trouble. BARRY: Sorry I couldn't finish it. If I did, I'd be up the rest of my life. (Barry points towards the rum cake) : Can I take a piece of this with me? VANESSA: Sure! Here, have a crumb. (Vanessa hands Barry a crumb but it is still pretty big for Barry) BARRY: - Thanks! VANESSA: - Yeah. BARRY: All right. Well, then... I guess I'll see you around. : Or not. VANESSA: OK, Barry... BARRY: And thank you so much again... for before. VANESSA: Oh, that? That was nothing. BARRY: Well, not nothing, but... Anyway... (Vanessa and Barry hold hands, but Vanessa has to hold out a finger because her hands is to big and Barry holds that) (The custodian looks over again and it appears Vanessa is laughing at her coffee again. The lightbulb that he was screwing in sparks and he falls off the ladder) (Fast forward in time and we see two Bee Scientists testing out a parachute in a Honex wind tunnel) BEE SCIENTIST #1: This can't possibly work. BEE SCIENTIST #2: He's all set to go. We may as well try it. : OK, Dave, pull the chute. (Dave pulls the chute and the wind slams him against the wall and he falls on his face.The camera pans over and we see Barry and Adam walking together) ADAM: - Sounds amazing. BARRY: - It was amazing! : It was the scariest, happiest moment of my life. ADAM: Humans! I can't believe you were with humans! : Giant, scary humans! What were they like? BARRY: Huge and crazy. They talk crazy. : They eat crazy giant things. They drive crazy. ADAM: - Do they try and kill you, like on TV? BARRY: - Some of them. But some of them don't. ADAM: - How'd you get back? BARRY: - Poodle. ADAM: You did it, and I'm glad. You saw whatever you wanted to see. : You had your "experience." Now you can pick out your job and be normal. BARRY: - Well... ADAM: - Well? BARRY: Well, I met someone. ADAM: You did? Was she Bee-ish? : - A wasp?! Your parents will kill you! BARRY: - No, no, no, not a wasp. ADAM: - Spider? BARRY: - I'm not attracted to spiders. : I know, for everyone else, it's the hottest thing, with the eight legs and all. : I can't get by that face. ADAM: So who is she? BARRY: She's... human. ADAM: No, no. That's a bee law. You wouldn't break a bee law. BARRY: - Her name's Vanessa. (Adam puts his head in his hands) ADAM: - Oh, boy. BARRY== She's so nice. And she's a florist! ADAM: Oh, no! You're dating a human florist! BARRY: We're not dating. ADAM: You're flying outside the hive, talking to humans that attack our homes : with power washers and M-80s! That's one-eighth a stick of dynamite! BARRY: She saved my life! And she understands me. ADAM: This is over! BARRY: Eat this. (Barry gives Adam a piece of the crumb that he got from Vanessa. Adam eats it) ADAM: (Adam's tone changes) This is not over! What was that? BARRY: - They call it a crumb. ADAM: - It was so stingin' stripey! BARRY: And that's not what they eat. That's what falls off what they eat! : - You know what a Cinnabon is? ADAM: - No. (Adam opens a door behind him and he pulls Barry in) BARRY: It's bread and cinnamon and frosting. ADAM: Be quiet! BARRY: They heat it up... ADAM: Sit down! (Adam forces Barry to sit down) BARRY: (Still rambling about Cinnabons) ...really hot! (Adam grabs Barry by the shoulders) ADAM: - Listen to me! : We are not them! We're us. There's us and there's them! BARRY== Yes, but who can deny the heart that is yearning? ADAM: There's no yearning. Stop yearning. Listen to me! : You have got to start thinking bee, my friend. Thinking bee! BARRY: - Thinking bee. WORKER BEE: - Thinking bee. WORKER BEES AND ADAM: Thinking bee! Thinking bee! Thinking bee! Thinking bee! (Flash forward in time; Barry is laying on a raft in a pool full of honey. He is wearing sunglasses) JANET: There he is. He's in the pool. MARTIN: You know what your problem is, Barry? (Barry pulls down his sunglasses and he looks annoyed) BARRY: (Sarcastic) I gotta start thinking bee? JANET: How much longer will this go on? MARTIN: It's been three days! Why aren't you working? (Puts sunglasses back on) BARRY: I've got a lot of big life decisions to think about. MARTIN: What life? You have no life! You have no job. You're barely a bee! JANET: Would it kill you to make a little honey? (Barry rolls off the raft and sinks into the honey pool) : Barry, come out. Your father's talking to you. : Martin, would you talk to him? MARTIN: Barry, I'm talking to you! (Barry keeps sinking into the honey until he is suddenly in Central Park having a picnic with Vanessa) (Barry has a cup of honey and he clinks his glass with Vanessas. Suddenly a mosquito lands on Vanessa and she slaps it, killing it. They both gasp but then burst out laughing) VANESSA: You coming? (The camera pans over and Vanessa is climbing into a small yellow airplane) BARRY: Got everything? VANESSA: All set! BARRY: Go ahead. I'll catch up. (Vanessa lifts off and flies ahead) VANESSA: Don't be too long. (Barry catches up with Vanessa and he sticks out his arms like ana irplane. He rolls from side to side, and Vanessa copies him with the airplane) VANESSA: Watch this! (Barry stays back and watches as Vanessa draws a heart in the air using pink smoke from the plane, but on the last loop-the-loop she suddenly crashes into a mountain and the plane explodes. The destroyed plane falls into some rocks and explodes a second time) BARRY: Vanessa! (As Barry is yelling his mouth fills with honey and he wakes up, discovering that he was just day dreaming. He slowly sinks back into the honey pool) MARTIN: - We're still here. JANET: - I told you not to yell at him. : He doesn't respond to yelling! MARTIN: - Then why yell at me? JANET: - Because you don't listen! MARTIN: I'm not listening to this. BARRY: Sorry, I've gotta go. MARTIN: - Where are you going? BARRY: - I'm meeting a friend. JANET: A girl? Is this why you can't decide? BARRY: Bye. (Barry flies out the door and Martin shakes his head) : JANET== I just hope she's Bee-ish. (Fast forward in time and Barry is sitting on Vanessa's shoulder and she is closing up her shop) BARRY: They have a huge parade of flowers every year in Pasadena? VANESSA: To be in the Tournament of Roses, that's every florist's dream! : Up on a float, surrounded by flowers, crowds cheering. BARRY: A tournament. Do the roses compete in athletic events? VANESSA: No. All right, I've got one. How come you don't fly everywhere? BARRY: It's exhausting. Why don't you run everywhere? It's faster. VANESSA: Yeah, OK, I see, I see. All right, your turn. BARRY: TiVo. You can just freeze live TV? That's insane! VANESSA: You don't have that? BARRY: We have Hivo, but it's a disease. It's a horrible, horrible disease. VANESSA: Oh, my. (A human walks by and Barry narrowly avoids him) PASSERBY: Dumb bees! VANESSA: You must want to sting all those jerks. BARRY: We try not to sting. It's usually fatal for us. VANESSA: So you have to watch your temper (They walk into a store) BARRY: Very carefully. You kick a wall, take a walk, : write an angry letter and throw it out. Work through it like any emotion: : Anger, jealousy, lust. (Suddenly an employee(Hector) hits Barry off of Vanessa's shoulder. Hector thinks he's saving Vanessa) VANESSA: (To Barry) Oh, my goodness! Are you OK? (Barry is getting up off the floor) BARRY: Yeah. VANESSA: (To Hector) - What is wrong with you?! HECTOR: (Confused) - It's a bug. VANESSA: He's not bothering anybody. Get out of here, you creep! (Vanessa hits Hector across the face with the magazine he had and then hits him in the head. Hector backs away covering his head) Barry: What was that? A Pic 'N' Save circular? (Vanessa sets Barry back on her shoulder) VANESSA: Yeah, it was. How did you know? BARRY: It felt like about 10 pages. Seventy-five is pretty much our limit. VANESSA: You've really got that down to a science. BARRY: - Oh, we have to. I lost a cousin to Italian Vogue. VANESSA: - I'll bet. (Barry looks to his right and notices there is honey for sale in the aisle) BARRY: What in the name of Mighty Hercules is this? (Barry looks at all the brands of honey, shocked) How did this get here? Cute Bee, Golden Blossom, : Ray Liotta Private Select? (Barry puts his hands up and slowly turns around, a look of disgust on his face) VANESSA: - Is he that actor? BARRY: - I never heard of him. : - Why is this here? VANESSA: - For people. We eat it. BARRY: You don't have enough food of your own?! (Hector looks back and notices that Vanessa is talking to Barry) VANESSA: - Well, yes. BARRY: - How do you get it? VANESSA: - Bees make it. BARRY: - I know who makes it! : And it's hard to make it! : There's heating, cooling, stirring. You need a whole Krelman thing! VANESSA: - It's organic. BARRY: - It's our-ganic! VANESSA: It's just honey, Barry. BARRY: Just what?! : Bees don't know about this! This is stealing! A lot of stealing! : You've taken our homes, schools, hospitals! This is all we have! : And it's on sale?! I'm getting to the bottom of this. : I'm getting to the bottom of all of this! (Flash forward in time; Barry paints his face with black strikes like a soldier and sneaks into the storage section of the store) (Two men, including Hector, are loading boxes into some trucks) : SUPERMARKET EMPLOYEE== Hey, Hector. : - You almost done? HECTOR: - Almost. (Barry takes a step to peak around the corner) (Whispering) He is here. I sense it. : Well, I guess I'll go home now (Hector pretends to walk away by walking in place and speaking loudly) : and just leave this nice honey out, with no one around. BARRY: You're busted, box boy! HECTOR: I knew I heard something! So you can talk! BARRY: I can talk. And now you'll start talking! : Where you getting the sweet stuff? Who's your supplier? HECTOR: I don't understand. I thought we were friends. : The last thing we want to do is upset bees! (Hector takes a thumbtack out of the board behind him and sword-fights Barry. Barry is using his stinger like a sword) : You're too late! It's ours now! BARRY: You, sir, have crossed the wrong sword! HECTOR: You, sir, will be lunch for my iguana, Ignacio! (Barry hits the thumbtack out of Hectors hand and Hector surrenders) Barry: Where is the honey coming from? : Tell me where! HECTOR: (Pointing to leaving truck) Honey Farms! It comes from Honey Farms! (Barry chases after the truck but it is getting away. He flies onto a bicyclists' backpack and he catches up to the truck) CAR DRIVER: (To bicyclist) Crazy person! (Barry flies off and lands on the windshield of the Honey farms truck. Barry looks around and sees dead bugs splattered everywhere) BARRY: What horrible thing has happened here? : These faces, they never knew what hit them. And now : they're on the road to nowhere! (Barry hears a sudden whisper) (Barry looks up and sees Mooseblood, a mosquito playing dead) MOOSEBLOOD: Just keep still. BARRY: What? You're not dead? MOOSEBLOOD: Do I look dead? They will wipe anything that moves. Where you headed? BARRY: To Honey Farms. I am onto something huge here. MOOSEBLOOD: I'm going to Alaska. Moose blood, crazy stuff. Blows your head off! ANOTHER BUG PLAYING DEAD: I'm going to Tacoma. (Barry looks at another bug) BARRY: - And you? MOOSEBLOOD: - He really is dead. BARRY: All right. (Another bug hits the windshield and the drivers notice. They activate the windshield wipers) MOOSEBLOOD== Uh-oh! (The windshield wipers are slowly sliding over the dead bugs and wiping them off) BARRY: - What is that?! MOOSEBLOOD: - Oh, no! : - A wiper! Triple blade! BARRY: - Triple blade? MOOSEBLOOD: Jump on! It's your only chance, bee! (Mooseblood and Barry grab onto the wiper and they hold on as it wipes the windshield) Why does everything have to be so doggone clean?! : How much do you people need to see?! (Bangs on windshield) : Open your eyes! Stick your head out the window! RADIO IN TRUCK: From NPR News in Washington, I'm Carl Kasell. MOOSEBLOOD: But don't kill no more bugs! (Mooseblood and Barry are washed off by the wipr fluid) MOOSEBLOOD: - Bee! BARRY: - Moose blood guy!! (Barry starts screaming as he hangs onto the antenna) (Suddenly it is revealed that a water bug is also hanging on the antenna. There is a pause and then Barry and the water bug both start screaming) TRUCK DRIVER: - You hear something? GUY IN TRUCK: - Like what? TRUCK DRIVER: Like tiny screaming. GUY IN TRUCK: Turn off the radio. (The antenna starts to lower until it gets to low and sinks into the truck. The water bug flies off and Barry is forced to let go and he is blown away. He luckily lands inside a horn on top of the truck where he finds Mooseblood, who was blown into the same place) MOOSEBLOOD: Whassup, bee boy? BARRY: Hey, Blood. (Fast forward in time and we see that Barry is deep in conversation with Mooseblood. They have been sitting in this truck for a while) BARRY: ...Just a row of honey jars, as far as the eye could see. MOOSEBLOOD: Wow! BARRY: I assume wherever this truck goes is where they're getting it. : I mean, that honey's ours. MOOSEBLOOD: - Bees hang tight. BARRY: - We're all jammed in. : It's a close community. MOOSEBLOOD: Not us, man. We on our own. Every mosquito on his own. BARRY: - What if you get in trouble? MOOSEBLOOD: - You a mosquito, you in trouble. : Nobody likes us. They just smack. See a mosquito, smack, smack! BARRY: At least you're out in the world. You must meet girls. MOOSEBLOOD: Mosquito girls try to trade up, get with a moth, dragonfly. : Mosquito girl don't want no mosquito. (An ambulance passes by and it has a blood donation sign on it) You got to be kidding me! : Mooseblood's about to leave the building! So long, bee! (Mooseblood leaves and flies onto the window of the ambulance where there are other mosquito's hanging out) : - Hey, guys! OTHER MOSQUITO: - Mooseblood! MOOSEBLOOD: I knew I'd catch y'all down here. Did you bring your crazy straw? (The truck goes out of view and Barry notices that the truck he's on is pulling into a camp of some sort) TRUCK DRIVER: We throw it in jars, slap a label on it, and it's pretty much pure profit. (Barry flies out) BARRY: What is this place? BEEKEEPER 1#: A bee's got a brain the size of a pinhead. BEEKEEPER #2: They are pinheads! : Pinhead. : - Check out the new smoker. BEEKEEPER #1: - Oh, sweet. That's the one you want. : The Thomas 3000! BARRY: Smoker? BEEKEEPER #1: Ninety puffs a minute, semi-automatic. Twice the nicotine, all the tar. : A couple breaths of this knocks them right out. BEEKEEPER #2: They make the honey, and we make the money. BARRY: "They make the honey, and we make the money"? (The Beekeeper sprays hundreds of cheap miniature apartments with the smoker. The bees are fainting or passing out) Oh, my! : What's going on? Are you OK? (Barry flies into one of the apartment and helps a Bee couple get off the ground. They are coughing and its hard for them to stand) BEE IN APARTMENT: Yeah. It doesn't last too long. BARRY: Do you know you're in a fake hive with fake walls? BEE IN APPARTMENT: Our queen was moved here. We had no choice. (The apartment room is completely empty except for a photo on the wall of the "queen" who is obviously a man in women's clothes) BARRY: This is your queen? That's a man in women's clothes! : That's a drag queen! : What is this? (Barry flies out and he discovers that there are hundreds of these structures, each housing thousands of Bees) Oh, no! : There's hundreds of them! (Barry takes out his camera and takes pictures of these Bee work camps. The beekeepers look very evil in these depictions) Bee honey. : Our honey is being brazenly stolen on a massive scale! : This is worse than anything bears have done! I intend to do something. (Flash forward in time and Barry is showing these pictures to his parents) JANET: Oh, Barry, stop. MARTIN: Who told you humans are taking our honey? That's a rumor. BARRY: Do these look like rumors? (Holds up the pictures) UNCLE CARL: That's a conspiracy theory. These are obviously doctored photos. JANET: How did you get mixed up in this? ADAM: He's been talking to humans. JANET: - What? MARTIN: - Talking to humans?! ADAM: He has a human girlfriend. And they make out! JANET: Make out? Barry! BARRY: We do not. ADAM: - You wish you could. MARTIN: - Whose side are you on? BARRY: The bees! UNCLE CARL: (He has been sitting in the back of the room this entire time) I dated a cricket once in San Antonio. Those crazy legs kept me up all night. JANET: Barry, this is what you want to do with your life? BARRY: I want to do it for all our lives. Nobody works harder than bees! : Dad, I remember you coming home so overworked : your hands were still stirring. You couldn't stop. JANET: I remember that. BARRY: What right do they have to our honey? : We live on two cups a year. They put it in lip balm for no reason whatsoever! ADAM: Even if it's true, what can one bee do? BARRY: Sting them where it really hurts. MARTIN: In the face! The eye! : - That would hurt. BARRY: - No. MARTIN: Up the nose? That's a killer. BARRY: There's only one place you can sting the humans, one place where it matters. (Flash forward a bit in time and we are watching the Bee News) BEE NEWS NARRATOR: Hive at Five, the hive's only full-hour action news source. BEE PROTESTOR: No more bee beards! BEE NEWS NARRATOR: With Bob Bumble at the anchor desk. : Weather with Storm Stinger. : Sports with Buzz Larvi. : And Jeanette Chung. BOB BUMBLE: - Good evening. I'm Bob Bumble. JEANETTE CHUNG: - And I'm Jeanette Chung. BOB BUMBLE: A tri-county bee, Barry Benson, : intends to sue the human race for stealing our honey, : packaging it and profiting from it illegally! JEANETTE CHUNG: Tomorrow night on Bee Larry King, : we'll have three former queens here in our studio, discussing their new book, : Classy Ladies, out this week on Hexagon. (The scene changes to an interview on the news with Bee version of Larry King and Barry) BEE LARRY KING: Tonight we're talking to Barry Benson. : Did you ever think, "I'm a kid from the hive. I can't do this"? BARRY: Bees have never been afraid to change the world. : What about Bee Columbus? Bee Gandhi? Bejesus? BEE LARRY KING: Where I'm from, we'd never sue humans. : We were thinking of stickball or candy stores. BARRY: How old are you? BEE LARRY KING: The bee community is supporting you in this case, : which will be the trial of the bee century. BARRY: You know, they have a Larry King in the human world too. BEE LARRY KING: It's a common name. Next week... BARRY: He looks like you and has a show and suspenders and colored dots... BEE LARRY KING: Next week... BARRY: Glasses, quotes on the bottom from the guest even though you just heard 'em. BEE LARRY KING: Bear Week next week! They're scary, hairy and here, live. (Bee Larry King gets annoyed and flies away offscreen) BARRY: Always leans forward, pointy shoulders, squinty eyes, very Jewish. (Flash forward in time. We see Vanessa enter and Ken enters behind her. They are arguing) KEN: In tennis, you attack at the point of weakness! VANESSA: It was my grandmother, Ken. She's 81. KEN== Honey, her backhand's a joke! I'm not gonna take advantage of that? BARRY: (To Ken) Quiet, please. Actual work going on here. KEN: (Pointing at Barry) - Is that that same bee? VANESSA: - Yes, it is! : I'm helping him sue the human race. BARRY: - Hello. KEN: - Hello, bee. VANESSA: This is Ken. BARRY: (Recalling the "Winter Boots" incident earlier) Yeah, I remember you. Timberland, size ten and a half. Vibram sole, I believe. KEN: (To Vanessa) Why does he talk again? VANESSA: Listen, you better go 'cause we're really busy working. KEN: But it's our yogurt night! VANESSA: (Holding door open for Ken) Bye-bye. KEN: (Yelling) Why is yogurt night so difficult?! (Ken leaves and Vanessa walks over to Barry. His workplace is a mess) VANESSA: You poor thing. You two have been at this for hours! BARRY: Yes, and Adam here has been a huge help. ADAM: - Frosting... - How many sugars? ==BARRY== Just one. I try not to use the competition. : So why are you helping me? VANESSA: Bees have good qualities. : And it takes my mind off the shop. : Instead of flowers, people are giving balloon bouquets now. BARRY: Those are great, if you're three. VANESSA: And artificial flowers. BARRY: - Oh, those just get me psychotic! VANESSA: - Yeah, me too. : BARRY: Bent stingers, pointless pollination. ADAM: Bees must hate those fake things! : Nothing worse than a daffodil that's had work done. : Maybe this could make up for it a little bit. VANESSA: - This lawsuit's a pretty big deal. BARRY: - I guess. ADAM: You sure you want to go through with it? BARRY: Am I sure? When I'm done with the humans, they won't be able : to say, "Honey, I'm home," without paying a royalty! (Flash forward in time and we are watching the human news. The camera shows a crowd outside a courthouse) NEWS REPORTER: It's an incredible scene here in downtown Manhattan, : where the world anxiously waits, because for the first time in history, : we will hear for ourselves if a honeybee can actually speak. (We are no longer watching through a news camera) ADAM: What have we gotten into here, Barry? BARRY: It's pretty big, isn't it? ADAM== (Looking at the hundreds of people around the courthouse) I can't believe how many humans don't work during the day. BARRY: You think billion-dollar multinational food companies have good lawyers? SECURITY GUARD: Everybody needs to stay behind the barricade. (A limousine drives up and a fat man,Layton Montgomery, a honey industry owner gets out and walks past Barry) ADAM: - What's the matter? BARRY: - I don't know, I just got a chill. (Fast forward in time and everyone is in the court) MONTGOMERY: Well, if it isn't the bee team. (To Honey Industry lawyers) You boys work on this? MAN: All rise! The Honorable Judge Bumbleton presiding. JUDGE BUMBLETON: All right. Case number 4475, : Superior Court of New York, Barry Bee Benson v. the Honey Industry : is now in session. : Mr. Montgomery, you're representing the five food companies collectively? MONTGOMERY: A privilege. JUDGE BUMBLETON: Mr. Benson... you're representing all the bees of the world? (Everyone looks closely, they are waiting to see if a Bee can really talk) (Barry makes several buzzing sounds to sound like a Bee) BARRY: I'm kidding. Yes, Your Honor, we're ready to proceed. JUDGE BUMBLBETON: Mr. Montgomery, your opening statement, please. MONTGOMERY: Ladies and gentlemen of the jury, : my grandmother was a simple woman. : Born on a farm, she believed it was man's divine right : to benefit from the bounty of nature God put before us. : If we lived in the topsy-turvy world Mr. Benson imagines, : just think of what would it mean. : I would have to negotiate with the silkworm : for the elastic in my britches! : Talking bee! (Montgomery walks over and looks closely at Barry) : How do we know this isn't some sort of : holographic motion-picture-capture Hollywood wizardry? : They could be using laser beams! : Robotics! Ventriloquism! Cloning! For all we know, : he could be on steroids! JUDGE BUMBLETON: Mr. Benson? BARRY: Ladies and gentlemen, there's no trickery here. : I'm just an ordinary bee. Honey's pretty important to me. : It's important to all bees. We invented it! : We make it. And we protect it with our lives. : Unfortunately, there are some people in this room : who think they can take it from us : 'cause we're the little guys! I'm hoping that, after this is all over, : you'll see how, by taking our honey, you not only take everything we have : but everything we are! JANET== (To Martin) I wish he'd dress like that all the time. So nice! JUDGE BUMBLETON: Call your first witness. BARRY: So, Mr. Klauss Vanderhayden of Honey Farms, big company you have. KLAUSS VANDERHAYDEN: I suppose so. BARRY: I see you also own Honeyburton and Honron! KLAUSS: Yes, they provide beekeepers for our farms. BARRY: Beekeeper. I find that to be a very disturbing term. : I don't imagine you employ any bee-free-ers, do you? KLAUSS: (Quietly) - No. BARRY: - I couldn't hear you. KLAUSS: - No. BARRY: - No. : Because you don't free bees. You keep bees. Not only that, : it seems you thought a bear would be an appropriate image for a jar of honey. KLAUSS: They're very lovable creatures. : Yogi Bear, Fozzie Bear, Build-A-Bear. BARRY: You mean like this? (The bear from Over The Hedge barges in through the back door and it is roaring and standing on its hind legs. It is thrashing its claws and people are screaming. It is being held back by a guard who has the bear on a chain) : (Pointing to the roaring bear) Bears kill bees! : How'd you like his head crashing through your living room?! : Biting into your couch! Spitting out your throw pillows! JUDGE BUMBLETON: OK, that's enough. Take him away. (The bear stops roaring and thrashing and walks out) BARRY: So, Mr. Sting, thank you for being here. Your name intrigues me. : - Where have I heard it before? MR. STING: - I was with a band called The Police. BARRY: But you've never been a police officer, have you? STING: No, I haven't. BARRY: No, you haven't. And so here we have yet another example : of bee culture casually stolen by a human : for nothing more than a prance-about stage name. STING: Oh, please. BARRY: Have you ever been stung, Mr. Sting? : Because I'm feeling a little stung, Sting. : Or should I say... Mr. Gordon M. Sumner! MONTGOMERY: That's not his real name?! You idiots! BARRY: Mr. Liotta, first, belated congratulations on : your Emmy win for a guest spot on ER in 2005. RAY LIOTTA: Thank you. Thank you. BARRY: I see from your resume that you're devilishly handsome : with a churning inner turmoil that's ready to blow. RAY LIOTTA: I enjoy what I do. Is that a crime? BARRY: Not yet it isn't. But is this what it's come to for you? : Exploiting tiny, helpless bees so you don't : have to rehearse your part and learn your lines, sir? RAY LIOTTA: Watch it, Benson! I could blow right now! BARRY: This isn't a goodfella. This is a badfella! (Ray Liotta looses it and tries to grab Barry) RAY LIOTTA: Why doesn't someone just step on this creep, and we can all go home?! JUDGE BUMBLETON: - Order in this court! RAY LIOTTA: - You're all thinking it! (Judge Bumbleton starts banging her gavel) JUDGE BUMBLETON: Order! Order, I say! RAY LIOTTA: - Say it! MAN: - Mr. Liotta, please sit down! (We see a montage of magazines which feature the court case) (Flash forward in time and Barry is back home with Vanessa) BARRY: I think it was awfully nice of that bear to pitch in like that. VANESSA: I think the jury's on our side. BARRY: Are we doing everything right,you know, legally? VANESSA: I'm a florist. BARRY: Right. Well, here's to a great team. VANESSA: To a great team! (Ken walks in from work. He sees Barry and he looks upset when he sees Barry clinking his glass with Vanessa) KEN: Well, hello. VANESSA: - Oh, Ken! BARRY: - Hello! VANESSA: I didn't think you were coming. : No, I was just late. I tried to call, but... (Ken holds up his phone and flips it open. The phone has no charge) ...the battery... VANESSA: I didn't want all this to go to waste, so I called Barry. Luckily, he was free. KEN: Oh, that was lucky. (Ken sits down at the table across from Barry and Vanessa leaves the room) VANESSA: There's a little left. I could heat it up. KEN: (Not taking his eyes off Barry) Yeah, heat it up, sure, whatever. BARRY: So I hear you're quite a tennis player. : I'm not much for the game myself. The ball's a little grabby. KEN: That's where I usually sit. Right... (Points to where Barry is sitting) there. VANESSA: (Calling from other room) Ken, Barry was looking at your resume, : and he agreed with me that eating with chopsticks isn't really a special skill. KEN: (To Barry) You think I don't see what you're doing? BARRY: I know how hard it is to find the right job. We have that in common. KEN: Do we? BARRY: Bees have 100 percent employment, but we do jobs like taking the crud out. KEN: (Menacingly) That's just what I was thinking about doing. (Ken reaches for a fork on the table but knocks if on the floor. He goes to pick it up) VANESSA: Ken, I let Barry borrow your razor for his fuzz. I hope that was all right. (Ken quickly rises back up after hearing this but hits his head on the table and yells) BARRY: I'm going to drain the old stinger. KEN: Yeah, you do that. (Barry flies past Ken to get to the bathroom and Ken freaks out, splashing some of the wine he was using to cool his head in his eyes. He yells in anger) (Barry looks at the magazines featuring his victories in court) BARRY: Look at that. (Barry flies into the bathroom) (He puts his hand on his head but this makes hurts him and makes him even madder. He yells again) (Barry is washing his hands in the sink but then Ken walks in) KEN: You know, you know I've just about had it (Closes bathroom door behind him) with your little mind games. (Ken is menacingly rolling up a magazine) BARRY: (Backing away) - What's that? KEN: - Italian Vogue. BARRY: Mamma mia, that's a lot of pages. KEN: It's a lot of ads. BARRY: Remember what Van said, why is your life more valuable than mine? KEN: That's funny, I just can't seem to recall that! (Ken smashes everything off the sink with the magazine and Barry narrowly escapes) (Ken follows Barry around and tries to hit him with the magazine but he keeps missing) (Ken gets a spray bottle) : I think something stinks in here! BARRY: (Enjoying the spray) I love the smell of flowers. (Ken holds a lighter in front of the spray bottle) KEN: How do you like the smell of flames?! BARRY: Not as much. (Ken fires his make-shift flamethrower but misses Barry, burning the bathroom. He torches the whole room but looses his footing and falls into the bathtub. After getting hit in the head by falling objects 3 times he picks up the shower head, revealing a Water bug hiding under it) WATER BUG: Water bug! Not taking sides! (Barry gets up out of a pile of bathroom supplies and he is wearing a chapstick hat) BARRY: Ken, I'm wearing a Chapstick hat! This is pathetic! (Ken switches the shower head to lethal) KEN: I've got issues! (Ken sprays Barry with the shower head and he crash lands into the toilet) (Ken menacingly looks down into the toilet at Barry) Well, well, well, a royal flush! BARRY: - You're bluffing. KEN: - Am I? (flushes toilet) (Barry grabs a chapstick from the toilet seat and uses it to surf in the flushing toilet) BARRY: Surf's up, dude! (Barry flies out of the toilet on the chapstick and sprays Ken's face with the toilet water) : EW,Poo water! BARRY: That bowl is gnarly. KEN: (Aiming a toilet cleaner at Barry) Except for those dirty yellow rings! (Barry cowers and covers his head and Vanessa runs in and takes the toilet cleaner from Ken just before he hits Barry) VANESSA: Kenneth! What are you doing?! KEN== (Leaning towards Barry) You know, I don't even like honey! I don't eat it! VANESSA: We need to talk! (Vanessa pulls Ken out of the bathroom) : He's just a little bee! : And he happens to be the nicest bee I've met in a long time! KEN: Long time? What are you talking about?! Are there other bugs in your life? VANESSA: No, but there are other things bugging me in life. And you're one of them! KEN: Fine! Talking bees, no yogurt night... : My nerves are fried from riding on this emotional roller coaster! VANESSA: Goodbye, Ken. (Ken huffs and walks out and slams the door. But suddenly he walks back in and stares at Barry) : And for your information, I prefer sugar-free, artificial sweeteners MADE BY MAN! (Ken leaves again and Vanessa leans in towards Barry) VANESSA: I'm sorry about all that. (Ken walks back in again) KEN: I know it's got an aftertaste! I LIKE IT! (Ken leaves for the last time) VANESSA: I always felt there was some kind of barrier between Ken and me. : I couldn't overcome it. Oh, well. : Are you OK for the trial? BARRY: I believe Mr. Montgomery is about out of ideas. (Flash forward in time and Barry, Adam, and Vanessa are back in court) MONTGOMERY-- We would like to call Mr. Barry Benson Bee to the stand. ADAM: Good idea! You can really see why he's considered one of the best lawyers... (Barry stares at Adam) ...Yeah. LAWYER: Layton, you've gotta weave some magic with this jury, or it's gonna be all over. MONTGOMERY: Don't worry. The only thing I have to do to turn this jury around : is to remind them of what they don't like about bees. (To lawyer) - You got the tweezers? LAWYER: - Are you allergic? MONTGOMERY: Only to losing, son. Only to losing. : Mr. Benson Bee, I'll ask you what I think we'd all like to know. : What exactly is your relationship (Points to Vanessa) : to that woman? BARRY: We're friends. MONTGOMERY: - Good friends? BARRY: - Yes. MONTGOMERY: How good? Do you live together? ADAM: Wait a minute... : MONTGOMERY: Are you her little... : ...bedbug? (Adam's stinger starts vibrating. He is agitated) I've seen a bee documentary or two. From what I understand, : doesn't your queen give birth to all the bee children? BARRY: - Yeah, but... MONTGOMERY: (Pointing at Janet and Martin) - So those aren't your real parents! JANET: - Oh, Barry... BARRY: - Yes, they are! ADAM: Hold me back! (Vanessa tries to hold Adam back. He wants to sting Montgomery) MONTGOMERY: You're an illegitimate bee, aren't you, Benson? ADAM: He's denouncing bees! MONTGOMERY: Don't y'all date your cousins? (Montgomery leans over on the jury stand and stares at Adam) VANESSA: - Objection! (Vanessa raises her hand to object but Adam gets free. He flies straight at Montgomery) =ADAM: - I'm going to pincushion this guy! BARRY: Adam, don't! It's what he wants! (Adam stings Montgomery in the butt and he starts thrashing around) MONTGOMERY: Oh, I'm hit!! : Oh, lordy, I am hit! JUDGE BUMBLETON: (Banging gavel) Order! Order! MONTGOMERY: (Overreacting) The venom! The venom is coursing through my veins! : I have been felled by a winged beast of destruction! : You see? You can't treat them like equals! They're striped savages! : Stinging's the only thing they know! It's their way! BARRY: - Adam, stay with me. ADAM: - I can't feel my legs. MONTGOMERY: (Overreacting and throwing his body around the room) What angel of mercy will come forward to suck the poison : from my heaving buttocks? JUDGE BUMLBETON: I will have order in this court. Order! : Order, please! (Flash forward in time and we see a human news reporter) NEWS REPORTER: The case of the honeybees versus the human race : took a pointed turn against the bees : yesterday when one of their legal team stung Layton T. Montgomery. (Adam is laying in a hospital bed and Barry flies in to see him) BARRY: - Hey, buddy. ADAM: - Hey. BARRY: - Is there much pain? ADAM: - Yeah. : I... : I blew the whole case, didn't I? BARRY: It doesn't matter. What matters is you're alive. You could have died. ADAM: I'd be better off dead. Look at me. (A small plastic sword is replaced as Adam's stinger) They got it from the cafeteria downstairs, in a tuna sandwich. : Look, there's a little celery still on it. (Flicks off the celery and sighs) BARRY: What was it like to sting someone? ADAM: I can't explain it. It was all... : All adrenaline and then... and then ecstasy! BARRY: ...All right. ADAM: You think it was all a trap? BARRY: Of course. I'm sorry. I flew us right into this. : What were we thinking? Look at us. We're just a couple of bugs in this world. ADAM: What will the humans do to us if they win? BARRY: I don't know. ADAM: I hear they put the roaches in motels. That doesn't sound so bad. BARRY: Adam, they check in, but they don't check out! ADAM: Oh, my. (Coughs) Could you get a nurse to close that window? BARRY: - Why? ADAM: - The smoke. (We can see that two humans are smoking cigarettes outside) : Bees don't smoke. BARRY: Right. Bees don't smoke. : Bees don't smoke! But some bees are smoking. : That's it! That's our case! ADAM: It is? It's not over? BARRY: Get dressed. I've gotta go somewhere. : Get back to the court and stall. Stall any way you can. (Flash forward in time and Adam is making a paper boat in the courtroom) ADAM: And assuming you've done step 29 correctly, you're ready for the tub! (We see that the jury have each made their own paper boats after being taught how by Adam. They all look confused) JUDGE BUMBLETON: Mr. Flayman. ADAM: Yes? Yes, Your Honor! JUDGE BUMBLETON: Where is the rest of your team? ADAM: (Continues stalling) Well, Your Honor, it's interesting. : Bees are trained to fly haphazardly, : and as a result, we don't make very good time. : I actually heard a funny story about... MONTGOMERY: Your Honor, haven't these ridiculous bugs : taken up enough of this court's valuable time? : How much longer will we allow these absurd shenanigans to go on? : They have presented no compelling evidence to support their charges : against my clients, who run legitimate businesses. : I move for a complete dismissal of this entire case! JUDGE BUMBLETON: Mr. Flayman, I'm afraid I'm going : to have to consider Mr. Montgomery's motion. ADAM: But you can't! We have a terrific case. MONTGOMERY: Where is your proof? Where is the evidence? : Show me the smoking gun! BARRY: (Barry flies in through the door) Hold it, Your Honor! You want a smoking gun? : Here is your smoking gun. (Vanessa walks in holding a bee smoker. She sets it down on the Judge's podium) JUDGE BUMBLETON: What is that? BARRY: It's a bee smoker! MONTGOMERY: (Picks up smoker) What, this? This harmless little contraption? : This couldn't hurt a fly, let alone a bee. (Montgomery accidentally fires it at the bees in the crowd and they faint and cough) (Dozens of reporters start taking pictures of the suffering bees) BARRY: Look at what has happened : to bees who have never been asked, "Smoking or non?" : Is this what nature intended for us? : To be forcibly addicted to smoke machines : and man-made wooden slat work camps? : Living out our lives as honey slaves to the white man? (Barry points to the honey industry owners. One of them is an African American so he awkwardly separates himself from the others) LAWYER: - What are we gonna do? - He's playing the species card. BARRY: Ladies and gentlemen, please, free these bees! ADAM AND VANESSA: Free the bees! Free the bees! BEES IN CROWD: Free the bees! HUMAN JURY: Free the bees! Free the bees! JUDGE BUMBLETON: The court finds in favor of the bees! BARRY: Vanessa, we won! VANESSA: I knew you could do it! High-five! (Vanessa hits Barry hard because her hand is too big) : Sorry. BARRY: (Overjoyed) I'm OK! You know what this means? : All the honey will finally belong to the bees. : Now we won't have to work so hard all the time. MONTGOMERY: This is an unholy perversion of the balance of nature, Benson. : You'll regret this. (Montgomery leaves and Barry goes outside the courtroom. Several reporters start asking Barry questions) REPORTER 1#: Barry, how much honey is out there? BARRY: All right. One at a time. REPORTER 2#: Barry, who are you wearing? BARRY: My sweater is Ralph Lauren, and I have no pants. (Barry flies outside with the paparazzi and Adam and Vanessa stay back) ADAM: (To Vanessa) - What if Montgomery's right? Vanessa: - What do you mean? ADAM: We've been living the bee way a long time, 27 million years. (Flash forward in time and Barry is talking to a man) BUSINESS MAN: Congratulations on your victory. What will you demand as a settlement? BARRY: First, we'll demand a complete shutdown of all bee work camps. (As Barry is talking we see a montage of men putting "closed" tape over the work camps and freeing the bees in the crappy apartments) Then we want back the honey that was ours to begin with, : every last drop. (Men in suits are pushing all the honey of the aisle and into carts) We demand an end to the glorification of the bear as anything more (We see a statue of a bear-shaped honey container being pulled down by bees) than a filthy, smelly, bad-breath stink machine. : We're all aware of what they do in the woods. (We see Winnie the Pooh sharing his honey with Piglet in the cross-hairs of a high-tech sniper rifle) BARRY: (Looking through binoculars) Wait for my signal. : Take him out. (Winnie gets hit by a tranquilizer dart and dramatically falls off the log he was standing on, his tongue hanging out. Piglet looks at Pooh in fear and the Sniper takes the honey.) SNIPER: He'll have nausea for a few hours, then he'll be fine. (Flash forward in time) BARRY: And we will no longer tolerate bee-negative nicknames... (Mr. Sting is sitting at home until he is taken out of his house by the men in suits) STING: But it's just a prance-about stage name! BARRY: ...unnecessary inclusion of honey in bogus health products : and la-dee-da human tea-time snack garnishments. (An old lady is mixing honey into her tea but suddenly men in suits smash her face down on the table and take the honey) OLD LADY: Can't breathe. (A honey truck pulls up to Barry's hive) WORKER: Bring it in, boys! : Hold it right there! Good. : Tap it. (Tons of honey is being pumped into the hive's storage) BEE WORKER 1#: (Honey overflows from the cup) Mr. Buzzwell, we just passed three cups, and there's gallons more coming! : - I think we need to shut down! =BEE WORKER #2= - Shut down? We've never shut down. : Shut down honey production! DEAN BUZZWELL: Stop making honey! (The bees all leave their stations. Two bees run into a room and they put the keys into a machine) Turn your key, sir! (Two worker bees dramatically turn their keys, which opens the button which they press, shutting down the honey-making machines. This is the first time this has ever happened) BEE: ...What do we do now? (Flash forward in time and a Bee is about to jump into a pool full of honey) Cannonball! (The bee gets stuck in the honey and we get a short montage of Bees leaving work) (We see the Pollen Jocks flying but one of them gets a call on his antenna) LOU LU DUVA: (Through "phone") We're shutting honey production! : Mission abort. POLLEN JOCK #1: Aborting pollination and nectar detail. Returning to base. (The Pollen Jocks fly back to the hive) (We get a time lapse of Central Park slowly wilting away as the bees all relax) BARRY: Adam, you wouldn't believe how much honey was out there. ADAM: Oh, yeah? BARRY: What's going on? Where is everybody? (The entire street is deserted) : - Are they out celebrating? ADAM: - They're home. : They don't know what to do. Laying out, sleeping in. : I heard your Uncle Carl was on his way to San Antonio with a cricket. BARRY: At least we got our honey back. ADAM: Sometimes I think, so what if humans liked our honey? Who wouldn't? : It's the greatest thing in the world! I was excited to be part of making it. : This was my new desk. This was my new job. I wanted to do it really well. : And now... : Now I can't. (Flash forward in time and Barry is talking to Vanessa) BARRY: I don't understand why they're not happy. : I thought their lives would be better! : They're doing nothing. It's amazing. Honey really changes people. VANESSA: You don't have any idea what's going on, do you? BARRY: - What did you want to show me? (Vanessa takes Barry to the rooftop where they first had coffee and points to her store) VANESSA: - This. (Points at her flowers. They are all grey and wilting) BARRY: What happened here? VANESSA: That is not the half of it. (Small flash forward in time and Vanessa and Barry are on the roof of her store and she points to Central Park) (We see that Central Park is no longer green and colorful, rather it is grey, brown, and dead-like. It is very depressing to look at) BARRY: Oh, no. Oh, my. : They're all wilting. VANESSA: Doesn't look very good, does it? BARRY: No. VANESSA: And whose fault do you think that is? BARRY: You know, I'm gonna guess bees. VANESSA== (Staring at Barry) Bees? BARRY: Specifically, me. : I didn't think bees not needing to make honey would affect all these things. VANESSA: It's not just flowers. Fruits, vegetables, they all need bees. BARRY: That's our whole SAT test right there. VANESSA: Take away produce, that affects the entire animal kingdom. : And then, of course... BARRY: The human species? : So if there's no more pollination, : it could all just go south here, couldn't it? VANESSA: I know this is also partly my fault. BARRY: How about a suicide pact? VANESSA: How do we do it? BARRY: - I'll sting you, you step on me. VANESSA: - That just kills you twice. BARRY: Right, right. VANESSA: Listen, Barry... sorry, but I gotta get going. (Vanessa leaves) BARRY: (To himself) I had to open my mouth and talk. : Vanessa? : Vanessa? Why are you leaving? Where are you going? (Vanessa is getting into a taxi) VANESSA: To the final Tournament of Roses parade in Pasadena. : They've moved it to this weekend because all the flowers are dying. : It's the last chance I'll ever have to see it. BARRY: Vanessa, I just wanna say I'm sorry. I never meant it to turn out like this. VANESSA: I know. Me neither. (The taxi starts to drive away) BARRY: Tournament of Roses. Roses can't do sports. : Wait a minute. Roses. Roses? : Roses! : Vanessa! (Barry flies after the Taxi) VANESSA: Roses?! : Barry? (Barry is flying outside the window of the taxi) BARRY: - Roses are flowers! VANESSA: - Yes, they are. BARRY: Flowers, bees, pollen! VANESSA: I know. That's why this is the last parade. BARRY: Maybe not. Could you ask him to slow down? VANESSA: Could you slow down? (The taxi driver screeches to a stop and Barry keeps flying forward) : Barry! (Barry flies back to the window) BARRY: OK, I made a huge mistake. This is a total disaster, all my fault. VANESSA: Yes, it kind of is. BARRY: I've ruined the planet. I wanted to help you : with the flower shop. I've made it worse. VANESSA: Actually, it's completely closed down. BARRY: I thought maybe you were remodeling. : But I have another idea, and it's greater than my previous ideas combined. VANESSA: I don't want to hear it! BARRY: All right, they have the roses, the roses have the pollen. : I know every bee, plant and flower bud in this park. : All we gotta do is get what they've got back here with what we've got. : - Bees. VANESSA: - Park. BARRY: - Pollen! VANESSA: - Flowers. BARRY: - Re-pollination! VANESSA: - Across the nation! : Tournament of Roses, Pasadena, California. : They've got nothing but flowers, floats and cotton candy. : Security will be tight. BARRY: I have an idea. (Flash forward in time. Vanessa is about to board a plane which has all the Roses on board. VANESSA: Vanessa Bloome, FTD. (Holds out badge) : Official floral business. It's real. SECURITY GUARD: Sorry, ma'am. Nice brooch. =VANESSA== Thank you. It was a gift. (Barry is revealed to be hiding inside the brooch) (Flash back in time and Barry and Vanessa are discussing their plan) BARRY: Once inside, we just pick the right float. VANESSA: How about The Princess and the Pea? : I could be the princess, and you could be the pea! BARRY: Yes, I got it. : - Where should I sit? GUARD: - What are you? BARRY: - I believe I'm the pea. GUARD: - The pea? VANESSA: It goes under the mattresses. GUARD: - Not in this fairy tale, sweetheart. - I'm getting the marshal. VANESSA: You do that! This whole parade is a fiasco! : Let's see what this baby'll do. (Vanessa drives the float through traffic) GUARD: Hey, what are you doing?! BARRY== Then all we do is blend in with traffic... : ...without arousing suspicion. : Once at the airport, there's no stopping us. (Flash forward in time and Barry and Vanessa are about to get on a plane) SECURITY GUARD: Stop! Security. : - You and your insect pack your float? VANESSA: - Yes. SECURITY GUARD: Has it been in your possession the entire time? VANESSA: - Yes. SECURITY GUARD: Would you remove your shoes? (To Barry) - Remove your stinger. BARRY: - It's part of me. SECURITY GUARD: I know. Just having some fun. Enjoy your flight. (Barry plotting with Vanessa) BARRY: Then if we're lucky, we'll have just enough pollen to do the job. (Flash forward in time and Barry and Vanessa are flying on the plane) Can you believe how lucky we are? We have just enough pollen to do the job! VANESSA: I think this is gonna work. BARRY: It's got to work. CAPTAIN SCOTT: (On intercom) Attention, passengers, this is Captain Scott. : We have a bit of bad weather in New York. : It looks like we'll experience a couple hours delay. VANESSA: Barry, these are cut flowers with no water. They'll never make it. BARRY: I gotta get up there and talk to them. VANESSA== Be careful. (Barry flies right outside the cockpit door) BARRY: Can I get help with the Sky Mall magazine? I'd like to order the talking inflatable nose and ear hair trimmer. (The flight attendant opens the door and walks out and Barry flies into the cockpit unseen) BARRY: Captain, I'm in a real situation. CAPTAIN SCOTT: - What'd you say, Hal? CO-PILOT HAL: - Nothing. (Scott notices Barry and freaks out) CAPTAIN SCOTT: Bee! BARRY: No,no,no, Don't freak out! My entire species... (Captain Scott gets out of his seat and tries to suck Barry into a handheld vacuum) HAL: (To Scott) What are you doing? (Barry lands on Hals hair but Scott sees him. He tries to suck up Barry but instead he sucks up Hals toupee) CAPTAIN SCOTT: Uh-oh. BARRY: - Wait a minute! I'm an attorney! HAL: (Hal doesn't know Barry is on his head) - Who's an attorney? CAPTAIN SCOTT: Don't move. (Scott hits Hal in the face with the vacuum in an attempt to hit Barry. Hal is knocked out and he falls on the life raft button which launches an infalatable boat into Scott, who gets knocked out and falls to the floor. They are both uncounscious.) BARRY: (To himself) Oh, Barry. BARRY: (On intercom, with a Southern accent) Good afternoon, passengers. This is your captain. : Would a Miss Vanessa Bloome in 24B please report to the cockpit? (Vanessa looks confused) (Normal accent) ...And please hurry! (Vanessa opens the door and sees the life raft and the uncounscious pilots) VANESSA: What happened here? BARRY: I tried to talk to them, but then there was a DustBuster, a toupee, a life raft exploded. : Now one's bald, one's in a boat, and they're both unconscious! VANESSA: ...Is that another bee joke? BARRY: - No! : No one's flying the plane! BUD DITCHWATER: (Through radio on plane) This is JFK control tower, Flight 356. What's your status? VANESSA: This is Vanessa Bloome. I'm a florist from New York. BUD: Where's the pilot? VANESSA: He's unconscious, and so is the copilot. BUD: Not good. Does anyone onboard have flight experience? BARRY: As a matter of fact, there is. BUD: - Who's that? BARRY: - Barry Benson. BUD: From the honey trial?! Oh, great. BARRY: Vanessa, this is nothing more than a big metal bee. : It's got giant wings, huge engines. VANESSA: I can't fly a plane. BARRY: - Why not? Isn't John Travolta a pilot? VANESSA: - Yes. BARRY: How hard could it be? (Vanessa sits down and flies for a little bit but we see lightning clouds outside the window) VANESSA: Wait, Barry! We're headed into some lightning. (An ominous lightning storm looms in front of the plane) (We are now watching the Bee News) BOB BUMBLE: This is Bob Bumble. We have some late-breaking news from JFK Airport, : where a suspenseful scene is developing. : Barry Benson, fresh from his legal victory... ADAM: That's Barry! BOB BUMBLE: ...is attempting to land a plane, loaded with people, flowers : and an incapacitated flight crew. JANET, MARTIN, UNCLE CAR AND ADAM: Flowers?! (The scene switches to the human news) REPORTER: (Talking with Bob Bumble) We have a storm in the area and two individuals at the controls : with absolutely no flight experience. BOB BUMBLE: Just a minute. There's a bee on that plane. BUD: I'm quite familiar with Mr. Benson and his no-account compadres. : They've done enough damage. REPORTER: But isn't he your only hope? BUD: Technically, a bee shouldn't be able to fly at all. : Their wings are too small... BARRY: (Through radio) Haven't we heard this a million times? : "The surface area of the wings and body mass make no sense."... BOB BUMBLE: - Get this on the air! BEE: - Got it. BEE NEWS CREW: - Stand by. BEE NEWS CREW: - We're going live! BARRY: (Through radio on TV) ...The way we work may be a mystery to you. : Making honey takes a lot of bees doing a lot of small jobs. : But let me tell you about a small job. : If you do it well, it makes a big difference. : More than we realized. To us, to everyone. : That's why I want to get bees back to working together. : That's the bee way! We're not made of Jell-O. : We get behind a fellow. : - Black and yellow! BEES: - Hello! (The scene switches and Barry is teaching Vanessa how to fly) BARRY: Left, right, down, hover. VANESSA: - Hover? BARRY: - Forget hover. VANESSA: This isn't so hard. (Pretending to honk the horn) Beep-beep! Beep-beep! (A Lightning bolt hits the plane and autopilot turns off) Barry, what happened?! BARRY: Wait, I think we were on autopilot the whole time. VANESSA: - That may have been helping me. BARRY: - And now we're not! VANESSA: So it turns out I cannot fly a plane. (The plane plummets but we see Lou Lu Duva and the Pollen Jocks, along with multiple other bees flying towards the plane) Lou Lu DUva: All of you, let's get behind this fellow! Move it out! : Move out! (The scene switches back to Vanessa and Barry in the plane) BARRY: Our only chance is if I do what I'd do, you copy me with the wings of the plane! (Barry sticks out his arms like an airplane and flys in front of Vanessa's face) VANESSA: Don't have to yell. BARRY: I'm not yelling! We're in a lot of trouble. VANESSA: It's very hard to concentrate with that panicky tone in your voice! BARRY: It's not a tone. I'm panicking! VANESSA: I can't do this! (Barry slaps Vanessa) BARRY: Vanessa, pull yourself together. You have to snap out of it! VANESSA: (Slaps Barry) You snap out of it. BARRY: (Slaps Vanessa) : You snap out of it. VANESSA: - You snap out of it! BARRY: - You snap out of it! (We see that all the Pollen Jocks are flying under the plane) VANESSA: - You snap out of it! BARRY: - You snap out of it! VANESSA: - You snap out of it! BARRY: - You snap out of it! VANESSA: - Hold it! BARRY: - Why? Come on, it's my turn. VANESSA: How is the plane flying? (The plane is now safely flying) VANESSA: I don't know. (Barry's antennae rings like a phone. Barry picks up) BARRY: Hello? LOU LU DUVA: (Through "phone") Benson, got any flowers for a happy occasion in there? (All of the Pollen Jocks are carrying the plane) BARRY: The Pollen Jocks! : They do get behind a fellow. LOU LU DUVA: - Black and yellow. POLLEN JOCKS: - Hello. LOU LU DUVA: All right, let's drop this tin can on the blacktop. BARRY: Where? I can't see anything. Can you? VANESSA: No, nothing. It's all cloudy. : Come on. You got to think bee, Barry. BARRY: - Thinking bee. - Thinking bee. (On the runway there are millions of bees laying on their backs) BEES: Thinking bee! Thinking bee! Thinking bee! BARRY: Wait a minute. I think I'm feeling something. VANESSA: - What? BARRY: - I don't know. It's strong, pulling me. : Like a 27-million-year-old instinct. : Bring the nose down. BEES: Thinking bee! Thinking bee! Thinking bee! CONTROL TOWER OPERATOR: - What in the world is on the tarmac? BUD: - Get some lights on that! (It is revealed that all the bees are organized into a giant pulsating flower formation) BEES: Thinking bee! Thinking bee! Thinking bee! BARRY: - Vanessa, aim for the flower. VANESSA: - OK. BARRY: Out the engines. We're going in on bee power. Ready, boys? LOU LU DUVA: Affirmative! BARRY: Good. Good. Easy, now. That's it. : Land on that flower! : Ready? Full reverse! : Spin it around! (The plane's nose is pointed at a flower painted on a nearby plane) - Not that flower! The other one! VANESSA: - Which one? BARRY: - That flower. (The plane is now pointed at a fat guy in a flowered shirt. He freaks out and tries to take a picture of the plane) VANESSA: - I'm aiming at the flower! BARRY: That's a fat guy in a flowered shirt. I mean the giant pulsating flower made of millions of bees! (The plane hovers over the bee-flower) : Pull forward. Nose down. Tail up. : Rotate around it. VANESSA: - This is insane, Barry! BARRY: - This's the only way I know how to fly. BUD: Am I koo-koo-kachoo, or is this plane flying in an insect-like pattern? (The plane is unrealistically hovering and spinning over the bee-flower) BARRY: Get your nose in there. Don't be afraid. Smell it. Full reverse! : Just drop it. Be a part of it. : Aim for the center! : Now drop it in! Drop it in, woman! : Come on, already. (The bees scatter and the plane safely lands) VANESSA: Barry, we did it! You taught me how to fly! BARRY: - Yes! (Vanessa is about to high-five Barry) No high-five! VANESSA: - Right. ADAM: Barry, it worked! Did you see the giant flower? BARRY: What giant flower? Where? Of course I saw the flower! That was genius! ADAM: - Thank you. BARRY: - But we're not done yet. : Listen, everyone! : This runway is covered with the last pollen : from the last flowers available anywhere on Earth. : That means this is our last chance. : We're the only ones who make honey, pollinate flowers and dress like this. : If we're gonna survive as a species, this is our moment! What do you say? : Are we going to be bees, or just Museum of Natural History keychains? BEES: We're bees! BEE WHO LIKES KEYCHAINS: Keychain! BARRY: Then follow me! Except Keychain. POLLEN JOCK #1: Hold on, Barry. Here. : You've earned this. BARRY: Yeah! : I'm a Pollen Jock! And it's a perfect fit. All I gotta do are the sleeves. (The Pollen Jocks throw Barry a nectar-collecting gun. Barry catches it) Oh, yeah. JANET: That's our Barry. (Barry and the Pollen Jocks get pollen from the flowers on the plane) (Flash forward in time and the Pollen Jocks are flying over NYC) : (Barry pollinates the flowers in Vanessa's shop and then heads to Central Park) BOY IN PARK: Mom! The bees are back! ADAM: (Putting on his Krelman hat) If anybody needs to make a call, now's the time. : I got a feeling we'll be working late tonight! (The bee honey factories are back up and running) (Meanwhile at Vanessa's shop) VANESSA: (To customer) Here's your change. Have a great afternoon! Can I help who's next? : Would you like some honey with that? It is bee-approved. Don't forget these. (There is a room in the shop where Barry does legal work for other animals. He is currently talking with a Cow) COW: Milk, cream, cheese, it's all me. And I don't see a nickel! : Sometimes I just feel like a piece of meat! BARRY: I had no idea. VANESSA: Barry, I'm sorry. Have you got a moment? BARRY: Would you excuse me? My mosquito associate will help you. MOOSEBLOOD: Sorry I'm late. COW: He's a lawyer too? MOOSEBLOOD: Ma'am, I was already a blood-sucking parasite. All I needed was a briefcase. VANESSA: Have a great afternoon! : Barry, I just got this huge tulip order, and I can't get them anywhere. BARRY: No problem, Vannie. Just leave it to me. VANESSA: You're a lifesaver, Barry. Can I help who's next? BARRY: All right, scramble, jocks! It's time to fly. VANESSA: Thank you, Barry! (Ken walks by on the sidewalk and sees the "bee-approved honey" in Vanessa's shop) KEN: That bee is living my life!! ANDY: Let it go, Kenny. KEN: - When will this nightmare end?! ANDY: - Let it all go. BARRY: - Beautiful day to fly. POLLEN JOCK: - Sure is. BARRY: Between you and me, I was dying to get out of that office. (Barry recreates the scene near the beginning of the movie where he flies through the box kite. The movie fades to black and the credits being) [--after credits; No scene can be seen but the characters can be heard talking over the credits--] You have got to start thinking bee, my friend! : - Thinking bee! - Me? BARRY: (Talking over singer) Hold it. Let's just stop for a second. Hold it. : I'm sorry. I'm sorry, everyone. Can we stop here? SINGER: Oh, BarryBARRY: I'm not making a major life decision during a production number! SINGER: All right. Take ten, everybody. Wrap it up, guys. BARRY: I had virtually no rehearsal for that. */ |
submitted at
0 likes
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | #include <iostream> #include <random> #include <string> #include <unordered_map> #include <vector> // A markov state contains words with their weights typedef std::unordered_map<std::string, std::size_t> MarkovState; typedef std::unordered_map<std::string, MarkovState> MarkovChain; MarkovChain markovChain; std::vector<std::string> split_str(const std::string& str, const std::string& delim) { std::size_t current_pos = 0; std::size_t prev_pos = 0; std::vector<std::string> result{}; while((current_pos = str.find(delim, prev_pos)) != std::string::npos) { result.push_back(str.substr(prev_pos, current_pos - prev_pos)); prev_pos = current_pos + delim.size(); } result.push_back(str.substr(prev_pos, current_pos)); return result; } std::string get_next_word(const std::string& last_word) { if(markovChain.count(last_word) == 0) { return ""; } // Weighted random shit static std::random_device dev; static std::mt19937 rng(dev()); std::size_t total_weight = 0; for(auto&[word, weight] : markovChain[last_word]) { total_weight += weight; } std::uniform_int_distribution<std::size_t> dist(0, total_weight - 1); std::size_t random_weight = dist(rng); std::size_t sum = 0; for(auto&[word, weight] : markovChain[last_word]) { if(sum <= random_weight && random_weight < sum + weight) { return word; } sum += weight; } return ""; } void train(const std::string& corpus) { std::vector<std::string> splitted_corpus = split_str(corpus, " "); // Build Markov chain for(std::size_t i = 0; i < splitted_corpus.size() - 1; ++i) { std::string& current_word = splitted_corpus[i]; std::string& next_word = splitted_corpus[i + 1]; markovChain[current_word][next_word]++; } } std::string complete(const std::string& text_so_far, std::size_t len=1) { auto v = split_str(text_so_far, " "); std::string last_word = v[v.size() - 1]; std::string result{}; while(len--) { std::string next_word = get_next_word(last_word); if(next_word.empty()) { return result; } result += (next_word + " "); last_word = next_word; } return result; } int main() { std::string training_text{}; std::string text_so_far{}; std::cout << "Enter training text: "; std::getline(std::cin, training_text); std::cout << "Enter text so far: "; std::getline(std::cin, text_so_far); train(training_text); std::cout << complete(text_so_far, 99) << std::endl; return 0; } |
post a comment