name | correct guesses | games together | ratio |
---|---|---|---|
kimapr | 2 | 4 | 0.500 |
razetime | 2 | 5 | 0.400 |
LyricLy | 2 | 12 | 0.167 |
Olivia | 1 | 8 | 0.125 |
moshikoi | 0 | 7 | 0.000 |
soup girl | 0 | 6 | 0.000 |
JJRubes | 0 | 6 | 0.000 |
luatic | 0 | 5 | 0.000 |
Palaiologos | 0 | 4 | 0.000 |
Dolphy | 0 | 4 | 0.000 |
olus2000 | 0 | 10 | 0.000 |
taswelll | 0 | 4 | 0.000 |
name | correct guesses | games together | ratio |
---|---|---|---|
moshikoi | 7 | 7 | 1.000 |
soup girl | 6 | 6 | 1.000 |
kimapr | 4 | 4 | 1.000 |
luatic | 5 | 5 | 1.000 |
Dolphy | 4 | 4 | 1.000 |
LyricLy | 12 | 12 | 1.000 |
razetime | 5 | 5 | 1.000 |
olus2000 | 9 | 10 | 0.900 |
JJRubes | 5 | 6 | 0.833 |
taswelll | 3 | 4 | 0.750 |
Olivia | 3 | 7 | 0.429 |
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 | #!/usr/bin/sed -nrf :_Problem # Gijswijt's sequence # https://cg.esolangs.gay/66/ :_Restrictions # can only generate the first 219 terms :main 2Q 1 s:.*: 1: h;v b seq_loop :seq_loop /^( [0-9]+){219}$/{ s:^ ::p Q 0 } s:(( [0-9]+)+)\1\1$:@3: s:(( [0-9]+)+)\1$:@2: s:^.*@:: s:^ .*$:1: H;x s:\n: : h b seq_loop |
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 | #!/usr/bin/sed -nrf :_Problem # look-and-say sequence # https://cg.esolangs.gay/64/ :_Restrictions # input N in unary, e.g. 000 instead of 3 (print all terms up to and including Nth) # very slow after the 54th term (regex slowed by increasing number of digits) :main # error handling v /^0+$/! { s/.*/Error: please input N in unary! Use 000 instead of 3./p Q 1 } # init s:^0:: h s:.*:1: b seq_loop :seq_loop # print s:.*:> &:p s:^> :: # stop condition x /^$/Q 0 s:^0:: x # generate next term s:([123])\1*: &@\1:g s: [123]:a:g s:a[123]:b:g s:b[123]:c:g y:abc:123: s:@::g b seq_loop |
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 | #!/usr/bin/sed -nrf #################################################### WARNING #################################################### # Back-up any file before you open it in this editor!! # ################################################################################################################# :_Problem # text editor # https://cg.esolangs.gay/62/ :_Restrictions # run as: FILE="file.txt" ./cg62_editor.sed (stdin used for input of commands) # escape character (\o033) and "EOF" keyword are reserved, can't be in the file # errors aren't handled, they close the editor instantly (no save!) # vertical scrolling isn't implemented, cursor can go out of screen (use file with few lines to test) ################################################# SETUP ######################################################### :init 1v;1x 1b f5 1!b apply_cmd ################################################# COMMANDS ###################################################### :apply_cmd /^u$/ { x;b u } /^uu$/ { x;b uu } /^d$/ { x;b d } /^dd$/ { x;b dd } /^l$/ { x;b l } /^ll$/ { x;b ll } /^r$/ { x;b r } /^rr$/ { x;b rr } /^tab$/ { x;b tab } /^enter$/ { x;b enter } /^i ./ { x;b i } /^k$/ { x;b k } /^kk$/ { x;b kk } /^kkk$/ { x;b kkk } /^clear$/ { x;b clear } /^f5$/ { x;b f5 } /^s$/ { x;b s } /^quit$/ { x;b quit } /^help$/ { x;b help } s@.*@Input error: unknown command!.@p b quit_error :u /^0/b display s:([^\n]*\n?[^\n]*)(\o033\[91m>\o033\[0m):\2\1: s:^(\o033\[91m>\o033\[0m)1:1\1: b display :uu /^1/s:^1(.*)(\o033\[91m>\o033\[0m):1\2\1: b display :d /^1/s:(\o033\[91m>\o033\[0m)([^\n]*\n?):\2\1: b display :dd /^1/s:(\o033\[91m>\o033\[0m)(.*):\2\1: b display :l /^1/s:^(1.*)(.)(\o033\[91m>\o033\[0m):\1\3\2: b display :ll /^0/b display s:([^\n]*)(\o033\[91m>\o033\[0m):\2\1: s:^(\o033\[91m>\o033\[0m)1:1\1: b display :r /^1/s:(\o033\[91m>\o033\[0m)(.):\2\1: b display :rr /^1/s:(\o033\[91m>\o033\[0m)([^\n]*):\2\1: b display :tab /^1/s:\o033\[91m>\o033\[0m:\t&: b display :enter /^1/s:\o033\[91m>\o033\[0m:\n&: b display :i /^0/b display x s:^i :: /\o033/{ s@.*@Input error: ESCAPE is a reserved character!@p b quit_error } /EOF/{ s@.*@Input error: 'EOF' is a reserved keyword!@p b quit_error } G;h;x s:^([^\n]+)\n(1.*)(\o033\[91m>\o033\[0m):\2\1\3: b display :k /^1/s:(\o033\[91m>\o033\[0m).:\1: b display :kk /^1/s:(\o033\[91m>\o033\[0m)[^\n]*:\1: b display :kkk /^1/s:(\o033\[91m>\o033\[0m).*:\1: b display :clear /^1/s:.*:1\o033[91m>\o033[0m: b display :f5 /^0/b display s:.*:cat "$FILE":e #how to test if file doesn't exist? /\o033/{ s@.*@File error: ESCAPE is a reserved character!@p b quit_error } /EOF/{ s@.*@File error: 'EOF' is a reserved keyword!@p b quit_error } s:^:1\o033[91m>\o033[0m: b display :s /^0/b display h;x s:^1:: s:\o033\[91m>\o033\[0m:: s:.*:cat << 'EOF' > "$FILE"\n&\nEOF:e x b display :quit b quit_ok :help /^0/{ s::1: b display } s:^1:0: b display :get_help #this should have been part of :help, but then both pattern and hold space would be occupied #display needs one free space to call to bash and other things, so the help text is JIT generated s:.*:u move cursor to the start of the line above\n: s:$:uu move cursor to the start of the file\n: s:$:d move cursor to the start of the line below\n: s:$:dd move cursor to the end of the file\n\n: s:$:l move cursor to the left\n: s:$:ll move cursor to the start of the current line\n: s:$:r move cursor to the right\n: s:$:rr move cursor to the end of the current line\n\n: s:$:tab insert tab\n: s:$:enter insert enter\n: s:$:i TXT insert TXT characters (except tab and enter)\n\n: s:$:k kill character after the cursor\n: s:$:kk kill all characters after the cursor till the end of the current line\n: s:$:kkk kill all characters after the cursor till the end of the file\n: s:$:clear kill all characters from the file\n\n: s:$:f5 reload content from the file on disk (unsaved changes lost)\n: s:$:s save content to file on disk\n: s:$:quit quit, discarding all changes! (works in help mode)\n\n: s:$:help toggle this help screen (works in help mode): b continue_display ################################################# DISPLAY ####################################################### :display /^1/{ h;x s::: } /^0/{ x b get_help :continue_display } :number_lines_and_wrap #Shit! No time left, let's cheat :D s@.*@cat -n << 'EOF'|sed 's:^[ \t]*::;s:\t:):'|fold -$(tput cols)\n&\nEOF@e #clear screen s:^:\o033[H\o033[J: s@$@\n~\nEnter command (type help for a list of available commands):@p b EOS :get_terminal_stats #sed can't directly access environmental var $FILE and terminal size s:.*:echo "$FILE";tput cols;tput lines:e b#? ################################################# THE END ####################################################### :quit_ok Q 0 :quit_error Q 1 :EOS |
1 2 3 4 5 6 7 8 9 10 11 | #!/usr/bin/sed -nrf s:.*:: :loop y:01:10: x;G s:^\n$:0&: s:(\n)(.*):\2\1:p s:\n$::;h /^(.{255}){255}.*$/!b loop q |
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 | #!/usr/bin/dc -f [Problem]c # spirograph: hypotrochoids and epitrochoids (echo 'R r d' as input*) # https://cg.esolangs.gay/43/ [Restrictions]c # *negative numbers are given using _ prefix, not - which is a dc command # the SVG shape can't be saved to a file, only printed :( [main]c [ #save each input parameter to its own register ?sdsrsR #based on r's sign execute the approppriate shape drawing function 0lr>hlex ]sm #TODO: fix it!! [hypotrochoids]c [ #gen angle range using LCM(r,R)/R as scaling factor lrlRlLxlR/dsf 360*lSx10k #calculate plot coordinates, stored in x and y arrays [ ddddd #calculate x lRlr-rlAxlCx*r lRlr-lr/*lAxlCxld* +r:x #calculate y lRlr-rlAxlCx d*1r-lVxv *r lRlr-lr/*lAxlCx d*1r-lVxv ld* -r:y #loop back if there's still an angle to process z0r>_ ]ds_x #print then quit 0klpxqq ]sh #TODO: fix it!! [epitrochoids]c [ #make r positive lrlVxsr #gen angle range using no (1) scaling factor 1dsf 360*lSx10k #calculate plot coordinates, stored in x and y arrays [ ddddd #calculate x lRlr+rlAxlCx*r lRlr+lr/*lAxlCxld* -r:x #calculate y lRlr+rlAxlCx d*1r-lVxv *r lRlr+lr/*lAxlCx d*1r-lVxv ld* -r:y #loop back if there's still an angle to process z0r>_ ]ds_x #print then quit 0klpxqq ]se [print]c [ #gen angle range lf360*lSx #print SVG header [<?xml version="1.0" encoding="UTF-8" standalone="no"?>]nAP [<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" ]n ["http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">]nAP [<svg width="100" height="100" xmlns="http://www.w3.org/2000/svg" ]n [xmlns:xlink="http://www.w3.org/1999/xlink">]nAP [ <path d="]n #add start point d[M ]n;xn[ ]nr;yn [ #add line segment d[ L ]n;xn[ ]nr;yn #loop back if there's still an angle to process z0r>_ ]ds_x #print SVG footer [ Z"/>]nAP[</svg>]nAP ]sp #TODO: fix it!! ######################### MATH ######################### #3: [stop] -> [0 1 2 3 ... stop] [seq]c [ 0r [ #push increment and float stop to top rd1+3R #push [increment stop] d3Rd_4Rr #loop back if stop != increment !=_ ]ds_x #pop stop d-+ ]sS #2: [a b] -> [GCD] [GCD]c [ #change to [max min] d3Rd_4Rr [r]s_>_ #Euclidean algorithm [ #change to [min max%min] d_3R% #loop back on non-zero remainder d0r>_ ]ds_x #pop remainder (0), GCD=min + ]sG #2: [a b] -> [LCM] [LCM]c [ #push [a b] d3Rd_4Rr #change to [|ab| GCD] *lVx _3RlGx #divide to get LCM / ]sL #1: [a] -> [cos] [COS]c [ 10k #Taylor serie dddddddd*******40320/r dddddd*****720/0r-r dddd***24/r d*2/0r- 1++++0k ]sC #1: [degrees] -> [radians] [d2g]c [ 10k #push 1 rad 180 3.1415926535 / #convert /0k ]sA #1: [a] -> [abs] [abs]c [ 10kd*v0k ]sV ######################################################## lmx |
--- cg38_I-calc_submitted.sed
+++ cg38_I-calc.sed
@@ -78 +78 @@
- \:^([0-9]+)(,.*)(_?[0-9]+)#\1#>-(_?[0-9]+):{ #fix!
+ \:^([0-9]+)(,.*)\b(_?[0-9]+)#\1#>-(_?[0-9]+):{
@@ -80 +79,0 @@
- s:(_?[0-9]+)(><SUB>):\2\1: #ugly workaround, not correct
@@ -90 +89 @@
- \:^([0-9]+)(,.*)(_?[0-9]+)#\1#>\+(_?[0-9]+):{ #fix!
+ \:^([0-9]+)(,.*)\b(_?[0-9]+)#\1#>\+(_?[0-9]+):{
@@ -92 +90,0 @@
- s:(_?[0-9]+)(><ADD>):\2\1: #ugly workaround, not correct
@@ -102 +100 @@
- \:^([0-9]+)(,.*)(_?[0-9]+)#\1#>\*(_?[0-9]+):{ #fix!
+ \:^([0-9]+)(,.*)\b(_?[0-9]+)#\1#>\*(_?[0-9]+):{
@@ -104 +101,0 @@
- s:(_?[0-9]+)(><MULT>):\2\1: #ugly workaround, not correct
@@ -114 +111 @@
- \:^([0-9]+)(,.*)(_?[0-9]+)#\1#>/(_?[0-9]+):{ #fix!
+ \:^([0-9]+)(,.*)\b(_?[0-9]+)#\1#>/(_?[0-9]+):{
@@ -116 +112,0 @@
- s:(_?[0-9]+)(><DIV>):\2\1: #ugly workaround, not correct
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 | #!/usr/bin/sed -nrf :_Problem # I-calc: calculator with I-style operator precedence # https://cg.esolangs.gay/38/ :_Restrictions # Division by zero is currently defined as infinite runtime! # Division rounds down to closest int (ignores sign): truncates! # Incredibly slow computation beyond 4 digit numbers! b DEBUG :main #multiple-digit numbers /[0-9][0-9]+/b undefined #unary operators and uneven whitespace around operators h t loop_u :loop_u s:^[0-9]([ \t]*)[-+*/]\1([0-9]):\2: t loop_u /^[0-9]$/!b undefined g #compute and print expression result \:[-+*/]:b parse_expression :done p b EOS :parse_expression l #loop one operator at a time, using ; to point to one s:^:>: :loop_pe_1 s:>([ \t0-9]+):\1>: #count whitespaces around current operator s:>:#0>: :loop_pe_2 \:(>[-+*/])[ \t]:{ s::\1: s:#([0-9]+)>:#<INCp>\1#result_ip_pe<pCNI>>: b incr_pos :result_ip_pe s:<INCp>([0-9]+)[^<]+<pCNI>:\1: b loop_pe_2 } s:[ \t]*#([0-9]+)>([-+*/]):#\1#\2>: \:>.*[-+*/]:b loop_pe_1 s:>:: l #new counter: highest precedence (0) first, lowest last s:^:-1,: :loop_pe_3 s:^(-?[0-9]+):<INC>\1#result_i_pe<CNI>: b incr :result_i_pe s:<INC>([0-9]+)[^<]+<CNI>:\1: #match operator with whitespaces/precedence = counter s:,:,>: :loop_pe_4 s:>([#_0-9]+):\1>: l b calc_bracket :result_bracket l \:>.*[-+*/]:b loop_pe_4 s:>:: \:[-+*/]:b loop_pe_3 s:[0-9]+,:: s:^_:-: b done #negative numbers are prefixed with _ instead, not - (like in dc) :calc_bracket #sub \:^([0-9]+)(,.*)\b(_?[0-9]+)#\1#>-(_?[0-9]+):{ s::\1\2><SUB>\3 \4#result_s_cb<BUS>: s:(<SUB>)_:\1-: s:(<SUB>-?[0-9]+ )_:\1-: b sub :result_s_cb s:(<SUB>)-:\1_: s:<SUB>(_?[0-9]+)[^<]+<BUS>:\1: b result_bracket } #add \:^([0-9]+)(,.*)\b(_?[0-9]+)#\1#>\+(_?[0-9]+):{ s::\1\2><ADD>\3 \4#result_a_cb<DDA>: s:(<ADD>)_:\1-: s:(<ADD>-?[0-9]+ )_:\1-: b add :result_a_cb s:(<ADD>)-:\1_: s:<ADD>(_?[0-9]+)[^<]+<DDA>:\1: b result_bracket } #mult \:^([0-9]+)(,.*)\b(_?[0-9]+)#\1#>\*(_?[0-9]+):{ s::\1\2><MULT>\3 \4#result_mm_cb<TLUM>: s:(<MULT>)_:\1-: s:(<MULT>-?[0-9]+ )_:\1-: b mult :result_mm_cb s:(<MULT>)-:\1_: s:<MULT>(_?[0-9]+)[^<]+<TLUM>:\1: b result_bracket } #div \:^([0-9]+)(,.*)\b(_?[0-9]+)#\1#>/(_?[0-9]+):{ s::\1\2><DIV>\3 \4#result_dv_cb<VID>: s:(<DIV>)_:\1-: s:(<DIV>-?[0-9]+ )_:\1-: b div :result_dv_cb s:(<DIV>)-:\1_: s:<DIV>(_?[0-9]+)[^<]+<VID>:\1: b result_bracket } s:>([-+*/]):\1>: b result_bracket :undefined s:.*:undefined:p b EOS :user_redirects /##result_ip_pe<pCNI>/b result_ip_pe /##result_i_pe<CNI>/b result_i_pe /##result_s_cb<BUS>/b result_s_cb /##result_a_cb<DDA>/b result_a_cb /##result_mm_cb<TLUM>/b result_mm_cb /##result_dv_cb<VID>/b result_dv_cb b EOS :DEBUG #test if GNU extensions are supported 1v b main ######################### MATH LIB 2.0 ######################### #1-2: <DIV>14 5#label<VID> -> <DIV>2##label<VID> #1-2: <DIV>-27 3#label<VID> -> <DIV>-9##label<VID> #1-2: <DIV>0 -5#label<VID> -> <DIV>0##label<VID> #1-2: <DIV>-15 -5#label<VID> -> <DIV>3##label<VID> #1-2: <DIV>9 0#label<VID> -> INFINITE RUNTIME!! :div s:<DIV>-?[0-9]+:&;: b next_dv :loop_dv /(<DIV>)-([0-9]+) -([0-9]+);/{ s::\1<DIVp>\2 \3#result_dvp_dv_1<pVID>;: b div_pos :result_dvp_dv_1 s:<DIVp>([0-9]+)[^<]+<pVID>:\1: b next_dv } /(<DIV>)-([0-9]+) ([0-9]+);/{ s::\1<DIVp>\2 \3#result_dvp_dv_2<pVID>;: b div_pos :result_dvp_dv_2 s:<DIVp>([0-9]+)[^<]+<pVID>:-\1: b next_dv } /(<DIV>)([0-9]+) -([0-9]+);/{ s::\1<DIVp>\2 \3#result_dvp_dv_3<pVID>;: b div_pos :result_dvp_dv_3 s:<DIVp>0[^<]+<pVID>:0: s:<DIVp>([0-9]+)[^<]+<pVID>:-\1: b next_dv } s:(<DIV>)([0-9]+) ([0-9]+);:\1<DIVp>\2 \3#result_dvp_dv_4<pVID>;: b div_pos :result_dvp_dv_4 s:<DIVp>([0-9]+)[^<]+<pVID>:\1: :next_dv /;#[^<]+<VID>/b print_dv s:(<DIV>[^;]+);( -?[0-9]+):\1\2;: b loop_dv :print_dv s:;(#[^<]+<VID>):#\1: b redirect #1+: <MULT>9 1 -14 -10#label<TLUM> -> <MULT>1260##label<TLUM> :mult s:<MULT>-?[0-9]+:&;: b next_mm :loop_mm /(<MULT>)-([0-9]+) -([0-9]+);/{ s::\1<MULTp>\2 \3#result_mmp_mm_1<pTLUM>;: b mult_pos :result_mmp_mm_1 s:<MULTp>([0-9]+)[^<]+<pTLUM>:\1: b next_mm } /(<MULT>)-([0-9]+) ([0-9]+);/{ s::\1<MULTp>\2 \3#result_mmp_mm_2<pTLUM>;: b mult_pos :result_mmp_mm_2 s:<MULTp>([0-9]+)[^<]+<pTLUM>:-\1: b next_mm } /(<MULT>)([0-9]+) -([0-9]+);/{ s::\1<MULTp>\2 \3#result_mmp_mm_3<pTLUM>;: b mult_pos :result_mmp_mm_3 s:<MULTp>([0-9]+)[^<]+<pTLUM>:-\1: b next_mm } s:(<MULT>)([0-9]+) ([0-9]+);:\1<MULTp>\2 \3#result_mmp_mm_4<pTLUM>;: b mult_pos :result_mmp_mm_4 s:<MULTp>([0-9]+)[^<]+<pTLUM>:\1: :next_mm /;#[^<]+<TLUM>/b print_mm s:(<MULT>[^;]+);( -?[0-9]+):\1\2;: b loop_mm :print_mm s:;(#[^<]+<TLUM>):#\1: b redirect #1-2: <SUB>14 9#label<BUS> -> <SUB>5##label<BUS> #1-2: <SUB>-14 9#label<BUS> -> <SUB>-23##label<BUS> #1-2: <SUB>0 -9#label<BUS> -> <SUB>9##label<BUS> #1-2: <SUB>-14 -9#label<BUS> -> <SUB>-5##label<BUS> :sub s:<SUB>-?[0-9]+:&;: b next_s :loop_s /(<SUB>)-([0-9]+) -([0-9]+);/{ s::\1<SUBp>\3 \2#result_sp_s_1<pBUS>;: b sub_pos :result_sp_s_1 s:<SUBp>(-?[0-9]+)[^<]+<pBUS>:\1: b next_s } /(<SUB>)-([0-9]+) ([0-9]+);/{ s::\1<ADDp>\2 \3#result_ap_s_1<pDDA>;: b add_pos :result_ap_s_1 s:<ADDp>([0-9]+)[^<]+<pDDA>:-\1: b next_s } /(<SUB>)([0-9]+) -([0-9]+);/{ s::\1<ADDp>\2 \3#result_ap_s_2<pDDA>;: b add_pos :result_ap_s_2 s:<ADDp>([0-9]+)[^<]+<pDDA>:\1: b next_s } s:(<SUB>)([0-9]+) ([0-9]+);:\1<SUBp>\2 \3#result_sp_s_2<pBUS>;: b sub_pos :result_sp_s_2 s:<SUBp>(-?[0-9]+)[^<]+<pBUS>:\1: :next_s /;#[^<]+<BUS>/b print_s s:(<SUB>[^;]+);( -?[0-9]+):\1\2;: b loop_s :print_s s:;(#[^<]+<BUS>):#\1: b redirect #1+: <ADD>9 14 0 -8 -16#label<DDA> -> <ADD>-1##label<DDA> :add s:<ADD>-?[0-9]+:&;: b next_a :loop_a /(<ADD>)-([0-9]+) -([0-9]+);/{ s::\1<ADDp>\2 \3#result_ap_a_1<pDDA>;: b add_pos :result_ap_a_1 s:<ADDp>([0-9]+)[^<]+<pDDA>:-\1: b next_a } /(<ADD>)-([0-9]+) ([0-9]+);/{ s::\1<SUBp>\3 \2#result_sp_a_1<pBUS>;: b sub_pos :result_sp_a_1 s:<SUBp>(-?[0-9]+)[^<]+<pBUS>:\1: b next_a } /(<ADD>)([0-9]+) -([0-9]+);/{ s::\1<SUBp>\2 \3#result_sp_a_2<pBUS>;: b sub_pos :result_sp_a_2 s:<SUBp>(-?[0-9]+)[^<]+<pBUS>:\1: b next_a } s:(<ADD>)([0-9]+) ([0-9]+);:\1<ADDp>\2 \3#result_ap_a_2<pDDA>;: b add_pos :result_ap_a_2 s:<ADDp>([0-9]+)[^<]+<pDDA>:\1: :next_a /;#[^<]+<DDA>/b print_a s:(<ADD>[^;]+);( -?[0-9]+):\1\2;: b loop_a :print_a s:;(#[^<]+<DDA>):#\1: b redirect #1+: <MAX>110 34 0 -34 -110#label<XAM> -> <MAX>110##label<XAM> :max s:<MAX>-?[0-9]+:&;: b next_M :loop_M /(<MAX>)-([0-9]+) -([0-9]+);/{ s::\1<MINp>\2 \3#result_mp_M<pNIM>;: b min_pos :result_mp_M s:<MINp>([0-9]+)[^<]+<pNIM>:-\1: b next_M } /(<MAX>)(-[0-9]+) ([0-9]+);/{ s::\1\3;: b next_M } /(<MAX>)([0-9]+) (-[0-9]+);/{ s::\1\2;: b next_M } s:(<MAX>)([0-9]+) ([0-9]+);:\1<MAXp>\2 \3#result_Mp_M<pXAM>;: b max_pos :result_Mp_M s:<MAXp>([0-9]+)[^<]+<pXAM>:\1: :next_M /;#[^<]+<XAM>/b print_M s:(<MAX>[^;]+);( -?[0-9]+):\1\2;: b loop_M :print_M s:;(#[^<]+<XAM>):#\1: b redirect #1+: <MIN>110 34 0 -34 -110#label<NIM> -> <MIN>-110##label<NIM> :min s:<MIN>-?[0-9]+:&;: b next_m :loop_m /(<MIN>)-([0-9]+) -([0-9]+);/{ s::\1<MAXp>\2 \3#result_Mp_m<pXAM>;: b max_pos :result_Mp_m s:<MAXp>([0-9]+)[^<]+<pXAM>:-\1: b next_m } /(<MIN>)(-[0-9]+) ([0-9]+);/{ s::\1\2;: b next_m } /(<MIN>)([0-9]+) (-[0-9]+);/{ s::\1\3;: b next_m } s:(<MIN>)([0-9]+) ([0-9]+);:\1<MINp>\2 \3#result_mp_m<pNIM>;: b min_pos :result_mp_m s:<MINp>([0-9]+)[^<]+<pNIM>:\1: :next_m /;#[^<]+<NIM>/b print_m s:(<MIN>[^;]+);( -?[0-9]+):\1\2;: b loop_m :print_m s:;(#[^<]+<NIM>):#\1: b redirect #1+: <DEC>10 0 -9#label<CED> -> <DEC>9 -1 -10##label<CED> :decr s:<DEC>:&;: :loop_d /<DEC>[^;]*; ?-/{ s:(<DEC>[^;]*; ?)-([0-9]+):\1<INCp>\2#result_ip_d<pCNI>: b incr_pos :result_ip_d s:<INCp>([0-9]+)[^<]+<pCNI>:-\1: b next_d } s:(<DEC>[^;]*; ?)([0-9]+):\1<DECp>\2#result_dp_d<pCED>: b decr_pos :result_dp_d s:<DECp>(-?[0-9]+)[^<]+<pCED>:\1: :next_d s:(<DEC>[^;]*);( ?-?[0-9]+):\1\2;: /;#[^<]+<CED>/!b loop_d s:;(#[^<]+<CED>):#\1: b redirect #1+: <INC>9 0 -10 -1#label<CNI> -> <INC>10 1 -9 0##label<CNI> :incr s:<INC>:&;: :loop_i /<INC>[^;]*; ?-/{ s:(<INC>[^;]*; ?)-([0-9]+):\1<DECp>\2#result_dp_i<pCED>: b decr_pos :result_dp_i s:<DECp>0#[^<]+<pCED>:0: s:<DECp>([0-9]+)[^<]+<pCED>:-\1: b next_i } s:(<INC>[^;]*; ?)([0-9]+):\1<INCp>\2#result_ip_i<pCNI>: b incr_pos :result_ip_i s:<INCp>([0-9]+)[^<]+<pCNI>:\1: :next_i s:(<INC>[^;]*);( ?-?[0-9]+):\1\2;: /;#[^<]+<CNI>/!b loop_i s:;(#[^<]+<CNI>):#\1: b redirect ######################### BASE LIB 2.0 ######################### #1-2: <DIVp>14 5#label<pVID> -> <DIVp>2##label<pVID> #1-2: <DIVp>5 14#label<pVID> -> <DIVp>0##label<pVID> #1-2: <DIVp>9 0#label<pVID> -> INFINITE RUNTIME!! :div_pos #TODO: write a much simpler algorithm, which also handles /0! /(<DIVp>)([0-9]+)#/{ s::\1\2 1,\2 \2#: b print_dvp } s:#[^<]+<pVID>:,1&: :loop_dvp s: ([0-9]+),([0-9]+)(#[^<]+<pVID>): \1,\2 <MULTp>\2 \1#result_mmp_dvp<pTLUM>\3: b mult_pos :result_mmp_dvp s:<MULTp>([0-9]+)[^<]+<pTLUM>:\1: /<DIVp>([0-9]+) [0-9]+,[0-9]+ \1#/b print_dvp s:(<DIVp>)([0-9]+) ([0-9]+),([0-9]+) ([0-9]+):&;<MAXp>\2 \5#result_Mp_dvp<pXAM>: b max_pos :result_Mp_dvp s:<MAXp>([0-9]+)[^<]+<pXAM>:\1: / ([0-9]+);\1#([^<]+<pVID>)/{ s:,([0-9]+) ([0-9]+);[0-9]+(#[^<]+<pVID>):,<DECp>\1#result_dp_dvp<pCED> \2\3: b decr_pos :result_dp_dvp s:<DECp>([0-9]+)[^<]+<pCED>:\1: b print_dvp } s:,([0-9]+) [0-9]+;[0-9]+(#[^<]+<pVID>):,<INCp>\1#result_ip_dvp<pCNI>\2: b incr_pos :result_ip_dvp s:<INCp>([0-9]+)[^<]+<pCNI>:\1: b loop_dvp :print_dvp s:(<DIVp>)[0-9]+ [0-9]+,([0-9]+) [0-9]+:\1\2#: b redirect #1-2: <MULTp>9 14#label<pTLUM> -> <MULTp>126##label<pTLUM> :mult_pos /(<MULTp>)([0-9]+)#/{ s::\10 \2,\2: b print_mmp } s:#[^<]+<pTLUM>:,0&: :loop_mmp /<MULTp>0/b print_mmp s:(<MULTp>)([0-9]+):\1<DECp>\2#result_dp_mmp<pCED>: b decr_pos :result_dp_mmp s:<DECp>([0-9]+)[^<]+<pCED>:\1: s:(<MULTp>[0-9]+ )([0-9]+),([0-9]+):\1\2,<ADDp>\3 \2#result_ap_mmp<pDDA>: b add_pos :result_ap_mmp s:<ADDp>([0-9]+)[^<]+<pDDA>:\1: b loop_mmp :print_mmp s:(<MULTp>)0 [0-9]+,([0-9]+):\1\2#: b redirect #1-2: <SUBp>9 14#label<pBUS> -> <SUBp>-5##label<pBUS> #1-2: <SUBp>14 9#label<pBUS> -> <SUBp>5##label<pBUS> :sub_pos /<SUBp>[0-9]+#/b print_sp :loop_sp /<SUBp>((0 )|([0-9]+ 0))/{ s:(<SUBp>)([0-9]+) 0:\1\2: s:(<SUBp>)0 ([0-9]+):\1-\2: b print_sp } s:(<SUBp>)([0-9]+):\1<DECp>\2#result_dp_sp_1<pCED>: b decr_pos :result_dp_sp_1 s:<DECp>([0-9]+)[^<]+<pCED>:\1: s:(<SUBp>[0-9]+ )([0-9]+):\1<DECp>\2#result_dp_sp_2<pCED>: b decr_pos :result_dp_sp_2 s:<DECp>([0-9]+)[^<]+<pCED>:\1: b loop_sp :print_sp s:#[^<]+<pBUS>:#&: b redirect #1-2: <ADDp>9 14#label<pDDA> -> <ADDp>23##label<pDDA> :add_pos /<ADDp>[0-9]+#/b print_ap :loop_ap /<ADDp>0/{ s:(<ADDp>)0 :\1: b print_ap } s:(<ADDp>)([0-9]+):\1<DECp>\2#result_dp_ap<pCED>: b decr_pos :result_dp_ap s:<DECp>([0-9]+)[^<]+<pCED>:\1: s:(<ADDp>[0-9]+ )([0-9]+):\1<INCp>\2#result_ip_ap<pCNI>: b incr_pos :result_ip_ap s:<INCp>([0-9]+)[^<]+<pCNI>:\1: b loop_ap :print_ap s:#[^<]+<pDDA>:#&: b redirect #1-2: <MAXp>110 34#label<pXAM> -> <MAXp>110##label<pXAM> :max_pos /(<MAXp>)([0-9]+)#/{ s::\1A\2,0B\2,0M\2#: b print_Mp } s:(<MAXp>)([0-9]+) ([0-9]+):\1A\2,\2B\3,\3M\3: :loop_Mp /,0[BM][^<]+<pXAM>/{ s:(<MAXp>)A([0-9]+),[1-9][0-9]*B[0-9]+,0M[0-9]+:\1A0,0B0,0M\2: b print_Mp } s:,([0-9]+)(B[^<]+<pXAM>):,<DECp>\1#result_dp_Mp_1<pCED>\2: b decr_pos :result_dp_Mp_1 s:,<DECp>([0-9]+)#[^<]+<pCED>(B[^<]+<pXAM>):,\1\2: s:,([0-9]+)(M[^<]+<pXAM>):,<DECp>\1#result_dp_Mp_2<pCED>\2: b decr_pos :result_dp_Mp_2 s:,<DECp>([0-9]+)#[^<]+<pCED>(M[^<]+<pXAM>):,\1\2: b loop_Mp :print_Mp s:(<MAXp>)A[0-9]+,[0-9]+B[0-9]+,[0-9]+M([0-9]+):\1\2: s:#[^<]+<pXAM>:#&: b redirect #1-2: <MINp>110 34#label<pNIM> -> <MINp>34##label<pNIM> :min_pos /(<MINp>)([0-9]+)#/{ s::\1A\2,0B\2,0m\2#: b print_mp } s:(<MINp>)([0-9]+) ([0-9]+):\1A\2,\2B\3,\3m\3: :loop_mp /,0[Bm][^<]+<pNIM>/{ s:(<MINp>)A([0-9]+),0B[0-9]+,[1-9][0-9]*m[0-9]+:\1A0,0B0,0m\2: b print_mp } s:,([0-9]+)(B[^<]+<pNIM>):,<DECp>\1#result_dp_mp_1<pCED>\2: b decr_pos :result_dp_mp_1 s:,<DECp>([0-9]+)#[^<]+<pCED>(B[^<]+<pNIM>):,\1\2: s:,([0-9]+)(m[^<]+<pNIM>):,<DECp>\1#result_dp_mp_2<pCED>\2: b decr_pos :result_dp_mp_2 s:,<DECp>([0-9]+)#[^<]+<pCED>(m[^<]+<pNIM>):,\1\2: b loop_mp :print_mp s:(<MINp>)A[0-9]+,[0-9]+B[0-9]+,[0-9]+m([0-9]+):\1\2: s:#[^<]+<pNIM>:#&: b redirect #1: <DECp>10#label<pCED> -> <DECp>9##label<pCED> #1: <DECp>0#label<pCED> -> <DECp>-1##label<pCED> :decr_pos :zeros_dp s:0(@*)(#[^<]+<pCED>):@\1\2: t zeros_dp s:9(@*)(#[^<]+<pCED>):8\1\2:;t print_dp s:8(@*)(#[^<]+<pCED>):7\1\2:;t print_dp s:7(@*)(#[^<]+<pCED>):6\1\2:;t print_dp s:6(@*)(#[^<]+<pCED>):5\1\2:;t print_dp s:5(@*)(#[^<]+<pCED>):4\1\2:;t print_dp s:4(@*)(#[^<]+<pCED>):3\1\2:;t print_dp s:3(@*)(#[^<]+<pCED>):2\1\2:;t print_dp s:2(@*)(#[^<]+<pCED>):1\1\2:;t print_dp s:1(@*)(#[^<]+<pCED>):0\1\2:;t print_dp :print_dp s:(<DECp>)@#:\1-1#: s:(<DECp>)0@:\1@: :loop_dp s:(<DECp>[^#]*)@:\19: /<DECp>[^#]*@/b loop_dp s:#[^<]+<pCED>:#&: b redirect #1: <INCp>9#label<pCNI> -> <INCp>10##label<pCNI> :incr_pos :nines_ip s:9(@*)(#[^<]+<pCNI>):@\1\2: t nines_ip s:0(@*)(#[^<]+<pCNI>):1\1\2:;t print_ip s:1(@*)(#[^<]+<pCNI>):2\1\2:;t print_ip s:2(@*)(#[^<]+<pCNI>):3\1\2:;t print_ip s:3(@*)(#[^<]+<pCNI>):4\1\2:;t print_ip s:4(@*)(#[^<]+<pCNI>):5\1\2:;t print_ip s:5(@*)(#[^<]+<pCNI>):6\1\2:;t print_ip s:6(@*)(#[^<]+<pCNI>):7\1\2:;t print_ip s:7(@*)(#[^<]+<pCNI>):8\1\2:;t print_ip s:8(@*)(#[^<]+<pCNI>):9\1\2:;t print_ip :print_ip s:(<INCp>)@:\11@: :loop_ip s:(<INCp>[^#]*)@:\10: /<INCp>[^#]*@/b loop_ip s:#[^<]+<pCNI>:#&: b redirect ######################### FUNCTION GLUE ######################### :redirect b base_lib_redirects :continue_redirects_1 b math_lib_redirects :continue_redirects_2 b user_redirects :base_lib_redirects /##result_dp_mp_1<pCED>/b result_dp_mp_1 /##result_dp_mp_2<pCED>/b result_dp_mp_2 /##result_dp_Mp_1<pCED>/b result_dp_Mp_1 /##result_dp_Mp_2<pCED>/b result_dp_Mp_2 /##result_dp_ap<pCED>/b result_dp_ap /##result_ip_ap<pCNI>/b result_ip_ap /##result_dp_sp_1<pCED>/b result_dp_sp_1 /##result_dp_sp_2<pCED>/b result_dp_sp_2 /##result_dp_mmp<pCED>/b result_dp_mmp /##result_ap_mmp<pDDA>/b result_ap_mmp /##result_mmp_dvp<pTLUM>/b result_mmp_dvp /##result_Mp_dvp<pXAM>/b result_Mp_dvp /##result_dp_dvp<pCED>/b result_dp_dvp /##result_ip_dvp<pCNI>/b result_ip_dvp b continue_redirects_1 :math_lib_redirects /##result_dp_i<pCED>/b result_dp_i /##result_ip_i<pCNI>/b result_ip_i /##result_ip_d<pCNI>/b result_ip_d /##result_dp_d<pCED>/b result_dp_d /##result_Mp_m<pXAM>/b result_Mp_m /##result_mp_m<pNIM>/b result_mp_m /##result_mp_M<pNIM>/b result_mp_M /##result_Mp_M<pXAM>/b result_Mp_M /##result_ap_a_1<pDDA>/b result_ap_a_1 /##result_ap_a_2<pDDA>/b result_ap_a_2 /##result_sp_a_1<pBUS>/b result_sp_a_1 /##result_sp_a_2<pBUS>/b result_sp_a_2 /##result_ap_s_1<pDDA>/b result_ap_s_1 /##result_ap_s_2<pDDA>/b result_ap_s_2 /##result_sp_s_1<pBUS>/b result_sp_s_1 /##result_sp_s_2<pBUS>/b result_sp_s_2 /##result_mmp_mm_1<pTLUM>/b result_mmp_mm_1 /##result_mmp_mm_2<pTLUM>/b result_mmp_mm_2 /##result_mmp_mm_3<pTLUM>/b result_mmp_mm_3 /##result_mmp_mm_4<pTLUM>/b result_mmp_mm_4 /##result_dvp_dv_1<pVID>/b result_dvp_dv_1 /##result_dvp_dv_2<pVID>/b result_dvp_dv_2 /##result_dvp_dv_3<pVID>/b result_dvp_dv_3 /##result_dvp_dv_4<pVID>/b result_dvp_dv_4 b continue_redirects_2 :EOS :END_OF_SCRIPT #mainly used to skip over remaining code, when needed |
1 2 3 4 5 6 7 8 9 10 11 12 | 2*2 + 1 2 * 2+1 9 / 1+2 - 1 / 2 0-6 * 2 4 / 1 + 1 2-4/2 -4 34 7 1 / 0 9*9*9*9 1+2*3 |
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 | 2*2 + 1$ 2#0#*2#1#+1$ 0,2#0#>*2#1#+1$ 0,>4#1#+1$ 0,4#1#>+1$ 0,4#1#+>1$ 1,4#1#>+1$ 1,>5$ 5 2 * 2+1$ 2#1#*2#0#+1$ 0,2#1#>*2#0#+1$ 0,2#1#*>2#0#+1$ 0,2#1#*2#0#>+1$ 0,2#1#*>3$ 1,2#1#>*3$ 1,>6$ 6 9 / 1+2 - 1 / 2$ 9#1#/1#0#+2#2#-1#4#/2$ 0,9#1#>/1#0#+2#2#-1#4#/2$ 0,9#1#/>1#0#+2#2#-1#4#/2$ 0,9#1#/1#0#>+2#2#-1#4#/2$ 0,9#1#/>3#2#-1#4#/2$ 0,9#1#/3#2#>-1#4#/2$ 0,9#1#/3#2#->1#4#/2$ 0,9#1#/3#2#-1#4#>/2$ 0,9#1#/3#2#-1#4#/>2$ 1,9#1#>/3#2#-1#4#/2$ 1,>3#2#-1#4#/2$ 1,3#2#>-1#4#/2$ 1,3#2#->1#4#/2$ 1,3#2#-1#4#>/2$ 1,3#2#-1#4#/>2$ 2,3#2#>-1#4#/2$ 2,>2#4#/2$ 2,2#4#>/2$ 2,2#4#/>2$ 3,2#4#>/2$ 3,2#4#/>2$ 4,2#4#>/2$ 4,>1$ 1 0-6 * 2$ 0#0#-6#1#*2$ 0,0#0#>-6#1#*2$ 0,>_6#1#*2$ 0,_6#1#>*2$ 0,_6#1#*>2$ 1,_6#1#>*2$ 1,_>12$ -12 4 / 1 + 1$ 4#2#/1#1#+1$ 0,4#2#>/1#1#+1$ 0,4#2#/>1#1#+1$ 0,4#2#/1#1#>+1$ 0,4#2#/1#1#+>1$ 1,4#2#>/1#1#+1$ 1,4#2#/>1#1#+1$ 1,4#2#/1#1#>+1$ 1,4#2#/>2$ 2,4#2#>/2$ 2,>2$ 2 2-4/2$ 2#0#-4#0#/2$ 0,2#0#>-4#0#/2$ 0,>_2#0#/2$ 0,_2#0#>/2$ 0,_>1$ -1 undefined undefined 7 INFINITE RUNTIME!! 9*9*9*9$ 9#0#*9#0#*9#0#*9$ 0,9#0#>*9#0#*9#0#*9$ 0,>81#0#*9#0#*9$ 0,81#0#>*9#0#*9$ 0,>729#0#*9$ 0,729#0#>*9$ 0,>6561$ 6561 1+2*3$ 1#0#+2#0#*3$ 0,1#0#>+2#0#*3$ 0,>3#0#*3$ 0,3#0#>*3$ 0,>9$ 9 |
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 | #!/usr/bin/sed -nrf :_Problem # digital root: sum all digits in a radix until the result is a single digit # https://cg.esolangs.gay/37/ :_Restrictions # Both number and radix are given as input in base 10 # Incredibly slow computation beyond 4 digit numbers! b debug :main b digital_root :return_root s: [0-9]+:\n:p b EOS #x b :digital_root :loop_dr s:^:0,: l b digit_sum :return_sum l s:^([0-9]+),[0-9]+:\1: /^([0-9]+) \1$/!{ s:.*:&<MAX>&#result_dr_Mp<XAM>: b max_pos :result_dr_Mp s:<MAX>([0-9]+).*:@\1: / ([0-9]+)@\1$/b finished s:@[0-9]+:: } b loop_dr :finished s:@[0-9]+:: b return_root #0,x b -> s,x b :digit_sum :loop_ds s:,([0-9]+) ([0-9]+):&<MOD>\1 \2#result_ds_mdp<DOM>: b mod_pos :result_ds_mdp s:<MOD>([0-9]+).*:;\1: s:^([0-9]+)(,[0-9]+ [0-9]+);([0-9]+):\1\2<ADD>\1 \3#result_ds_ap<DDA>: b add_pos :result_ds_ap s:^[0-9]+(,[0-9]+ [0-9]+)<ADD>([0-9]+).*:\2\1: b integer_division :return_quotient /,0 /!b loop_ds b return_sum #s,x b -> s,(x//b) b :integer_division s:$:;0 0: :loop_id s: ([0-9]+);[0-9]+ ([0-9]+):&<ADD>\1 \2#result_id_ap<DDA>: b add_pos :result_id_ap s:(;[0-9]+ )[0-9]+<ADD>([0-9]+).*:\1\2: /,([0-9]+) [0-9]+;[0-9]+ \1$/!{ s:,([0-9]+) [0-9]+;[0-9]+ ([0-9]+):&<MAX>\1 \2#result_id_Mp<XAM>: b max_pos :result_id_Mp s:<MAX>([0-9]+).*:@\1: /([0-9]+)@\1$/b done s:@[0-9]+:: } s:;([0-9]+) [0-9]+:&<INC>\1#result_id_ip<CNI>: b incr_pos :result_id_ip s:;[0-9]+( [0-9]+)<INC>([0-9]+).*:;\2\1: b loop_id :done s:,[0-9]+( [0-9]+);([0-9]+) [0-9]+@[0-9]+:,\2\1: b return_quotient :user_redirects /##result_dr_Mp<XAM>/b result_dr_Mp /##result_ds_mdp<DOM>/b result_ds_mdp /##result_ds_ap<DDA>/b result_ds_ap /##result_id_ap<DDA>/b result_id_ap /##result_id_Mp<XAM>/b result_id_Mp /##result_id_ip<CNI>/b result_id_ip b EOS :debug #test if GNU extensions are supported 1v b main ######################### MATH / UTILS ######################### (most of it was written before cg, used as my standard library :) #4: <LCG>seed a c m#label<GCL> -> <LCG>new_seed##label<GCL> :lcg_pos s:(<LCG>)([0-9]+ [0-9]+):\1<MULT>\2#result_mpp_lcgp<TLUM>: b mult_pos :result_mpp_lcgp s:(<LCG>)<MULT>([0-9]+)[^<]+<TLUM>:\1\2: s:(<LCG>)([0-9]+) ([0-9]+):\1<ADD>\3 \2#result_ap_lcgp<DDA>: b add_pos :result_ap_lcgp s:(<LCG>)<ADD>([0-9]+)[^<]+<DDA>:\1\2: s:(<LCG>)([0-9]+ [0-9]+):\1<MOD>\2#result_mdp_lcgp<DOM>: b mod_pos :result_mdp_lcgp s:(<LCG>)<MOD>([0-9]+)[^<]+<DOM>:\1\2#: b redirect #2: <INTERSECTION>3 4 5,2 3 4 5 6 7 8#label<NOITCESRETNI> -> <INTERSECTION>1##label<NOITCESRETNI> :intersection_pos s:(<INTERSECTION>)([^,]+):\1!\2 : :loop_isp /<INTERSECTION>[^!]+!,/{ s:(<INTERSECTION>)[^#]+:\10: b print_isp } /<INTERSECTION>[^!]*!([0-9]+) [^,]*,[^#]*\b\1\b/{ s:(<INTERSECTION>)[^#]+:\11: b print_isp } s:(<INTERSECTION>[^!]*)!([0-9]+ ):\1\2!: b loop_isp :print_isp s:#[^<]+<NOITCESRETNI>:#&: b redirect #2: <SUBSET>3 4 5,2 3 4 5 6 7 8#label<TESBUS> -> <SUBSET>1##label<TESBUS> :subset_pos s:(<SUBSET>)([^,]+):\1!\2 : :loop_ssp /<SUBSET>[^!]+!,/{ s:(<SUBSET>)[^#]+:\11: b print_ssp } /<SUBSET>[^!]*!([0-9]+) [^,]*,[^#]*\b\1\b/{ s:(<SUBSET>[^!]*)!([0-9]+ ):\1\2!: b loop_ssp } s:(<SUBSET>)[^#]+:\10: :print_ssp s:#[^<]+<TESBUS>:#&: b redirect #1+: <SEQ>3-5,2-8,7-7#label<QES> -> <SEQ>3 4 5,2 3 4 5 6 7 8,7##label<QES> :seq_pos s:<SEQ>:&,: b next_sp :loop_sp /,([0-9]+)<INC>\1#[^<]+<CNI>[^<]+<QES>/b next_sp b incr_pos :result_ip_sp s:(<INC>)([0-9]+)#([^<]+<CNI>)([^,#]+)([^<]+<QES>):\1\2\3\4 \2\5: b loop_sp :next_sp s:,[0-9]+<INC>[^<]+<CNI>([^<]+<QES>):,\1: /,[0-9]+-[0-9]+[,#][^<]+<QES>/!b print_sp s:,([0-9]+)-([0-9]+)([,#][^<]+<QES>):,\2<INC>\1#result_ip_sp<CNI>\1\3: b loop_sp :print_sp s:(<SEQ>),([^#]+)(#[^<]+<QES>):\1\2#\3: b redirect #1+: <MAX>1 2 3#label<XAM> -> <MAX>3##label<XAM> :max_pos s:(<MAX>)([0-9]+#):\10 \2: s: ?([0-9]+) ([0-9]+)(#[^<]+<XAM>):A\1,\1B\2,\2M\2\3: :loop_Mp /,0[BM][^<]+<XAM>/b next_Mp s:,([0-9]+)(B[^<]+<XAM>):,<DEC>\1#result_dp_Mp1<CED>\2: b decr_pos :result_dp_Mp1 s:,<DEC>([0-9]+)#[^<]+<CED>(B[^<]+<XAM>):,\1\2: s:,([0-9]+)(M[^<]+<XAM>):,<DEC>\1#result_dp_Mp2<CED>\2: b decr_pos :result_dp_Mp2 s:,<DEC>([0-9]+)#[^<]+<CED>(M[^<]+<XAM>):,\1\2: b loop_Mp :next_Mp s:A([0-9]+),[1-9][0-9]*B[0-9]+,0M[0-9]+([^<]+<XAM>):A0,0B0,0M\1\2: /<MAX>A/b print_Mp s:B[0-9]+,[0-9]+M([0-9]+)([^<]+<XAM>):B\1,\1M\1\2: s: ?([0-9]+)A[0-9]+,[0-9]+:A\1,\1: b loop_Mp :print_Mp s:A[0-9]+,[0-9]+B[0-9]+,[0-9]+M([0-9]+):\1: s:#[^<]+<XAM>:#&: b redirect #1+: <MIN>1 2 3#label<NIM> -> <MIN>1##label<NIM> :min_pos s:(<MIN>)([0-9]+)#:\1\20 \2#: s:(<MIN>0)0:\1: s: ?([0-9]+) ([0-9]+)(#[^<]+<NIM>):A\1,\1B\2,\2m\2\3: :loop_mp /,0[Bm][^<]+<NIM>/b next_mp #compare lengths first before the dec method s:,([0-9]+)(B[^<]+<NIM>):,<DEC>\1#result_dp_mp1<CED>\2: b decr_pos :result_dp_mp1 s:,<DEC>([0-9]+)#[^<]+<CED>(B[^<]+<NIM>):,\1\2: s:,([0-9]+)(m[^<]+<NIM>):,<DEC>\1#result_dp_mp2<CED>\2: b decr_pos :result_dp_mp2 s:,<DEC>([0-9]+)#[^<]+<CED>(m[^<]+<NIM>):,\1\2: b loop_mp :next_mp s:A([0-9]+),0B[0-9]+,[1-9][0-9]*m[0-9]+([^<]+<NIM>):A0,0B0,0m\1\2: /<MIN>A/b print_mp s:B[0-9]+,[0-9]+m([0-9]+)([^<]+<NIM>):B\1,\1m\1\2: s: ?([0-9]+)A[0-9]+,[0-9]+:A\1,\1: b loop_mp :print_mp s:A[0-9]+,[0-9]+B[0-9]+,[0-9]+m([0-9]+):\1: s:#[^<]+<NIM>:#&: b redirect #2: <MOD>5 2#label<DOM> -> <MOD>1##label<DOM> :mod_pos s:#[^>]+<DOM>:,0 0,0&: :loop_mdp_1 s:(<MOD>[0-9]+ [0-9]+,)([0-9]+) [0-9]+,[0-9]+:\1\2 \2: s:(<MOD>[0-9]+ )([0-9]+),([0-9]+):\1\2,<ADD>\2 \3#result_ap_mdp<DDA>: b add_pos :result_ap_mdp s:<ADD>([0-9]+)[^>]+<DDA>([^>]+<DOM>):\1\2: s:<MOD>([0-9]+) [0-9]+,([0-9]+) [0-9]+:&<MIN>\1 \2#result_mp_mdp<NIM>: b min_pos :result_mp_mdp s:<MIN>([0-9]+)[^>]+<NIM>:,\1: /<MOD>([0-9]+) [0-9]+,[0-9]+ [0-9]+,\1/!b loop_mdp_1 /<MOD>([0-9]+) [0-9]+,\1 / s:(<MOD>[0-9]+ [0-9]+),([0-9]+) [0-9]+:\1,\2 \2: s:(<MOD>[0-9]+) [0-9]+,[0-9]+ ([0-9]+),[0-9]+:\1,\2 0: :loop_mdp_2 /<MOD>([0-9]+),\1/b print_mdp s:(<MOD>)([0-9]+):\1<DEC>\2#result_dp_mdp<CED>: b decr_pos :result_dp_mdp s:<DEC>([0-9]+)[^>]+<CED>:\1: s:(<MOD>[0-9]+,[0-9]+ )([0-9]+):\1<INC>\2#result_ip_mdp<CNI>: b incr_pos :result_ip_mdp s:<INC>([0-9]+)[^>]+<CNI>:\1: b loop_mdp_2 :print_mdp s:(<MOD>)[0-9]+,[0-9]+ ([0-9]+):\1\2#: b redirect #1+: <MULT>2 3 4#label<TLUM> -> <MULT>24##label<TLUM> :mult_pos s:(<MULT>)([0-9]+#):\11 \2: :loop_mpp / ?\b0\b ([0-9]+)(#[^<]+<TLUM>)/{ s:(<MULT>)[^#]+:\1 0: b print_mpp } s: ?([0-9]+) ([0-9]+)(#[^<]+<TLUM>):<ADD>\1 \2#result_ap_mpp<DDA>\3: s:(<ADD>)([0-9]+) ([^<]+<DDA>[^<]+<TLUM>):\1<SEQ>1-\2#result_sp_mpp<QES>\3: b seq_pos :result_sp_mpp s:(<SEQ>)[0-9]+ ?([^#]*[^<]+<QES>)([0-9]+):\3 \1\2\3: /<SEQ>#/!b result_sp_mpp s: <SEQ>[^<]+<QES>[0-9]+:: b add_pos :result_ap_mpp s:<ADD>([^#]+)[^<]+<DDA>: \1: /<MULT>[0-9]+ /b loop_mpp :print_mpp s:(<MULT>) :\1: s:#[^<]+<TLUM>:#&: b redirect #1+: <ADD>1 2 3#label<DDA> -> <ADD>6##label<DDA> :add_pos s:(<ADD>)([0-9]+#):\10 \2: s: ?([0-9]+) ([0-9]+)(#[^<]+<DDA>):<DEC>\1#result_dp_ap<CED><INC>\2#result_ip_ap<CNI>\3: :loop_ap /<DEC>0/b next_ap b decr_pos :result_dp_ap s:#([^<]+<CED>):\1: b incr_pos :result_ip_ap s:#([^<]+<CNI>):\1: b loop_ap :next_ap /<ADD><DEC>/b print_ap s: ?([0-9]+)(<DEC>)0:\2\1: b loop_ap :print_ap s:<DEC>0#result_dp_ap<CED><INC>([0-9]+)#result_ip_ap<CNI>(#[^<]+<DDA>):\1#\2: b redirect #1: <DEC>10#label<CED> -> <DEC>9##label<CED> :decr_pos :zeros s:0(@*)(#[^<]+<CED>):@\1\2: t zeros s:9(@*)(#[^<]+<CED>):8\1\2:;t print_dp s:8(@*)(#[^<]+<CED>):7\1\2:;t print_dp s:7(@*)(#[^<]+<CED>):6\1\2:;t print_dp s:6(@*)(#[^<]+<CED>):5\1\2:;t print_dp s:5(@*)(#[^<]+<CED>):4\1\2:;t print_dp s:4(@*)(#[^<]+<CED>):3\1\2:;t print_dp s:3(@*)(#[^<]+<CED>):2\1\2:;t print_dp s:2(@*)(#[^<]+<CED>):1\1\2:;t print_dp s:1(@*)(#[^<]+<CED>):0\1\2:;t print_dp :print_dp s:(<DEC>)0@:\1@: :loop_dp s:(<DEC>[^#]*)@:\19: /<DEC>[^#]*@/b loop_dp s:#[^<]+<CED>:#&: b redirect #1: <INC>9#label<CNI> -> <INC>10##label<CNI> :incr_pos :nines s:9(@*)(#[^<]+<CNI>):@\1\2: t nines s:0(@*)(#[^<]+<CNI>):1\1\2:;t print_ip s:1(@*)(#[^<]+<CNI>):2\1\2:;t print_ip s:2(@*)(#[^<]+<CNI>):3\1\2:;t print_ip s:3(@*)(#[^<]+<CNI>):4\1\2:;t print_ip s:4(@*)(#[^<]+<CNI>):5\1\2:;t print_ip s:5(@*)(#[^<]+<CNI>):6\1\2:;t print_ip s:6(@*)(#[^<]+<CNI>):7\1\2:;t print_ip s:7(@*)(#[^<]+<CNI>):8\1\2:;t print_ip s:8(@*)(#[^<]+<CNI>):9\1\2:;t print_ip :print_ip s:(<INC>)@:\11@: :loop_ip s:(<INC>[^#]*)@:\10: /<INC>[^#]*@/b loop_ip s:#[^<]+<CNI>:#&: b redirect :redirect b library_redirects :continue_redirects b user_redirects :library_redirects /##result_mpp_lcgp<TLUM>/b result_mpp_lcgp /##result_ap_lcgp<DDA>/b result_ap_lcgp /##result_mdp_lcgp<DOM>/b result_mdp_lcgp /##result_dp_ap<CED>/b result_dp_ap /##result_dp_Mp1<CED>/b result_dp_Mp1 /##result_dp_Mp2<CED>/b result_dp_Mp2 /##result_dp_mp1<CED>/b result_dp_mp1 /##result_dp_mp2<CED>/b result_dp_mp2 /##result_ap_mdp<DDA>/b result_ap_mdp /##result_mp_mdp<NIM>/b result_mp_mdp /##result_dp_mdp<CED>/b result_dp_mdp /##result_ip_mdp<CNI>/b result_ip_mdp /##result_sp_mpp<QES>/b result_sp_mpp /##result_ap_mpp<DDA>/b result_ap_mpp /##result_ip_ap<CNI>/b result_ip_ap /##result_ip_sp<CNI>/b result_ip_sp b continue_redirects :EOS #End Of Script (mainly used to skip over remaining code, when needed) |
1 2 3 4 5 | 7 10 13 16 48 10 103 2 3110 12 |
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 | #!/usr/bin/sed -nrsf :_Problem # sokoban derivative (only the physics system) # https://cg.esolangs.gay/35/ :_Restrictions # Tile values are only in [0-9] range and board size is fixed at 6x6. :main #test if GNU extensions are supported 1v #store input data, then parse the moves (first line) and the board (remaining 6 lines) H 1{ /[WASD]/!{ s/.*/Error: no moves, [WASD]+, found on line 1!/ p;q } } 2,${ /^(-?[0-9][ \t]*){6}$/!{ s/.*/Error: board size must be 6x6, with each tile having a value in [0-9] range!/ p;q } } $!d g s:^\n[^\n]+:: /(\n[^\n]+){6}/!{ s/.*/Error: board size must be 6x6!/ p;q } s:[0-9 \t\n]::g /^-$/!{ s/.*/Error: exactly one tile, the player, must have its value prepended with '-' (negative value)!/ p;q } x s: ::g #print input state s/^\n/\nInput state:\n()/p s:^\n[^\n]+\n\(\):: x s/.*/Intermediary states:/p :loop g #call one_move, save resulting state, then discard the move b one_move :return h;x s:^[WASD]:: x #print intermediary state (skip if output state reached) and loop again if needed s:^[WASD]:(&): /^\([WASD]\)\n/!p /^\([WASD]\)\n/!b loop #print output state s/^/Output state:\n/p b EOS :one_move #index the board s:\n(-?[0-9])(-?[0-9])(-?[0-9])(-?[0-9])(-?[0-9])(-?[0-9])\n:\n,0=\1,1=\2,2=\3,3=\4,4=\5,5=\6\n@: s:@(-?[0-9])(-?[0-9])(-?[0-9])(-?[0-9])(-?[0-9])(-?[0-9])\n:,6=\1,7=\2,8=\3,9=\4,10=\5,11=\6\n@: s:@(-?[0-9])(-?[0-9])(-?[0-9])(-?[0-9])(-?[0-9])(-?[0-9])\n:,12=\1,13=\2,14=\3,15=\4,16=\5,17=\6\n@: s:@(-?[0-9])(-?[0-9])(-?[0-9])(-?[0-9])(-?[0-9])(-?[0-9])\n:,18=\1,19=\2,20=\3,21=\4,22=\5,23=\6\n@: s:@(-?[0-9])(-?[0-9])(-?[0-9])(-?[0-9])(-?[0-9])(-?[0-9])\n:,24=\1,25=\2,26=\3,27=\4,28=\5,29=\6\n@: s:@(-?[0-9])(-?[0-9])(-?[0-9])(-?[0-9])(-?[0-9])(-?[0-9]):,30=\1,31=\2,32=\3,33=\4,34=\5,35=\6: #setup number line and the tile adjacency table (lazy to calculate it) s:$:\nL0112233445566778899L: s:-([0-9])(.*L[0-9]+)\1\1:-\1\2\1-\1: s:$:<ADJ>,0-S6D1,1-S7A0D2,2-S8A1D3,3-S9A2D4,4-S10A3D5,5-S11A4: s:$:,6-W0S12D7,7-W1S13A6D8,8-W2S14A7D9,9-W3S15A8D10,10-W4S16A9D11,11-W5S17A10: s:$:,12-W6S18D13,13-W7S19A12D14,14-W8S20A13D15,15-W9S21A14D16,16-W10S22A15D17,17-W11S23A16: s:$:,18-W12S24D19,19-W13S25A18D20,20-W14S26A19D21,21-W15S27A20D22,22-W16S28A21D23,23-W17S29A22: s:$:,24-W18S30D25,25-W19S31A24D26,26-W20S32A25D27,27-W21S33A26D28,28-W22S34A27D29,29-W23S35A28: s:$:,30-W24D31,31-W25A30D32,32-W26A31D33,33-W27A32D34,34-W28A33D35,35-W29A34,<JDA>: #skip current move since player is already at the edge of the board /^([WASD]).*,([0-9][0-9]?)=-.*<ADJ>.*,\2-[^,]*\1/!{ s/^[WASD]/Warning: current move & is skipped since the player is already at the edge of the board!\n&/ P b skip } s:=-:=+-: :construct_path #from current player/box get the next tile in direction of current move s:^([WASD])(.*,)([0-9][0-9]?)(=\+.*<ADJ>.*,)\3(-[^,]*)\1([0-9][0-9]?):\6\n&: s:=\+:=@: #if next tile is an empty space, the path of tiles to move was finished, call apply_move /^([0-9][0-9]?)\n.*,\1=0/b apply_move #if next tile is a wall, skip current move /^([0-9][0-9]?)\n.*,\1=([0-9]).*L[0-9]+\2[0-9]*-/!{ s/^[^\n]+\n([WASD])/Warning: current move \1 is skipped because of a blocking wall!\n\1/ P b skip } #next tile is a box, mark it with + to become new current box from now on s:^([0-9][0-9]?)(\n.*,)\1=([0-9])(.*L[0-9]+)\3([0-9]*-):\1\2\1=+\3\4\3\5: s:^[^\n]+\n:: #skip current move since current box is already at the edge of the board /^([WASD]).*,([0-9][0-9]?)=\+.*<ADJ>.*,\2-[^,]*\1/!{ s/^[WASD]/Warning: current move & is skipped since last moveable box is already at the edge of the board!\n&/ P b skip } b construct_path :apply_move #transform current move into opposite move, to go from empty space back to player s:\n[WASD]:& ,W->S,S->W,A->D,D->A : s:\n([WASD]) [^\n]*,\1->([WASD])[^\n]* :\n\2\n\1: :shift #call skip to finish, if current tile is already at the edge of the board /^([0-9][0-9]?)\n([WASD]).*<ADJ>.*,\1-[^,]*\2/!{ s:^[^\n]+\n:: b skip } #from current tile get the next tile in opposite direction of current move s:^([0-9][0-9]?)\n([WASD])(.*<ADJ>.*,)\1(-[^,]*)\2([0-9][0-9]?):\1 \5\n\2\3\1\4\2\5: #if next tile isn't marked with @, path was already shifted, call skip to finish /^[0-9][0-9]? ([0-9][0-9]?)\n.*,\1=@/!{ s:^[^\n]+\n:: b skip } #swap values of current tile and next tile, with next tile to become new current tile s:^([0-9][0-9]?) ([0-9][0-9]?)(\n.*,)\1=0(.*,)\2=(@-?[0-9]):\2\3\1=\5\4\2=0: s:^([0-9][0-9]?) ([0-9][0-9]?)(\n.*,)\2=(@-?[0-9])(.*,)\1=0:\2\3\2=0\5\1=\4: b shift :skip s:^[^\n]+\n:: #strip tile markings s:=@:=:g s:=\+:=:g #remove the number line and the tile adjacency table, then strip the board index (for pretty printing back in main) s:\nL.*$:: s:,[0-9][0-9]?=::g b return :EOS #End Of Script (mainly used to skip over remaining code, when needed) |
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 | Input state: ()SAAWWWDDSSSSWWWDSSSWWWDSSS 000000 001000 06-3320 000000 000000 000000 Intermediary states: (S)AAWWWDDSSSSWWWDSSSWWWDSSS 000000 001000 060320 00-3000 000000 000000 (A)AWWWDDSSSSWWWDSSSWWWDSSS 000000 001000 060320 0-30000 000000 000000 (A)WWWDDSSSSWWWDSSSWWWDSSS 000000 001000 060320 -300000 000000 000000 (W)WWDDSSSSWWWDSSSWWWDSSS 000000 001000 -360320 000000 000000 000000 (W)WDDSSSSWWWDSSSWWWDSSS 000000 -301000 060320 000000 000000 000000 (W)DDSSSSWWWDSSSWWWDSSS -300000 001000 060320 000000 000000 000000 (D)DSSSSWWWDSSSWWWDSSS 0-30000 001000 060320 000000 000000 000000 (D)SSSSWWWDSSSWWWDSSS 00-3000 001000 060320 000000 000000 000000 (S)SSSWWWDSSSWWWDSSS 000000 00-3000 061320 000000 000000 000000 (S)SSWWWDSSSWWWDSSS 000000 000000 06-3320 001000 000000 000000 (S)SWWWDSSSWWWDSSS 000000 000000 060320 00-3000 001000 000000 (S)WWWDSSSWWWDSSS 000000 000000 060320 000000 00-3000 001000 (W)WWDSSSWWWDSSS 000000 000000 060320 00-3000 000000 001000 (W)WDSSSWWWDSSS 000000 000000 06-3320 000000 000000 001000 (W)DSSSWWWDSSS 000000 00-3000 060320 000000 000000 001000 (D)SSSWWWDSSS 000000 000-300 060320 000000 000000 001000 (S)SSWWWDSSS 000000 000000 060-320 000300 000000 001000 (S)SWWWDSSS 000000 000000 060020 000-300 000300 001000 (S)WWWDSSS 000000 000000 060020 000000 000-300 001300 (W)WWDSSS 000000 000000 060020 000-300 000000 001300 (W)WDSSS 000000 000000 060-320 000000 000000 001300 (W)DSSS 000000 000-300 060020 000000 000000 001300 (D)SSS 000000 0000-30 060020 000000 000000 001300 (S)SS 000000 000000 0600-30 000020 000000 001300 (S)S 000000 000000 060000 0000-30 000020 001300 Output state: (S) 000000 000000 060000 000000 0000-30 001320 |
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 | Input state: ()W 000000 001000 06-3320 000000 000000 000000 Intermediary states: Output state: (W) 001000 00-3000 060320 000000 000000 000000 Input state: ()S 000000 001000 06-3320 000000 000000 000000 Intermediary states: Output state: (S) 000000 001000 060320 00-3000 000000 000000 Input state: ()A 000000 001000 06-3320 000000 000000 000000 Intermediary states: Warning: current move A is skipped because of a blocking wall! Output state: (A) 000000 001000 06-3320 000000 000000 000000 Input state: ()D 000000 001000 06-3320 000000 000000 000000 Intermediary states: Output state: (D) 000000 001000 060-332 000000 000000 000000 |
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 | #!/usr/bin/sed -nrf :_Problem # fizzbuzz: numbers divisible by 3 replaced with 'Fizz', those by 5 with 'Buzz' and those by 15 with 'FizzBuzz' (first 100 numbers) # https://cg.esolangs.gay/34/ b debug :main 2q s:.*:\n0: :loop_m #increment number s:\n([0-9]+)$:\n<INC>\1#result_ip_m<CNI>: b incr_pos :result_ip_m s:<INC>([0-9]+)[^<]+<CNI>:\1: #divisible by 3? s:\n([0-9]+)$:&,<MOD>\1 3#result_mdp_m1<DOM>: b mod_pos :result_mdp_m1 s:<MOD>([0-9]+)[^<]+<DOM>:\1: s:\n[0-9]+,0$:Fizz&: s:,[0-9]$:: #divisible by 5? s:\n([0-9]+)$:&,<MOD>\1 5#result_mdp_m2<DOM>: b mod_pos :result_mdp_m2 s:<MOD>([0-9]+)[^<]+<DOM>:\1: s:\n[0-9]+,0$:Buzz&: s:,[0-9]$:: #print and prepare for next iteration s:^\n([0-9]+)$:\1&: P s:^[^\n]+:: /\n100$/!b loop_m b EOS :user_redirects /##result_ip_m<CNI>/b result_ip_m /##result_mdp_m1<DOM>/b result_mdp_m1 /##result_mdp_m2<DOM>/b result_mdp_m2 b EOS :debug #test if GNU extensions are supported 1v b main ######################### MATH / UTILS ######################### (most of it was written before cg, used as my standard library :) #4: <LCG>seed a c m#label<GCL> -> <LCG>new_seed##label<GCL> :lcg_pos s:(<LCG>)([0-9]+ [0-9]+):\1<MULT>\2#result_mpp_lcgp<TLUM>: b mult_pos :result_mpp_lcgp s:(<LCG>)<MULT>([0-9]+)[^<]+<TLUM>:\1\2: s:(<LCG>)([0-9]+) ([0-9]+):\1<ADD>\3 \2#result_ap_lcgp<DDA>: b add_pos :result_ap_lcgp s:(<LCG>)<ADD>([0-9]+)[^<]+<DDA>:\1\2: s:(<LCG>)([0-9]+ [0-9]+):\1<MOD>\2#result_mdp_lcgp<DOM>: b mod_pos :result_mdp_lcgp s:(<LCG>)<MOD>([0-9]+)[^<]+<DOM>:\1\2#: b redirect #2: <INTERSECTION>3 4 5,2 3 4 5 6 7 8#label<NOITCESRETNI> -> <INTERSECTION>1##label<NOITCESRETNI> :intersection_pos s:(<INTERSECTION>)([^,]+):\1!\2 : :loop_isp /<INTERSECTION>[^!]+!,/{ s:(<INTERSECTION>)[^#]+:\10: b print_isp } /<INTERSECTION>[^!]*!([0-9]+) [^,]*,[^#]*\b\1\b/{ s:(<INTERSECTION>)[^#]+:\11: b print_isp } s:(<INTERSECTION>[^!]*)!([0-9]+ ):\1\2!: b loop_isp :print_isp s:#[^<]+<NOITCESRETNI>:#&: b redirect #2: <SUBSET>3 4 5,2 3 4 5 6 7 8#label<TESBUS> -> <SUBSET>1##label<TESBUS> :subset_pos s:(<SUBSET>)([^,]+):\1!\2 : :loop_ssp /<SUBSET>[^!]+!,/{ s:(<SUBSET>)[^#]+:\11: b print_ssp } /<SUBSET>[^!]*!([0-9]+) [^,]*,[^#]*\b\1\b/{ s:(<SUBSET>[^!]*)!([0-9]+ ):\1\2!: b loop_ssp } s:(<SUBSET>)[^#]+:\10: :print_ssp s:#[^<]+<TESBUS>:#&: b redirect #1+: <SEQ>3-5,2-8,7-7#label<QES> -> <SEQ>3 4 5,2 3 4 5 6 7 8,7##label<QES> :seq_pos s:<SEQ>:&,: b next_sp :loop_sp /,([0-9]+)<INC>\1#[^<]+<CNI>[^<]+<QES>/b next_sp b incr_pos :result_ip_sp s:(<INC>)([0-9]+)#([^<]+<CNI>)([^,#]+)([^<]+<QES>):\1\2\3\4 \2\5: b loop_sp :next_sp s:,[0-9]+<INC>[^<]+<CNI>([^<]+<QES>):,\1: /,[0-9]+-[0-9]+[,#][^<]+<QES>/!b print_sp s:,([0-9]+)-([0-9]+)([,#][^<]+<QES>):,\2<INC>\1#result_ip_sp<CNI>\1\3: b loop_sp :print_sp s:(<SEQ>),([^#]+)(#[^<]+<QES>):\1\2#\3: b redirect #1+: <MAX>1 2 3#label<XAM> -> <MAX>3##label<XAM> :max_pos s:(<MAX>)([0-9]+#):\10 \2: s: ?([0-9]+) ([0-9]+)(#[^<]+<XAM>):A\1,\1B\2,\2M\2\3: :loop_Mp /,0[BM][^<]+<XAM>/b next_Mp s:,([0-9]+)(B[^<]+<XAM>):,<DEC>\1#result_dp_Mp1<CED>\2: b decr_pos :result_dp_Mp1 s:,<DEC>([0-9]+)#[^<]+<CED>(B[^<]+<XAM>):,\1\2: s:,([0-9]+)(M[^<]+<XAM>):,<DEC>\1#result_dp_Mp2<CED>\2: b decr_pos :result_dp_Mp2 s:,<DEC>([0-9]+)#[^<]+<CED>(M[^<]+<XAM>):,\1\2: b loop_Mp :next_Mp s:A([0-9]+),[1-9][0-9]*B[0-9]+,0M[0-9]+([^<]+<XAM>):A0,0B0,0M\1\2: /<MAX>A/b print_Mp s:B[0-9]+,[0-9]+M([0-9]+)([^<]+<XAM>):B\1,\1M\1\2: s: ?([0-9]+)A[0-9]+,[0-9]+:A\1,\1: b loop_Mp :print_Mp s:A[0-9]+,[0-9]+B[0-9]+,[0-9]+M([0-9]+):\1: s:#[^<]+<XAM>:#&: b redirect #1+: <MIN>1 2 3#label<NIM> -> <MIN>1##label<NIM> :min_pos s:(<MIN>)([0-9]+)#:\1\20 \2#: s:(<MIN>0)0:\1: s: ?([0-9]+) ([0-9]+)(#[^<]+<NIM>):A\1,\1B\2,\2m\2\3: :loop_mp /,0[Bm][^<]+<NIM>/b next_mp #compare lengths first before the dec method s:,([0-9]+)(B[^<]+<NIM>):,<DEC>\1#result_dp_mp1<CED>\2: b decr_pos :result_dp_mp1 s:,<DEC>([0-9]+)#[^<]+<CED>(B[^<]+<NIM>):,\1\2: s:,([0-9]+)(m[^<]+<NIM>):,<DEC>\1#result_dp_mp2<CED>\2: b decr_pos :result_dp_mp2 s:,<DEC>([0-9]+)#[^<]+<CED>(m[^<]+<NIM>):,\1\2: b loop_mp :next_mp s:A([0-9]+),0B[0-9]+,[1-9][0-9]*m[0-9]+([^<]+<NIM>):A0,0B0,0m\1\2: /<MIN>A/b print_mp s:B[0-9]+,[0-9]+m([0-9]+)([^<]+<NIM>):B\1,\1m\1\2: s: ?([0-9]+)A[0-9]+,[0-9]+:A\1,\1: b loop_mp :print_mp s:A[0-9]+,[0-9]+B[0-9]+,[0-9]+m([0-9]+):\1: s:#[^<]+<NIM>:#&: b redirect #2: <MOD>5 2#label<DOM> -> <MOD>1##label<DOM> :mod_pos s:#[^>]+<DOM>:,0 0,0&: :loop_mdp_1 s:(<MOD>[0-9]+ [0-9]+,)([0-9]+) [0-9]+,[0-9]+:\1\2 \2: s:(<MOD>[0-9]+ )([0-9]+),([0-9]+):\1\2,<ADD>\2 \3#result_ap_mdp<DDA>: b add_pos :result_ap_mdp s:<ADD>([0-9]+)[^>]+<DDA>([^>]+<DOM>):\1\2: s:<MOD>([0-9]+) [0-9]+,([0-9]+) [0-9]+:&<MIN>\1 \2#result_mp_mdp<NIM>: b min_pos :result_mp_mdp s:<MIN>([0-9]+)[^>]+<NIM>:,\1: /<MOD>([0-9]+) [0-9]+,[0-9]+ [0-9]+,\1/!b loop_mdp_1 /<MOD>([0-9]+) [0-9]+,\1/ s:(<MOD>[0-9]+ [0-9]+),([0-9]+) [0-9]+:\1,\2 \2: s:(<MOD>[0-9]+) [0-9]+,[0-9]+ ([0-9]+),[0-9]+:\1,\2 0: :loop_mdp_2 /<MOD>([0-9]+),\1/b print_mdp s:(<MOD>)([0-9]+):\1<DEC>\2#result_dp_mdp<CED>: b decr_pos :result_dp_mdp s:<DEC>([0-9]+)[^>]+<CED>:\1: s:(<MOD>[0-9]+,[0-9]+ )([0-9]+):\1<INC>\2#result_ip_mdp<CNI>: b incr_pos :result_ip_mdp s:<INC>([0-9]+)[^>]+<CNI>:\1: b loop_mdp_2 :print_mdp s:(<MOD>)[0-9]+,[0-9]+ ([0-9]+):\1\2#: b redirect #1+: <MULT>2 3 4#label<TLUM> -> <MULT>24##label<TLUM> :mult_pos s:(<MULT>)([0-9]+#):\11 \2: :loop_mpp / ?\b0\b ([0-9]+)(#[^<]+<TLUM>)/{ s:(<MULT>)[^#]+:\1 0: b print_mpp } s: ?([0-9]+) ([0-9]+)(#[^<]+<TLUM>):<ADD>\1 \2#result_ap_mpp<DDA>\3: s:(<ADD>)([0-9]+) ([^<]+<DDA>[^<]+<TLUM>):\1<SEQ>1-\2#result_sp_mpp<QES>\3: b seq_pos :result_sp_mpp s:(<SEQ>)[0-9]+ ?([^#]*[^<]+<QES>)([0-9]+):\3 \1\2\3: /<SEQ>#/!b result_sp_mpp s: <SEQ>[^<]+<QES>[0-9]+:: b add_pos :result_ap_mpp s:<ADD>([^#]+)[^<]+<DDA>: \1: /<MULT>[0-9]+ /b loop_mpp :print_mpp s:(<MULT>) :\1: s:#[^<]+<TLUM>:#&: b redirect #1+: <ADD>1 2 3#label<DDA> -> <ADD>6##label<DDA> :add_pos s:(<ADD>)([0-9]+#):\10 \2: s: ?([0-9]+) ([0-9]+)(#[^<]+<DDA>):<DEC>\1#result_dp_ap<CED><INC>\2#result_ip_ap<CNI>\3: :loop_ap /<DEC>0/b next_ap b decr_pos :result_dp_ap s:#([^<]+<CED>):\1: b incr_pos :result_ip_ap s:#([^<]+<CNI>):\1: b loop_ap :next_ap /<ADD><DEC>/b print_ap s: ?([0-9]+)(<DEC>)0:\2\1: b loop_ap :print_ap s:<DEC>0#result_dp_ap<CED><INC>([0-9]+)#result_ip_ap<CNI>(#[^<]+<DDA>):\1#\2: b redirect #1: <DEC>10#label<CED> -> <DEC>9##label<CED> :decr_pos :zeros s:0(@*)(#[^<]+<CED>):@\1\2: t zeros s:9(@*)(#[^<]+<CED>):8\1\2:;t print_dp s:8(@*)(#[^<]+<CED>):7\1\2:;t print_dp s:7(@*)(#[^<]+<CED>):6\1\2:;t print_dp s:6(@*)(#[^<]+<CED>):5\1\2:;t print_dp s:5(@*)(#[^<]+<CED>):4\1\2:;t print_dp s:4(@*)(#[^<]+<CED>):3\1\2:;t print_dp s:3(@*)(#[^<]+<CED>):2\1\2:;t print_dp s:2(@*)(#[^<]+<CED>):1\1\2:;t print_dp s:1(@*)(#[^<]+<CED>):0\1\2:;t print_dp :print_dp s:(<DEC>)0@:\1@: :loop_dp s:(<DEC>[^#]*)@:\19: /<DEC>[^#]*@/b loop_dp s:#[^<]+<CED>:#&: b redirect #1: <INC>9#label<CNI> -> <INC>10##label<CNI> :incr_pos :nines s:9(@*)(#[^<]+<CNI>):@\1\2: t nines s:0(@*)(#[^<]+<CNI>):1\1\2:;t print_ip s:1(@*)(#[^<]+<CNI>):2\1\2:;t print_ip s:2(@*)(#[^<]+<CNI>):3\1\2:;t print_ip s:3(@*)(#[^<]+<CNI>):4\1\2:;t print_ip s:4(@*)(#[^<]+<CNI>):5\1\2:;t print_ip s:5(@*)(#[^<]+<CNI>):6\1\2:;t print_ip s:6(@*)(#[^<]+<CNI>):7\1\2:;t print_ip s:7(@*)(#[^<]+<CNI>):8\1\2:;t print_ip s:8(@*)(#[^<]+<CNI>):9\1\2:;t print_ip :print_ip s:(<INC>)@:\11@: :loop_ip s:(<INC>[^#]*)@:\10: /<INC>[^#]*@/b loop_ip s:#[^<]+<CNI>:#&: b redirect :redirect b library_redirects :continue_redirects b user_redirects :library_redirects /##result_mpp_lcgp<TLUM>/b result_mpp_lcgp /##result_ap_lcgp<DDA>/b result_ap_lcgp /##result_mdp_lcgp<DOM>/b result_mdp_lcgp /##result_dp_ap<CED>/b result_dp_ap /##result_dp_Mp1<CED>/b result_dp_Mp1 /##result_dp_Mp2<CED>/b result_dp_Mp2 /##result_dp_mp1<CED>/b result_dp_mp1 /##result_dp_mp2<CED>/b result_dp_mp2 /##result_ap_mdp<DDA>/b result_ap_mdp /##result_mp_mdp<NIM>/b result_mp_mdp /##result_dp_mdp<CED>/b result_dp_mdp /##result_ip_mdp<CNI>/b result_ip_mdp /##result_sp_mpp<QES>/b result_sp_mpp /##result_ap_mpp<DDA>/b result_ap_mpp /##result_ip_ap<CNI>/b result_ip_ap /##result_ip_sp<CNI>/b result_ip_sp b continue_redirects :EOS #End Of Script (mainly used to skip over remaining code, when needed) |
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 | #!/usr/bin/dc -f [Problem]c # OISC (Tape first line, syntax after: <current state> <current cell> <new cell> <tape movement> <new state>. See attached example scripts.) # https://cg.esolangs.gay/33/ [Restrictions]c # Only [0-9] values are allowed for tape cells and state (0 being the termination state). For movement only 1:left, 2:stay and 3:right. # Tape length and maximum number of iterations are small for debugging purposes, but can be increased. # Script comments and presence of empty lines aren't supported. One can hack dc to write a form of comment, see attached example scripts. [setup]c #custom exits (working with q in variable execution depths is a nightmare) [n10P q]se [n 0sk 2Q]sf #set starting state, tape pointer, tape length and 0 value for each cell 1ss 0sp 60st ltsc[lc1-dsc0r:Tlc0!=z]szlzx #store script tape from first line ? z d[Error: tape must contain at least one cell!]r0=e X+ sc[ 0sk d1+z[Error: tape cell can't have a string value! Use [0-9] instead.]rlc2+=f X+d-+ d[Error: tape cell must have a [0-9] value!]r9<f X+ d[Error: tape cell must have a [0-9] value!]r0>f X+ 1sk lc1-dsc:Tlc0!=z ]szlzx []lk0=ec #store all script instructions in one array and store its length (instructions are one per line and same length of 5 values) 0sa 0sb 0sc 0si [ 0sk zsh d1+z[Error: instruction value can't be a string! Use [0-9] instead.]rlh2+=f X+d-+ d[Error: instruction value must be [0-9]!]r9<f X+ d[Error: instruction value must be [0-9]!]r0>f X+ 1sk 0sh lc1-dsc:Ilcla!=x ]sx [ ? z dli+si 0sk #can't do 5!= because on empty lines and especially at end of file there will be 0 values (used to exit this macro) d[Error: instruction must be exactly 5 space separated values!]r1=f X+ d[Error: instruction must be exactly 5 space separated values!]r2=f X+ d[Error: instruction must be exactly 5 space separated values!]r3=f X+ d[Error: instruction must be exactly 5 space separated values!]r4=f X+ d[Error: instruction must be exactly 5 space separated values!]r5<f X+ 1sk lb+dsbsc z0!=x []lk0=fc lbsa lblc!=z ]szlzx []lk0=ec lid[Error: there must be at least one instruction!]r0=e X+ 0sk c #set instruction pointer and maximum number of iterations a script could run (infinite loops are easily possible) _1sq 1000sm [printing]c [ #debug printing [[*]n]sx [state: ]nlsn[, tape:]n 0sc[[ ]nlclp=xlcd;Tn1+dsclt!=z]szlzx 10P [instructions: ]n 0sc[[ ]nlclq1+=xlcd;In1+dscli!=z]szlzx 10P ]sd [ #final printing and soft quit (often called more than once; dc might complain, but it does the job in the end) lk1=d 0sk 3Q ]sg [ #print error and call quit n10P lgx ]se [main]c [ lq+sq #decrement iteration counter and quit if limit was reached (value 0) lm1-dsm0=g 2Q ]sn [ 1sk ldx [ #check if current state matches instruction's <current state> 4 lq1+dsq;I ls!=n #check if current cell matches the value of the instruction's <current cell> 3 lq1+dsq;I lp;T!=n #change the current cell's value to that of the instruction's <new cell> value lq1+dsq;I lp:T #apply <tape movement> lq1+dsq;I d[Error: tape movement must have a [1-3] value!]r3<e X+ d[Error: tape movement must have a [1-3] value!]r1>e X+ _2+lp+ d[Error: tape pointer can't go anymore to the left!]r0>e X+ d[Error: tape pointer can't go anymore to the right!]rlt<e X+ sp #apply <new state> and exit if it is 0 (the termination state) lq1+dsq;I ss ls0=g #reset instruction pointer _1sq ]x #artificially nested macro only needed for the soft quit lk0=g lqli1-!=r lk0=g [Error: no instruction matched!]0 0=e ]srlrx c |
1 2 3 4 | 1 0 0 1 0 1 1 1 2 [tape is set on first line (abusing data=code mode of dc to write comments, that are otherwise not implemented)]X+ 1 0 1 3 1 [in starting state 1, check if the current cell is either 0 or 1 and replace it with 1 or 0 respectively; then move right]X+ 1 1 0 3 1 1 2 2 1 0 [if current cell is 2, a way to represent the end of the binary sequence on the tape, go left and change to state 0 (exit)]X+ |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | 2 7 4 0 [number (274) is put on tape one digit per cell, with 0 in this case used to represent end of number; plus the result at the end]X+ 1 1 1 3 1 [in starting state 1 no tape change is done, only navigating to the end of the number]X+ 1 2 2 3 1 1 3 3 3 1 1 4 4 3 1 1 5 5 3 1 1 6 6 3 1 1 7 7 3 1 1 8 8 3 1 1 9 9 3 1 1 0 0 1 2 [end token (value 0) reached, go left and switch to state 2]X+ 2 2 2 3 4 [from state 2 go to state 4, if the end digit is even, or state 5 if odd]X+ 2 4 4 3 4 2 6 6 3 4 2 8 8 3 4 [if the number would have ended in 0, a change in this script and a different end token would have been needed!]X+ 2 1 1 3 5 2 3 3 3 5 2 5 5 3 5 2 7 7 3 5 2 9 9 3 5 4 0 1 2 0 [in state 4 change the end token to 1 (true, even), now representing the result, then change to state 0 (exit)]X+ 5 0 0 2 0 [in state 5 change the end token to 0 (false, odd), then exit]X+ |
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 | #!/usr/bin/sed -nrf :_Problem # maze generator # https://cg.esolangs.gay/32/ :_Restrictions # Fixed 9x9 size. At this size most mazes will have a trivial solution. # Generation is astronomically slow with own RNG. I can use smaller values in LCG, but it forms loops quickly. Default: system RNG. # Initial seed passed to script must be [0-9], for convenience. With system RNG you still might have to wait 5-10 minutes to complete. b debug :main 1h #9x9 maze setup, each cell is numbered s:.*: <SEQ>0-80#result_sp_m<QES> : b seq_pos :result_sp_m s:<SEQ>([^#]+)[^<]+<QES>:\1: y: :#: s:#(8|17|26|35|44|53|62|71|80)#:&\n###################\n#:g s:^:###################\n: s:\n#$:: #initial [0-9] seed and LCG(19,18,129)? setup x 1{ s:^.*(.)$:\1: /^[0-9]$/!{ s:.*:Please give as input a seed between 0 and 9!:p b EOS } s:^[0-9]$:<LCG>& 19 18 129<GCL> 19 18 129: } #adjacency table (no time to calculate it, especially for the sides; top side would even run in negative numbers, not supported atm by my lib) s:$:<ADJ>,0-D9R1,1-D10L0R2,2-D11L1R3,3-D12L2R4,4-D13L3R5,5-D14L4R6,6-D15L5R7,7-D16L6R8,8-D17L7,9-U0D18R10,10-U1D19L9R11,11-U2D20L10R12,12-U3D21L11R13,13-U4D22L12R14,14-U5D23L13R15,15-U6D24L14R16,16-U7D25L15R17,17-U8D26L16,18-U9D27R19,19-U10D28L18R20,20-U11D29L19R21,21-U12D30L20R22,22-U13D31L21R23,23-U14D32L22R24,24-U15D33L23R25,25-U16D34L24R26,26-U17D35L25,27-U18D36R28,28-U19D37L27R29,29-U20D38L28R30,30-U21D39L29R31,31-U22D40L30R32,32-U23D41L31R33,33-U24D42L32R34,34-U25D43L33R35,35-U26D44L34,36-U27D45R37,37-U28D46L36R38,38-U29D47L37R39,39-U30D48L38R40,40-U31D49L39R41,41-U32D50L40R42,42-U33D51L41R43,43-U34D52L42R44,44-U35D53L43,45-U36D54R46,46-U37D55L45R47,47-U38D56L46R48,48-U39D57L47R49,49-U40D58L48R50,50-U41D59L49R51,51-U42D60L50R52,52-U43D61L51R53,53-U44D62L52,54-U45D63R55,55-U46D64L54R56,56-U47D65L55R57,57-U48D66L56R58,58-U49D67L57R59,59-U50D68L58R60,60-U51D69L59R61,61-U52D70L60R62,62-U53D71L61,63-U54D72R64,64-U55D73L63R65,65-U56D74L64R66,66-U57D75L65R67,67-U58D76L66R68,68-U59D77L67R69,69-U60D78L68R70,70-U61D79L69R71,71-U62D80L70,72-U63R73,73-U64L72R74,74-U65L73R75,75-U66L74R76,76-U67L75R77,77-U68L76R78,78-U69L77R79,79-U70L78R80,80-U71L79,<JDA>: x #Aldous-Broder algorithm-ish :D # in hindsight this performs way tooo many random steps to find that isolated corner cell for ex that hasn't been visited yet: need faster algorithm! #mark each cell's visitation as False s:[0-9]+:&,F:g #set first cell as current cell, would be nice if this was randomized to be anywhere on the 4 sides, and mark its visitation to True s:#0,F#:#C0,T#: :loop_ABa ##own RNG using LCG #x #s:<GCL>:#result_lcgp_m&: #b lcg_pos :result_lcgp_m #s:#[^<]+(<GCL>)( [0-9]+ [0-9]+ [0-9]+)(<ADJ>):\2\1\2\3: #x;G #system RNG G;x s:.*:seq 0 999|shuf|head -n 1:e x;G s:(<LCG>)[0-9]+( [0-9]+ [0-9]+ [0-9]+)(<GCL>.*<JDA>)\n([0-9]+):\1\4\2\3: x;G s:.*(<LCG>):\1: x #pick a random neighbour s:(C)([0-9]+)(,.*<ADJ>.*,)\2(-):\1\2\3\2\4@: #2 neighbours: corner cells /@((D[0-9]+R[0-9]+)|(D[0-9]+L[0-9]+)|(U[0-9]+R[0-9]+)|(U[0-9]+L[0-9]+)),/{ /<LCG>[0-9]*[02468] /s:([#=])([0-9]+)(,.*<ADJ>.*@)([UDLR])\2([UDLR]):\1N\4\2\3\4\2\5: /<LCG>[0-9]*[13579] /s:([#=])([0-9]+)(,.*<ADJ>.*@[UDLR][0-9]+)([UDLR])\2(,):\1N\4\2\3\4\2\5: } #3 neighbours: side cells, except corners /@((D[0-9]+L[0-9]+R[0-9]+)|(U[0-9]+D[0-9]+R[0-9]+)|(U[0-9]+D[0-9]+L[0-9]+)|(U[0-9]+L[0-9]+R[0-9]+)),/{ /<LCG>[0-9]*[012] /s:([#=])([0-9]+)(,.*<ADJ>.*@)([UDLR])\2([UDLR]):\1N\4\2\3\4\2\5: /<LCG>[0-9]*[3456] /s:([#=])([0-9]+)(,.*<ADJ>.*@[UDLR][0-9]+)([UDLR])\2([UDLR]):\1N\4\2\3\4\2\5: /<LCG>[0-9]*[789] /s:([#=])([0-9]+)(,.*<ADJ>.*@[UDLR][0-9]+[UDLR][0-9]+)([UDLR])\2(,):\1N\4\2\3\4\2\5: } #4 neighbours: interior cells /@U[0-9]+D[0-9]+L[0-9]+R[0-9]+,/{ /<LCG>[0-9]*[01] /s:([#=])([0-9]+)(,.*<ADJ>.*@)([UDLR])\2([UDLR]):\1N\4\2\3\4\2\5: /<LCG>[0-9]*[234] /s:([#=])([0-9]+)(,.*<ADJ>.*@[UDLR][0-9]+)([UDLR])\2([UDLR]):\1N\4\2\3\4\2\5: /<LCG>[0-9]*[567] /s:([#=])([0-9]+)(,.*<ADJ>.*@[UDLR][0-9]+[UDLR][0-9]+)([UDLR])\2([UDLR]):\1N\4\2\3\4\2\5: /<LCG>[0-9]*[89] /s:([#=])([0-9]+)(,.*<ADJ>.*@[UDLR][0-9]+[UDLR][0-9]+[UDLR][0-9]+)([UDLR])\2(,):\1N\4\2\3\4\2\5: } s:\n<LCG>.*:: /N[UDLR][0-9]+,F/{ #remove (in this case convert from # to =) the wall between the current cell and the neighbour /NL/s:#(C):=\1: /NR/s:#(N):=\1: /N[UD]/{ s:N[UD]([0-9]+),.*$:&;<MOD>\1 9#result_mdp_m<DOM>: b mod_pos :result_mdp_m s:<MOD>([0-9]+)[^<]+<DOM>$:<ADD>2 \1 \1#result_ap_m<DDA>: b add_pos :result_ap_m s:<ADD>([0-9]+)[^<]+<DDA>$:<SEQ>1-\1#result_sp_m2<QES>: b seq_pos :result_sp_m2 s:(<SEQ>) ?[0-9]+:@\1: /<SEQ>#/!b result_sp_m2 s:<SEQ>.*$:: } /NU/{ s:N[^\n]+\n:&@: b shift } /ND/{ s:C[^\n]+\n:&@: :shift s:(@)([#=]):\2\1: s:(;)@:\1: /;$/!b shift s:[#=]@:=: s:;$:: } #mark neighbour's visitation to True s:(N[UDLR][0-9]+),F:\1,T: } #set the neighbour as current cell s:C:: s:N[UDLR]:C: p#debug /F/b loop_ABa #display :print s:C:: s:([#=])(0):\1S\2: s:([#=])(80):\1E\2: s:\b([SE]?)[0-9]+,[TF]:\1 :g s:([SE]) :\1:g y:=: : #ANSI colors and fixed height/width ratio on terminal (h~=2w) s: :&&:g s:#:\o033[30;40m \o033[0m:g s:[SE]:\o033[31;41m \o033[0m:g p b EOS :user_redirects /##result_sp_m<QES>/b result_sp_m /##result_lcgp_m<GCL>/b result_lcgp_m /##result_mdp_m<DOM>/b result_mdp_m /##result_ap_m<DDA>/b result_ap_m /##result_sp_m2<QES>/b result_sp_m2 #/##result_debug<[^>]+>/b result_debug b EOS :debug #test if GNU extensions are supported 1v #s:.*:<LCG>&#result_debug<GCL>:;b lcg_pos #:result_debug #s:<[^>]+>([^#]+)[^<]+<[^>]+>:\1:p #b EOS b main ######################### MATH / UTILS ######################### (most of it was written before cg, used as my standard library :) #4: <LCG>seed a c m#label<GCL> -> <LCG>new_seed##label<GCL> :lcg_pos s:(<LCG>)([0-9]+ [0-9]+):\1<MULT>\2#result_mpp_lcgp<TLUM>: b mult_pos :result_mpp_lcgp s:(<LCG>)<MULT>([0-9]+)[^<]+<TLUM>:\1\2: s:(<LCG>)([0-9]+) ([0-9]+):\1<ADD>\3 \2#result_ap_lcgp<DDA>: b add_pos :result_ap_lcgp s:(<LCG>)<ADD>([0-9]+)[^<]+<DDA>:\1\2: s:(<LCG>)([0-9]+ [0-9]+):\1<MOD>\2#result_mdp_lcgp<DOM>: b mod_pos :result_mdp_lcgp s:(<LCG>)<MOD>([0-9]+)[^<]+<DOM>:\1\2#: b redirect #2: <INTERSECTION>3 4 5,2 3 4 5 6 7 8#label<NOITCESRETNI> -> <INTERSECTION>1##label<NOITCESRETNI> :intersection_pos s:(<INTERSECTION>)([^,]+):\1!\2 : :loop_isp /<INTERSECTION>[^!]+!,/{ s:(<INTERSECTION>)[^#]+:\10: b print_isp } /<INTERSECTION>[^!]*!([0-9]+) [^,]*,[^#]*\b\1\b/{ s:(<INTERSECTION>)[^#]+:\11: b print_isp } s:(<INTERSECTION>[^!]*)!([0-9]+ ):\1\2!: b loop_isp :print_isp s:#[^<]+<NOITCESRETNI>:#&: b redirect #2: <SUBSET>3 4 5,2 3 4 5 6 7 8#label<TESBUS> -> <SUBSET>1##label<TESBUS> :subset_pos s:(<SUBSET>)([^,]+):\1!\2 : :loop_ssp /<SUBSET>[^!]+!,/{ s:(<SUBSET>)[^#]+:\11: b print_ssp } /<SUBSET>[^!]*!([0-9]+) [^,]*,[^#]*\b\1\b/{ s:(<SUBSET>[^!]*)!([0-9]+ ):\1\2!: b loop_ssp } s:(<SUBSET>)[^#]+:\10: :print_ssp s:#[^<]+<TESBUS>:#&: b redirect #1+: <SEQ>3-5,2-8,7-7#label<QES> -> <SEQ>3 4 5,2 3 4 5 6 7 8,7##label<QES> :seq_pos s:<SEQ>:&,: b next_sp :loop_sp /,([0-9]+)<INC>\1#[^<]+<CNI>[^<]+<QES>/b next_sp b incr_pos :result_ip_sp s:(<INC>)([0-9]+)#([^<]+<CNI>)([^,#]+)([^<]+<QES>):\1\2\3\4 \2\5: b loop_sp :next_sp s:,[0-9]+<INC>[^<]+<CNI>([^<]+<QES>):,\1: /,[0-9]+-[0-9]+[,#][^<]+<QES>/!b print_sp s:,([0-9]+)-([0-9]+)([,#][^<]+<QES>):,\2<INC>\1#result_ip_sp<CNI>\1\3: b loop_sp :print_sp s:(<SEQ>),([^#]+)(#[^<]+<QES>):\1\2#\3: b redirect #1+: <MAX>1 2 3#label<XAM> -> <MAX>3##label<XAM> :max_pos s:(<MAX>)([0-9]+#):\10 \2: s: ?([0-9]+) ([0-9]+)(#[^<]+<XAM>):A\1,\1B\2,\2M\2\3: :loop_Mp /,0[BM][^<]+<XAM>/b next_Mp s:,([0-9]+)(B[^<]+<XAM>):,<DEC>\1#result_dp_Mp1<CED>\2: b decr_pos :result_dp_Mp1 s:,<DEC>([0-9]+)#[^<]+<CED>(B[^<]+<XAM>):,\1\2: s:,([0-9]+)(M[^<]+<XAM>):,<DEC>\1#result_dp_Mp2<CED>\2: b decr_pos :result_dp_Mp2 s:,<DEC>([0-9]+)#[^<]+<CED>(M[^<]+<XAM>):,\1\2: b loop_Mp :next_Mp s:A([0-9]+),[1-9][0-9]*B[0-9]+,0M[0-9]+([^<]+<XAM>):A0,0B0,0M\1\2: /<MAX>A/b print_Mp s:B[0-9]+,[0-9]+M([0-9]+)([^<]+<XAM>):B\1,\1M\1\2: s: ?([0-9]+)A[0-9]+,[0-9]+:A\1,\1: b loop_Mp :print_Mp s:A[0-9]+,[0-9]+B[0-9]+,[0-9]+M([0-9]+):\1: s:#[^<]+<XAM>:#&: b redirect #1+: <MIN>1 2 3#label<NIM> -> <MIN>1##label<NIM> :min_pos s:(<MIN>)([0-9]+)#:\1\20 \2#: s:(<MIN>0)0:\1: s: ?([0-9]+) ([0-9]+)(#[^<]+<NIM>):A\1,\1B\2,\2m\2\3: :loop_mp /,0[Bm][^<]+<NIM>/b next_mp #compare lengths first before the dec method s:,([0-9]+)(B[^<]+<NIM>):,<DEC>\1#result_dp_mp1<CED>\2: b decr_pos :result_dp_mp1 s:,<DEC>([0-9]+)#[^<]+<CED>(B[^<]+<NIM>):,\1\2: s:,([0-9]+)(m[^<]+<NIM>):,<DEC>\1#result_dp_mp2<CED>\2: b decr_pos :result_dp_mp2 s:,<DEC>([0-9]+)#[^<]+<CED>(m[^<]+<NIM>):,\1\2: b loop_mp :next_mp s:A([0-9]+),0B[0-9]+,[1-9][0-9]*m[0-9]+([^<]+<NIM>):A0,0B0,0m\1\2: /<MIN>A/b print_mp s:B[0-9]+,[0-9]+m([0-9]+)([^<]+<NIM>):B\1,\1m\1\2: s: ?([0-9]+)A[0-9]+,[0-9]+:A\1,\1: b loop_mp :print_mp s:A[0-9]+,[0-9]+B[0-9]+,[0-9]+m([0-9]+):\1: s:#[^<]+<NIM>:#&: b redirect #2: <MOD>5 2#label<DOM> -> <MOD>1##label<DOM> :mod_pos s:#[^>]+<DOM>:,0 0,0&: :loop_mdp_1 s:(<MOD>[0-9]+ [0-9]+,)([0-9]+) [0-9]+,[0-9]+:\1\2 \2: s:(<MOD>[0-9]+ )([0-9]+),([0-9]+):\1\2,<ADD>\2 \3#result_ap_mdp<DDA>: b add_pos :result_ap_mdp s:<ADD>([0-9]+)[^>]+<DDA>([^>]+<DOM>):\1\2: s:<MOD>([0-9]+) [0-9]+,([0-9]+) [0-9]+:&<MIN>\1 \2#result_mp_mdp<NIM>: b min_pos :result_mp_mdp s:<MIN>([0-9]+)[^>]+<NIM>:,\1: /<MOD>([0-9]+) [0-9]+,[0-9]+ [0-9]+,\1/!b loop_mdp_1 /<MOD>([0-9]+) [0-9]+,\1/ s:(<MOD>[0-9]+ [0-9]+),([0-9]+) [0-9]+:\1,\2 \2: s:(<MOD>[0-9]+) [0-9]+,[0-9]+ ([0-9]+),[0-9]+:\1,\2 0: :loop_mdp_2 /<MOD>([0-9]+),\1/b print_mdp s:(<MOD>)([0-9]+):\1<DEC>\2#result_dp_mdp<CED>: b decr_pos :result_dp_mdp s:<DEC>([0-9]+)[^>]+<CED>:\1: s:(<MOD>[0-9]+,[0-9]+ )([0-9]+):\1<INC>\2#result_ip_mdp<CNI>: b incr_pos :result_ip_mdp s:<INC>([0-9]+)[^>]+<CNI>:\1: b loop_mdp_2 :print_mdp s:(<MOD>)[0-9]+,[0-9]+ ([0-9]+):\1\2#: b redirect #1+: <MULT>2 3 4#label<TLUM> -> <MULT>24##label<TLUM> :mult_pos s:(<MULT>)([0-9]+#):\11 \2: :loop_mpp / ?\b0\b ([0-9]+)(#[^<]+<TLUM>)/{ s:(<MULT>)[^#]+:\1 0: b print_mpp } s: ?([0-9]+) ([0-9]+)(#[^<]+<TLUM>):<ADD>\1 \2#result_ap_mpp<DDA>\3: s:(<ADD>)([0-9]+) ([^<]+<DDA>[^<]+<TLUM>):\1<SEQ>1-\2#result_sp_mpp<QES>\3: b seq_pos :result_sp_mpp s:(<SEQ>)[0-9]+ ?([^#]*[^<]+<QES>)([0-9]+):\3 \1\2\3: /<SEQ>#/!b result_sp_mpp s: <SEQ>[^<]+<QES>[0-9]+:: b add_pos :result_ap_mpp s:<ADD>([^#]+)[^<]+<DDA>: \1: /<MULT>[0-9]+ /b loop_mpp :print_mpp s:(<MULT>) :\1: s:#[^<]+<TLUM>:#&: b redirect #1+: <ADD>1 2 3#label<DDA> -> <ADD>6##label<DDA> :add_pos s:(<ADD>)([0-9]+#):\10 \2: s: ?([0-9]+) ([0-9]+)(#[^<]+<DDA>):<DEC>\1#result_dp_ap<CED><INC>\2#result_ip_ap<CNI>\3: :loop_ap /<DEC>0/b next_ap b decr_pos :result_dp_ap s:#([^<]+<CED>):\1: b incr_pos :result_ip_ap s:#([^<]+<CNI>):\1: b loop_ap :next_ap /<ADD><DEC>/b print_ap s: ?([0-9]+)(<DEC>)0:\2\1: b loop_ap :print_ap s:<DEC>0#result_dp_ap<CED><INC>([0-9]+)#result_ip_ap<CNI>(#[^<]+<DDA>):\1#\2: b redirect #1: <DEC>10#label<CED> -> <DEC>9##label<CED> :decr_pos :zeros s:0(@*)(#[^<]+<CED>):@\1\2: t zeros s:9(@*)(#[^<]+<CED>):8\1\2:;t print_dp s:8(@*)(#[^<]+<CED>):7\1\2:;t print_dp s:7(@*)(#[^<]+<CED>):6\1\2:;t print_dp s:6(@*)(#[^<]+<CED>):5\1\2:;t print_dp s:5(@*)(#[^<]+<CED>):4\1\2:;t print_dp s:4(@*)(#[^<]+<CED>):3\1\2:;t print_dp s:3(@*)(#[^<]+<CED>):2\1\2:;t print_dp s:2(@*)(#[^<]+<CED>):1\1\2:;t print_dp s:1(@*)(#[^<]+<CED>):0\1\2:;t print_dp :print_dp s:(<DEC>)0@:\1@: :loop_dp s:(<DEC>[^#]*)@:\19: /<DEC>[^#]*@/b loop_dp s:#[^<]+<CED>:#&: b redirect #1: <INC>9#label<CNI> -> <INC>10##label<CNI> :incr_pos :nines s:9(@*)(#[^<]+<CNI>):@\1\2: t nines s:0(@*)(#[^<]+<CNI>):1\1\2:;t print_ip s:1(@*)(#[^<]+<CNI>):2\1\2:;t print_ip s:2(@*)(#[^<]+<CNI>):3\1\2:;t print_ip s:3(@*)(#[^<]+<CNI>):4\1\2:;t print_ip s:4(@*)(#[^<]+<CNI>):5\1\2:;t print_ip s:5(@*)(#[^<]+<CNI>):6\1\2:;t print_ip s:6(@*)(#[^<]+<CNI>):7\1\2:;t print_ip s:7(@*)(#[^<]+<CNI>):8\1\2:;t print_ip s:8(@*)(#[^<]+<CNI>):9\1\2:;t print_ip :print_ip s:(<INC>)@:\11@: :loop_ip s:(<INC>[^#]*)@:\10: /<INC>[^#]*@/b loop_ip s:#[^<]+<CNI>:#&: b redirect :redirect b library_redirects :continue_redirects b user_redirects :library_redirects /##result_mpp_lcgp<TLUM>/b result_mpp_lcgp /##result_ap_lcgp<DDA>/b result_ap_lcgp /##result_mdp_lcgp<DOM>/b result_mdp_lcgp /##result_dp_ap<CED>/b result_dp_ap /##result_dp_Mp1<CED>/b result_dp_Mp1 /##result_dp_Mp2<CED>/b result_dp_Mp2 /##result_dp_mp1<CED>/b result_dp_mp1 /##result_dp_mp2<CED>/b result_dp_mp2 /##result_ap_mdp<DDA>/b result_ap_mdp /##result_mp_mdp<NIM>/b result_mp_mdp /##result_dp_mdp<CED>/b result_dp_mdp /##result_ip_mdp<CNI>/b result_ip_mdp /##result_sp_mpp<QES>/b result_sp_mpp /##result_ap_mpp<DDA>/b result_ap_mpp /##result_ip_ap<CNI>/b result_ip_ap /##result_ip_sp<CNI>/b result_ip_sp b continue_redirects :EOS #End Of Script (mainly used to skip over remaining code, when needed) Q |
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 | #!/usr/bin/sed -znrf :_Problem # compute Levenshtein distance between two null-byte separated strings # https://cg.esolangs.gay/30/ :_Restrictions # script can't handle the following characters in either of the two input string: ', ><' and most likely '#' also # script can handle empty string edgecase :D # recommended way to run the script (weird API): echo -n 'STRING STRING'|sed 's:$:\x0:;s: :\x0:'|./cg30_Levenshtein.sed|sed '$s:\x0::' b debug :main b read_init :result_ri_m #if one string is empty the distance is the length of the other /\x0,1$/{ s:^.*\b([0-9]+)\x0.*$:Distance = \1\n:p b EOS } :loop_m s:^:>: s:,([0-9]+)\b:&<: #>sitting,0< 1 2 3 4 5 6 7\000kitten,1$ :loop_m1 s:$:\x0,1,1,1: l #substitution cost s:>([^,])(.*\x0\1.*\x0,)1:>\1\20: s:\b([0-9]+)<.*\x0.*\x0,:&\1 : s:(\x0,)([^,]+)(.*)$:\1<ADD>\2#result_ap_ms<DDA>\3: b add_pos :result_ap_ms s:<ADD>([^#]+)[^<]+<DDA>:\1: #deletion cost s:< ([0-9]+)\b.*\x0.*\x0,[^,]+,:&\1 : s:(\x0,[^,]+,)([^,]+)(.*)$:\1<ADD>\2#result_ap_md<DDA>\3: b add_pos :result_ap_md s:<ADD>([^#]+)[^<]+<DDA>:\1: #insertion cost s:\b([0-9]+)\x0,[^,]+,[^,]+,:&\1 : s:(\x0,[^,]+,[^,]+,)(.*)$:\1<ADD>\2#result_ap_mi<DDA>: b add_pos :result_ap_mi s:<ADD>([^#]+)[^<]+<DDA>:\1: s:\x0,([^,]+),([^,]+),([^,]+)$: <MIN>\1 \2 \3#result_mp_m<NIM>: b min_pos :result_mp_m s:<MIN>([^#]+)[^<]+<NIM>:\1: s:>(.):\1>: s:< ([0-9]+): \1<: l /<\x0/!b loop_m1 #sitting>,0 1 2 3 4 5 6 7<\000kitten,1 1 2 3 4 5 6 7$ s:^([^,]+,).*(<\x0[^,]+,)([0-9]+)\b(.*)$:\1\3\4\2<INC>\3#result_ip_m<CNI>: b incr_pos :result_ip_m s:<INC>([^#]+)[^<]+<CNI>:\1: s:(<\x0).:\1: s:[><]::g l;= /^.*\x0,/!b loop_m #sitting,6 6 5 4 3 3 2 3\000,7$ s:^.*\b([0-9]+)\x0,.*$:Distance = \1\n:p b EOS :read_init /^$/{ s::,0: b result_sp_ri } s:.*:,&<INC>0#result_ip_ri<CNI>: :loop_ri s:,([^<]):\1,: b incr_pos :result_ip_ri s:#([^<]+<CNI>):\1: /,<INC>/!b loop_ri s:<INC>([^#]+).*:<SEQ>0-\1#result_sp_ri<QES>: b seq_pos :result_sp_ri s:<SEQ>([^#]+).*:\1: 1h 1b EOS H;g s:\b([0-9]+)\x0.*\b([0-9]+)$:&\x0<MAX>\1 \2#result_mp_ri<XAM>: b max_pos :result_mp_ri /\b([0-9]+)\x0<MAX>\1/ s:^(.*)\x0(.*\x0).*:\2\1: s:(\x0[^,]*,).*$:\11: b result_ri_m :user_redirects /##result_ip_m<CNI>/b result_ip_m /##result_mp_m<NIM>/b result_mp_m /##result_ap_ms<DDA>/b result_ap_ms /##result_ap_md<DDA>/b result_ap_md /##result_ap_mi<DDA>/b result_ap_mi /##result_ip_ri<CNI>/b result_ip_ri /##result_sp_ri<QES>/b result_sp_ri /##result_mp_ri<XAM>/b result_mp_ri b EOS :debug #test if GNU extensions are supported 1v b main ######################### MATH / UTILS ######################### (most of it was written before cg, used as my standard library :)) #2: <INTERSECTION>3 4 5,2 3 4 5 6 7 8#label<NOITCESRETNI> -> <INTERSECTION>1##label<NOITCESRETNI> :intersection_pos s:(<INTERSECTION>)([^,]+):\1!\2 : :loop_isp /<INTERSECTION>[^!]+!,/{ s:(<INTERSECTION>)[^#]+:\10: b print_isp } /<INTERSECTION>[^!]*!([0-9]+) [^,]*,[^#]*\b\1\b/{ s:(<INTERSECTION>)[^#]+:\11: b print_isp } s:(<INTERSECTION>[^!]*)!([0-9]+ ):\1\2!: b loop_isp :print_isp s:#[^<]+<NOITCESRETNI>:#&: b redirect #2: <SUBSET>3 4 5,2 3 4 5 6 7 8#label<TESBUS> -> <SUBSET>1##label<TESBUS> :subset_pos s:(<SUBSET>)([^,]+):\1!\2 : :loop_ssp /<SUBSET>[^!]+!,/{ s:(<SUBSET>)[^#]+:\11: b print_ssp } /<SUBSET>[^!]*!([0-9]+) [^,]*,[^#]*\b\1\b/{ s:(<SUBSET>[^!]*)!([0-9]+ ):\1\2!: b loop_ssp } s:(<SUBSET>)[^#]+:\10: :print_ssp s:#[^<]+<TESBUS>:#&: b redirect #1+: <SEQ>3-5,2-8,7-7#label<QES> -> <SEQ>3 4 5,2 3 4 5 6 7 8,7##label<QES> :seq_pos s:<SEQ>:&,: b next_sp :loop_sp /,([0-9]+)<INC>\1#[^<]+<CNI>[^<]+<QES>/b next_sp b incr_pos :result_ip_sp s:(<INC>)([0-9]+)#([^<]+<CNI>)([^,#]+)([^<]+<QES>):\1\2\3\4 \2\5: b loop_sp :next_sp s:,[0-9]+<INC>[^<]+<CNI>([^<]+<QES>):,\1: /,[0-9]+-[0-9]+[,#][^<]+<QES>/!b print_sp s:,([0-9]+)-([0-9]+)([,#][^<]+<QES>):,\2<INC>\1#result_ip_sp<CNI>\1\3: b loop_sp :print_sp s:(<SEQ>),([^#]+)(#[^<]+<QES>):\1\2#\3: b redirect #1+: <MAX>1 2 3#label<XAM> -> <MAX>3##label<XAM> :max_pos s:(<MAX>)([0-9]+#):\10 \2: s: ?([0-9]+) ([0-9]+)(#[^<]+<XAM>):A\1,\1B\2,\2M\2\3: :loop_Mp /,0[BM][^<]+<XAM>/b next_Mp s:,([0-9]+)(B[^<]+<XAM>):,<DEC>\1#result_dp_Mp1<CED>\2: b decr_pos :result_dp_Mp1 s:,<DEC>([0-9]+)#[^<]+<CED>(B[^<]+<XAM>):,\1\2: s:,([0-9]+)(M[^<]+<XAM>):,<DEC>\1#result_dp_Mp2<CED>\2: b decr_pos :result_dp_Mp2 s:,<DEC>([0-9]+)#[^<]+<CED>(M[^<]+<XAM>):,\1\2: b loop_Mp :next_Mp s:A([0-9]+),[1-9][0-9]*B[0-9]+,0M[0-9]+([^<]+<XAM>):A0,0B0,0M\1\2: /<MAX>A/b print_Mp s:B[0-9]+,[0-9]+M([0-9]+)([^<]+<XAM>):B\1,\1M\1\2: s: ?([0-9]+)A[0-9]+,[0-9]+:A\1,\1: b loop_Mp :print_Mp s:A[0-9]+,[0-9]+B[0-9]+,[0-9]+M([0-9]+):\1: s:#[^<]+<XAM>:#&: b redirect #1+: <MIN>1 2 3#label<NIM> -> <MIN>1##label<NIM> :min_pos s:(<MIN>)([0-9]+)#:\1\20 \2#: s:(<MIN>0)0:\1: s: ?([0-9]+) ([0-9]+)(#[^<]+<NIM>):A\1,\1B\2,\2m\2\3: :loop_mp /,0[Bm][^<]+<NIM>/b next_mp s:,([0-9]+)(B[^<]+<NIM>):,<DEC>\1#result_dp_mp1<CED>\2: b decr_pos :result_dp_mp1 s:,<DEC>([0-9]+)#[^<]+<CED>(B[^<]+<NIM>):,\1\2: s:,([0-9]+)(m[^<]+<NIM>):,<DEC>\1#result_dp_mp2<CED>\2: b decr_pos :result_dp_mp2 s:,<DEC>([0-9]+)#[^<]+<CED>(m[^<]+<NIM>):,\1\2: b loop_mp :next_mp s:A([0-9]+),0B[0-9]+,[1-9][0-9]*m[0-9]+([^<]+<NIM>):A0,0B0,0m\1\2: /<MIN>A/b print_mp s:B[0-9]+,[0-9]+m([0-9]+)([^<]+<NIM>):B\1,\1m\1\2: s: ?([0-9]+)A[0-9]+,[0-9]+:A\1,\1: b loop_mp :print_mp s:A[0-9]+,[0-9]+B[0-9]+,[0-9]+m([0-9]+):\1: s:#[^<]+<NIM>:#&: b redirect #1+: <ADD>1 2 3#label<DDA> -> <ADD>6##label<DDA> :add_pos s:(<ADD>)([0-9]+#):\10 \2: s: ?([0-9]+) ([0-9]+)(#[^<]+<DDA>):<DEC>\1#result_dp_ap<CED><INC>\2#result_ip_ap<CNI>\3: :loop_ap /<DEC>0/b next_ap b decr_pos :result_dp_ap s:#([^<]+<CED>):\1: b incr_pos :result_ip_ap s:#([^<]+<CNI>):\1: b loop_ap :next_ap /<ADD><DEC>/b print_ap s: ?([0-9]+)(<DEC>)0:\2\1: b loop_ap :print_ap s:<DEC>0#result_dp_ap<CED><INC>([0-9]+)#result_ip_ap<CNI>(#[^<]+<DDA>):\1#\2: b redirect #1: <DEC>10#label<CED> -> <DEC>9##label<CED> :decr_pos :zeros s:0(@*)(#[^<]+<CED>):@\1\2: t zeros s:9(@*)(#[^<]+<CED>):8\1\2:;t print_dp s:8(@*)(#[^<]+<CED>):7\1\2:;t print_dp s:7(@*)(#[^<]+<CED>):6\1\2:;t print_dp s:6(@*)(#[^<]+<CED>):5\1\2:;t print_dp s:5(@*)(#[^<]+<CED>):4\1\2:;t print_dp s:4(@*)(#[^<]+<CED>):3\1\2:;t print_dp s:3(@*)(#[^<]+<CED>):2\1\2:;t print_dp s:2(@*)(#[^<]+<CED>):1\1\2:;t print_dp s:1(@*)(#[^<]+<CED>):0\1\2:;t print_dp :print_dp s:(<DEC>)0@:\1@: :loop_dp s:(<DEC>[^#]*)@:\19: /<DEC>[^#]*@/b loop_dp s:#[^<]+<CED>:#&: b redirect #1: <INC>9#label<CNI> -> <INC>10##label<CNI> :incr_pos :nines s:9(@*)(#[^<]+<CNI>):@\1\2: t nines s:0(@*)(#[^<]+<CNI>):1\1\2:;t print_ip s:1(@*)(#[^<]+<CNI>):2\1\2:;t print_ip s:2(@*)(#[^<]+<CNI>):3\1\2:;t print_ip s:3(@*)(#[^<]+<CNI>):4\1\2:;t print_ip s:4(@*)(#[^<]+<CNI>):5\1\2:;t print_ip s:5(@*)(#[^<]+<CNI>):6\1\2:;t print_ip s:6(@*)(#[^<]+<CNI>):7\1\2:;t print_ip s:7(@*)(#[^<]+<CNI>):8\1\2:;t print_ip s:8(@*)(#[^<]+<CNI>):9\1\2:;t print_ip :print_ip s:(<INC>)@:\11@: :loop_ip s:(<INC>[^#]*)@:\10: /<INC>[^#]*@/b loop_ip s:#[^<]+<CNI>:#&: b redirect :redirect b library_redirects :continue_redirects b user_redirects :library_redirects /##result_dp_ap<CED>/b result_dp_ap /##result_dp_Mp1<CED>/b result_dp_Mp1 /##result_dp_Mp2<CED>/b result_dp_Mp2 /##result_dp_mp1<CED>/b result_dp_mp1 /##result_dp_mp2<CED>/b result_dp_mp2 /##result_ip_ap<CNI>/b result_ip_ap /##result_ip_sp<CNI>/b result_ip_sp b continue_redirects :EOS #End Of Script (mainly used to skip over remaining code, when needed) |
post a comment