Problem Statement
A hall of mirrors is a large room with many mirrors throughout it. When you look at one of these mirrors, often you end up seeing an object that is far away and has been reflected off many mirrors. To aid in the design of halls of mirrors, you are to write a class Mirrors with a method seen, which will tell you what object is seen, given a particular configuration of mirrors and objects, and the location and direction being looked.
Your method will take a
Finally, start will represent the location and direction that a person is looking from. The first element will be the x coordinate, the second element will be the y coordinate, and the third element will be the heading that they are looking in. The heading will be in the range 0 to 359, representing the number of degrees in a counter-clockwise direction, starting from straight right (positive x), that the person is looking. Thus a heading of 0 means the person is looking in the positive x direction, a heading of 90 indicates the positive y direction, and a heading of 45 indicates that the person is looking half way between the positive x and positive y directions.
Your method must determine what is seen when a person stands at the given coordinates and looks in the given direction. If the person sees himself, return "me". If the person doesn't see any object or himself, return "space". Otherwise return the name of the object the person sees.
Definition
- Class:
- Mirrors
- Method:
- seen
- Parameters:
- String[], String[], int[]
- Returns:
- String
- Method signature:
- String seen(String[] mirrors, String[] objects, int[] start)
- (be sure your method is public)
Notes
- All mirrors are double sided, and should be treated as line segments.
- All objects, and the person, are perfect circles and have a radius of 1.
- A mirror reflects light such that the angle formed between the mirror and the incoming light is the same as the angle formed between the mirror and the outgoing light. Thus the angle between the incoming and outgoing light is 180-2*(angle between mirror and light).
- If you look along a mirror, the mirror has no effect. (see examples).
Constraints
- Each element of mirrors will be formatted exactly as "
", with no extra spaces. - Each element of objects will be formatted exactly as "
", with no extra spaces or leading 0's. - mirrors will contain between 0 and 50 elements, inclusive.
- objects will contain between 0 and 50 elements, inclusive.
- start will contain exactly three elements, the first two representing x and y, respectively, and the third representing the heading the person is looking in.
- All coordinates will be integers in the range 0 to 1000, inclusive.
- The heading (3rd element of start) will be in the range 0 to 359, inclusive.
- No objects or mirrors will overlap other objects, mirrors, or the person (this includes touching at one point).
- No element of mirrors will represent a point. (x1==x2 and y1==y2)
- Each object will have a unique
other than "me" or "space". - Each
will contain only lowercase characters. - To avoid cumulative rounding errors, the object (or "me" or "space") seen will be seen in 50 mirrors or less.
- To avoid rounding errors, the object seen will be seen definatively. This means that no objects will be barely seen, or almost seen, and there will never be any question about which mirror is seen. This is ensured by checking that the path to the object seen does not pass within 0.001 of any other object, mirror, or the person.
- Each element of mirrors, and objects will contain between 1 and 50 characters, inclusive.
Examples
{"0 0 100 100"}
{"a 15 10"}
{10,5,90}
Returns: "a"
The one mirror is at a 45 degree angle
{"0 0 100 100"}
{"a 15 10"}
{10,5,180}
Returns: "space"
{"0 0 100 100"}
{"a 15 10"}
{20,5,135}
Returns: "a"
{"0 0 0 1000","1000 0 999 1000"}
{"a 500 152"}
{2,0,1}
Returns: "a"
{"0 0 0 100"}
{}
{20,0,179}
Returns: "me"
{"0 0 49 49"}
{"a 1000 20"}
{20,0,90}
Returns: "a"
{"0 0 0 1000","1000 0 999 1000"}
{"a 500 608"}
{2,0,2}
Returns: "a"
{"907 922 798 552","443 177 401 640"}
{}
{811,608,343}
Returns: "me"
{"838 646 260 238","735 989 935 880","97 475 344 514"}
{"aa 212 360","ab 467 122","ac 104 191","ad 244 103","ae 498 735","af 718 897","ag 473 510","ah 348 430","ai 506 48","aj 314 674","ak 928 701","al 278 741","am 528 600","an 728 748","ao 491 137"}
{249,28,108}
Returns: "ac"
{"832 314 566 10"}
{"aa 294 762","ab 922 396","ac 103 879","ad 286 427","ae 903 0","af 509 467","ag 382 95","ah 873 584","ai 195 787","aj 548 281","ak 933 58","al 531 121","am 804 573","an 587 298","ao 539 317"}
{480,97,20}
Returns: "am"
{"728 890 286 956","802 184 311 754","360 205 74 338","269 929 382 795","210 228 564 130","604 727 321 921","579 388 514 512"}
{"aa 152 485","ab 987 606","ac 127 765","ad 319 395","ae 612 178","af 881 221","ag 426 340","ah 731 777","ai 86 933","aj 957 512","ak 681 676","al 614 267","am 230 83","an 751 113","ao 663 171","ap 344 677","aq 100 489","ar 933 469","as 710 317","at 189 724","au 971 644","av 680 48","aw 873 606","ax 541 728","ay 181 358","az 925 894","ba 636 4","bb 585 890","bc 667 63","bd 147 59","be 965 151"}
{215,876,12}
Returns: "ac"
{"431 937 317 716","599 201 926 45","343 101 304 323","910 946 310 992"}
{"aa 454 47","ab 705 793","ac 690 586","ad 111 521","ae 117 407","af 344 1","ag 770 466","ah 998 323","ai 354 862","aj 200 860","ak 64 467","al 290 101","am 356 942","an 498 219","ao 892 533","ap 23 298","aq 677 434","ar 818 291","as 806 628","at 443 197","au 106 95","av 388 644","aw 425 961","ax 300 62","ay 247 672","az 701 897","ba 835 591","bb 878 839","bc 108 421","bd 819 908","be 18 751","bf 244 323","bg 291 629","bh 20 468","bi 995 478","bj 505 968","bk 571 837","bl 651 810","bm 618 426","bn 36 717","bo 956 742","bp 310 450"}
{218,929,349}
Returns: "am"
{"908 93 709 794","759 315 503 217","103 873 599 928"}
{"aa 302 461","ab 699 185","ac 272 65","ad 727 146","ae 103 968","af 928 467","ag 909 513","ah 408 96","ai 670 383","aj 567 132","ak 843 252","al 798 641","am 106 517","an 189 644","ao 978 516","ap 168 486","aq 415 34","ar 535 959","as 495 158","at 952 69","au 657 498","av 501 110","aw 55 622","ax 603 715","ay 47 82","az 238 927","ba 920 767","bb 88 925","bc 534 430","bd 986 924","be 696 182","bf 777 951","bg 695 374","bh 514 660","bi 649 819","bj 726 63","bk 2 505","bl 319 92","bm 754 35","bn 624 186","bo 785 786","bp 933 705","bq 953 416"}
{884,786,160}
Returns: "aw"
{"165 383 870 470","955 639 651 793","834 223 734 328"}
{"aa 721 112"}
{601,438,296}
Returns: "me"
{"192 940 176 904","113 959 447 161"}
{"aa 562 311","ab 426 625","ac 314 561","ad 103 343","ae 730 307","af 269 680","ag 191 321","ah 675 932","ai 673 864","aj 83 919","ak 400 998","al 154 588","am 911 784","an 596 952","ao 130 591","ap 374 279","aq 795 307","ar 344 589","as 267 211","at 803 391","au 567 347","av 89 326","aw 199 783","ax 561 808","ay 209 798","az 978 35","ba 751 118","bb 560 772","bc 300 575","bd 778 92","be 612 156","bf 219 903","bg 421 301","bh 740 420","bi 893 382","bj 435 937","bk 832 791","bl 915 154","bm 682 726","bn 754 69","bo 447 748","bp 982 924","bq 745 480","br 943 974"}
{347,337,328}
Returns: "ap"
{"119 93 245 463","328 216 589 545","551 858 128 8","66 75 239 662"}
{"aa 614 285","ab 47 238","ac 217 680","ad 998 779","ae 601 96","af 271 962","ag 619 297","ah 819 913","ai 254 735","aj 378 493","ak 247 590","al 99 69","am 397 58","an 644 539","ao 989 616","ap 718 486","aq 548 262","ar 337 723","as 232 557","at 205 968","au 506 582","av 446 831","aw 409 857","ax 636 839","ay 644 606","az 446 728","ba 895 727","bb 514 845","bc 316 265","bd 76 55","be 842 192","bf 748 245","bg 60 805","bh 352 100","bi 712 133","bj 66 619","bk 466 314","bl 283 470","bm 544 11","bn 469 122","bo 916 629","bp 19 432","bq 253 210","br 558 201","bs 571 669","bt 394 72","bu 477 200","bv 860 27"}
{283,534,36}
Returns: "av"
{"379 525 817 652","763 187 749 336","107 613 715 894"}
{"aa 932 677","ab 55 813","ac 129 832","ad 160 194","ae 512 139","af 35 349","ag 635 951","ah 156 36","ai 95 149","aj 356 834","ak 302 433","al 93 302","am 956 866","an 557 734","ao 314 49","ap 705 358","aq 726 583","ar 659 831","as 429 161","at 743 415","au 97 557","av 868 783","aw 163 944","ax 888 487","ay 524 513","az 0 265","ba 829 89","bb 284 11","bc 187 497","bd 973 905","be 805 782","bf 117 467","bg 732 970","bh 898 480","bi 671 963","bj 935 591","bk 510 326","bl 622 116","bm 72 193","bn 667 43","bo 361 230"}
{761,446,167}
Returns: "ak"
{"149 224 36 609","875 281 460 311","40 597 158 747","337 270 296 569"}
{"aa 148 59","ab 753 216","ac 43 115","ad 579 352","ae 519 626","af 582 199","ag 603 665","ah 301 210","ai 267 327","aj 547 650","ak 14 929","al 55 314","am 227 902","an 899 507","ao 404 787","ap 701 290","aq 638 600"}
{775,294,261}
Returns: "me"
{"409 59 565 448","810 491 776 481","227 932 426 533","687 248 471 186","58 90 568 693"}
{"aa 124 972","ab 3 719","ac 528 315","ad 645 690","ae 443 494","af 912 853","ag 270 473","ah 317 499","ai 884 252","aj 10 426","ak 524 952","al 918 826","am 306 31","an 707 275","ao 125 862","ap 252 91","aq 897 555","ar 209 406","as 948 752","at 455 985","au 77 833","av 601 971","aw 286 857","ax 547 468","ay 384 367","az 35 122","ba 785 110","bb 469 597","bc 530 604","bd 845 201","be 255 451","bf 511 725","bg 128 274","bh 582 912","bi 983 152","bj 297 909"}
{794,474,104}
Returns: "me"
{"209 939 958 974"}
{"aa 630 67","ab 897 735","ac 99 126","ad 762 55","ae 663 950","af 235 380","ag 6 1","ah 245 702","ai 314 70","aj 842 636","ak 463 789","al 329 633","am 207 244","an 957 230","ao 679 251","ap 183 986","aq 689 91","ar 476 392","as 311 898","at 799 276","au 966 189"}
{524,963,271}
Returns: "me"
{"962 672 971 902","275 552 269 586"}
{"aa 39 977","ab 743 943","ac 521 470","ad 600 510","ae 462 889","af 621 484","ag 816 130","ah 35 652","ai 387 196","aj 664 471","ak 32 86","al 674 42","am 986 290","an 716 918","ao 731 220","ap 136 908","aq 828 794","ar 868 453","as 62 501","at 899 263","au 296 753","av 188 878","aw 438 952","ax 261 514","ay 36 778","az 729 78","ba 75 388","bb 454 486","bc 706 822","bd 95 516","be 814 706","bf 336 244","bg 505 479","bh 188 766","bi 822 740","bj 365 279","bk 278 987","bl 893 826","bm 70 1","bn 780 937","bo 152 325","bp 807 179","bq 714 816","br 205 160","bs 992 83","bt 319 813"}
{742,638,32}
Returns: "ab"
{"95 243 240 220","457 80 949 243","827 618 67 592"}
{"aa 829 485","ab 188 770","ac 29 327","ad 279 289","ae 271 414","af 96 133","ag 951 90","ah 34 969","ai 764 910","aj 1000 339","ak 199 714","al 300 350","am 478 881","an 942 824","ao 675 460","ap 491 631","aq 284 946","ar 715 105","as 343 985","at 59 637","au 315 404","av 653 735","aw 351 563","ax 937 167","ay 202 188","az 188 23","ba 8 524","bb 209 888","bc 440 839","bd 163 673","be 174 96","bf 113 31","bg 490 830","bh 99 679","bi 830 110","bj 704 420","bk 576 809","bl 918 142","bm 874 228","bn 799 538","bo 309 572","bp 816 873","bq 425 673","br 35 688","bs 549 828","bt 277 905","bu 172 618"}
{147,467,65}
Returns: "au"
{"543 574 777 598","737 348 762 461","353 988 959 981"}
{"aa 205 872","ab 428 871","ac 535 409","ad 402 996","ae 282 727","af 76 986","ag 389 238","ah 622 521","ai 288 365","aj 379 994","ak 409 619","al 694 327","am 578 24","an 672 426","ao 317 377","ap 496 486","aq 334 164","ar 359 521","as 277 58","at 523 769","au 193 766","av 474 337","aw 982 684","ax 678 315","ay 530 246","az 954 830","ba 164 60","bb 68 987","bc 490 942","bd 769 395","be 718 736","bf 65 57","bg 60 377","bh 294 686","bi 872 968","bj 135 161","bk 770 823","bl 530 724","bm 109 280","bn 175 644","bo 815 825","bp 64 607","bq 774 474","br 385 748","bs 690 709","bt 910 325","bu 550 175","bv 914 270","bw 632 271"}
{582,493,96}
Returns: "me"
{"963 724 693 668","389 15 151 249","458 51 115 956","793 299 476 705","801 108 386 417","825 5 987 12"}
{"aa 413 488","ab 319 147","ac 19 530","ad 715 223","ae 703 962","af 799 700","ag 491 370","ah 683 701","ai 116 218","aj 562 634","ak 103 408","al 64 356","am 29 617","an 490 20","ao 1 349","ap 495 64","aq 60 793","ar 909 197","as 182 254","at 410 464","au 786 161","av 468 896","aw 168 349","ax 551 593","ay 81 649","az 868 517","ba 755 566","bb 30 718","bc 22 212","bd 902 194","be 849 494","bf 531 96","bg 489 966","bh 535 518","bi 693 700","bj 504 696","bk 890 977","bl 993 47","bm 5 583","bn 462 93","bo 667 54","bp 88 994"}
{827,231,252}
Returns: "bd"
{"530 861 901 746"}
{"aa 798 581","ab 443 858","ac 578 314","ad 974 42","ae 319 87","af 94 507","ag 191 399","ah 578 59","ai 24 664","aj 932 707","ak 357 454","al 894 460","am 933 626","an 960 714","ao 833 817","ap 831 190","aq 703 466","ar 802 587","as 803 456","at 807 66","au 960 734","av 44 462","aw 815 758","ax 839 612","ay 185 430","az 689 540","ba 742 255","bb 240 315"}
{662,819,94}
Returns: "me"
{"999 218 523 850","549 228 130 227"}
{"aa 251 969","ab 365 738","ac 634 199","ad 571 912","ae 442 38","af 371 712","ag 77 329"}
{756,43,37}
Returns: "me"
{"103 519 750 951","613 554 339 671","927 287 870 315"}
{"aa 482 330","ab 634 620","ac 761 45","ad 643 270","ae 478 992","af 86 470","ag 563 69","ah 594 69","ai 218 23","aj 897 81","ak 542 929","al 108 591","am 15 76","an 668 281","ao 742 249","ap 241 677","aq 383 703","ar 559 855","as 309 312","at 902 236","au 620 242","av 684 241","aw 322 193","ax 413 77","ay 144 723","az 92 622","ba 177 444","bb 990 416","bc 764 865","bd 603 52","be 856 514","bf 534 853","bg 331 542","bh 964 547","bi 640 395","bj 364 860","bk 471 294"}
{121,283,30}
Returns: "bi"
{"629 157 154 971"}
{"aa 925 65","ab 800 540","ac 208 415","ad 669 682","ae 163 49","af 442 904","ag 202 882","ah 673 772","ai 443 283","aj 512 257","ak 49 75","al 9 696","am 387 518","an 992 530","ao 370 907","ap 160 25","aq 97 98","ar 302 26","as 914 509","at 536 677","au 316 918","av 334 976","aw 697 715","ax 662 956","ay 804 71","az 933 268","ba 899 850","bb 658 957","bc 69 28","bd 589 255","be 792 785","bf 879 300","bg 889 377","bh 295 755","bi 250 457","bj 788 492","bk 249 460"}
{785,624,222}
Returns: "as"
{"783 745 365 530","975 702 124 968","17 653 68 789","387 478 214 549","100 349 221 761","825 562 691 345","413 32 482 429"}
{"aa 798 300","ab 997 976","ac 18 894","ad 755 501","ae 62 730","af 511 641","ag 344 835","ah 305 776","ai 240 26","aj 508 928","ak 339 352","al 100 125","am 657 45","an 419 764","ao 419 451","ap 681 26","aq 994 886","ar 744 676","as 24 681","at 662 87","au 856 725","av 773 221","aw 898 641","ax 267 341","ay 661 400","az 374 680","ba 804 550","bb 606 918","bc 696 432","bd 754 308","be 676 738","bf 683 507","bg 386 498","bh 291 681","bi 340 140","bj 413 277","bk 97 549","bl 849 906","bm 292 166","bn 132 148","bo 44 60","bp 174 753","bq 189 510","br 358 593"}
{119,133,99}
Returns: "bh"
{"874 4 106 412"}
{"aa 662 900","ab 812 110","ac 565 621","ad 231 615","ae 899 280","af 359 448","ag 620 586","ah 410 349","ai 656 746","aj 571 935","ak 749 378","al 443 909","am 299 317","an 911 868","ao 234 238","ap 635 350","aq 974 471","ar 931 437","as 891 523","at 134 933","au 279 328"}
{707,845,262}
Returns: "ar"
{"897 384 46 155","31 812 39 60","863 633 92 795"}
{"aa 373 628","ab 740 92","ac 478 158","ad 535 11","ae 175 140"}
{89,209,203}
Returns: "me"
{"294 875 575 78","395 876 903 119","701 877 770 814","808 255 609 92"}
{"aa 955 404","ab 219 722"}
{529,329,34}
Returns: "me"
{"944 494 764 674","410 631 475 27"}
{"aa 46 174","ab 214 794","ac 970 55","ad 538 183","ae 909 908","af 742 755","ag 241 194","ah 685 396","ai 225 709","aj 147 371","ak 687 155","al 627 461","am 12 840","an 834 560","ao 138 56","ap 849 166","aq 193 633","ar 755 564","as 403 221","at 941 653","au 892 374","av 153 337","aw 59 99","ax 815 83","ay 263 646","az 73 773","ba 649 447"}
{578,247,45}
Returns: "me"
{"976 238 627 190","502 933 756 328","372 231 385 614"}
{"aa 479 803","ab 948 494","ac 425 22","ad 708 579","ae 959 815","af 439 564","ag 437 196","ah 525 376","ai 677 345","aj 612 903","ak 77 704","al 56 330","am 582 963","an 4 419","ao 67 518","ap 794 261","aq 150 379","ar 245 512","as 11 338","at 74 643","au 783 635","av 83 253","aw 226 267","ax 32 88","ay 947 572","az 48 993","ba 109 670","bb 277 663","bc 721 935","bd 972 751","be 834 647","bf 628 520","bg 652 640","bh 840 41","bi 415 810","bj 511 623","bk 96 47","bl 699 991","bm 420 314","bn 871 550","bo 430 297","bp 588 895"}
{856,326,243}
Returns: "ai"
{"346 481 721 395","383 888 768 509","28 633 207 408","977 533 997 1"}
{"aa 308 475","ab 731 261","ac 511 873","ad 848 750","ae 458 409","af 912 84","ag 358 119","ah 944 249","ai 404 570","aj 832 89","ak 2 709","al 56 299","am 953 787","an 535 246","ao 150 575","ap 386 402","aq 426 15","ar 733 873","as 950 357","at 233 862","au 219 731","av 883 736","aw 36 176","ax 786 702","ay 19 48","az 6 38","ba 148 851","bb 322 234","bc 557 567","bd 668 356","be 282 679","bf 368 453","bg 976 196","bh 748 848","bi 618 182","bj 584 696","bk 172 464","bl 953 300","bm 673 424","bn 419 279","bo 710 64","bp 194 831","bq 427 782"}
{830,30,48}
Returns: "ah"
{"263 123 98 507","63 47 437 142"}
{"aa 494 242","ab 954 209","ac 973 465","ad 926 265","ae 156 488","af 715 915","ag 998 907","ah 668 61","ai 404 118","aj 847 299","ak 267 724","al 551 537","am 879 665","an 445 742","ao 776 51","ap 847 320","aq 743 755","ar 879 952","as 624 558","at 186 971","au 860 833","av 644 811","aw 172 476","ax 46 338","ay 609 112","az 54 372","ba 253 359","bb 776 109","bc 253 313","bd 255 641","be 476 258","bf 766 291","bg 8 9","bh 270 11","bi 923 249","bj 619 645","bk 242 638","bl 59 506","bm 757 518"}
{407,309,160}
Returns: "aw"
{"459 456 730 185","81 354 599 540"}
{"aa 20 640","ab 530 405","ac 91 539","ad 619 495","ae 416 340","af 752 938","ag 674 233"}
{586,251,128}
Returns: "ae"
{"410 265 891 681"}
{"aa 647 979","ab 574 894","ac 856 327","ad 243 155","ae 623 437","af 648 188","ag 904 820","ah 462 305","ai 683 194","aj 211 495","ak 620 266","al 537 561","am 495 325","an 964 482","ao 911 926","ap 869 721","aq 569 422","ar 36 29","as 85 638","at 75 745","au 779 457","av 183 475","aw 52 745","ax 249 538"}
{12,566,6}
Returns: "ag"
{"416 121 491 982","58 68 59 108"}
{"aa 30 461","ab 146 531","ac 912 501","ad 456 270","ae 113 529","af 673 811","ag 534 880","ah 513 272","ai 283 195","aj 43 882","ak 617 712","al 7 22","am 129 496","an 751 222","ao 338 290","ap 688 645","aq 818 598","ar 223 130","as 179 944","at 545 138","au 299 760","av 707 993","aw 389 191","ax 0 666","ay 679 213","az 679 996","ba 710 872","bb 740 599","bc 519 96","bd 591 967","be 249 506"}
{140,163,24}
Returns: "am"
{"187 270 204 781","143 81 145 618"}
{"aa 977 132","ab 951 513","ac 617 833","ad 0 868","ae 373 296","af 404 825","ag 454 752","ah 139 362","ai 855 646","aj 1 767","ak 222 584","al 411 558","am 541 910","an 472 948","ao 796 700","ap 919 119","aq 85 151","ar 766 362","as 992 905"}
{234,626,152}
Returns: "ac"
{"543 440 680 697","898 968 988 966","697 280 832 34","738 499 112 251","652 738 1 173"}
{"aa 988 749","ab 709 783","ac 771 881","ad 486 339","ae 851 373","af 434 392","ag 448 386","ah 538 719","ai 810 318","aj 750 285","ak 801 905","al 55 428","am 164 316","an 805 487","ao 751 966","ap 464 957","aq 547 13","ar 147 780","as 328 654","at 375 232","au 339 54","av 784 949","aw 471 513","ax 655 37","ay 50 742","az 476 923","ba 470 420","bb 952 464","bc 605 111","bd 280 193"}
{141,383,290}
Returns: "am"
{"288 109 34 258","667 309 990 734"}
{"aa 978 673","ab 964 707","ac 620 355","ad 614 649","ae 830 2","af 272 81","ag 140 160","ah 788 76","ai 849 245","aj 543 197","ak 170 466","al 880 978","am 954 62","an 15 989","ao 665 250","ap 229 342","aq 286 293","ar 783 885","as 516 177","at 42 310","au 118 508","av 527 918","aw 586 338","ax 158 751","ay 342 822","az 806 420","ba 517 797","bb 358 1000","bc 12 597","bd 914 994","be 931 679","bf 364 545","bg 655 925","bh 621 696","bi 845 814","bj 935 767","bk 323 997","bl 302 639","bm 425 194","bn 737 1","bo 625 766","bp 265 436"}
{406,733,316}
Returns: "ax"
{}
{"a 10 0"}
{0,0,0}
Returns: "a"
{"10 0 20 0"}
{"a 30 0"}
{0,0,0}
Returns: "a"
{"11 10 20 10","0 20 20 0"}
{"a 30 10"}
{10,20,270}
Returns: "a"