From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.66.119.201 with SMTP id kw9mr22858448pab.4.1435609289656; Mon, 29 Jun 2015 13:21:29 -0700 (PDT) X-Received: by 10.140.93.38 with SMTP id c35mr187194qge.38.1435609289607; Mon, 29 Jun 2015 13:21:29 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!feeder.eternal-september.org!news.glorb.com!j8no2674733igd.0!news-out.google.com!w15ni10610qge.0!nntp.google.com!j5no1306831qga.1!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Mon, 29 Jun 2015 13:21:29 -0700 (PDT) In-Reply-To: <24d183ce-77b6-4fe1-a95e-0ff5ef72c7bd@googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=86.145.105.14; posting-account=pmkN8QoAAAAtIhXRUfydb0SCISnwaeyg NNTP-Posting-Host: 86.145.105.14 References: <24d183ce-77b6-4fe1-a95e-0ff5ef72c7bd@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <1fad5a33-a5c2-45ae-95c0-74c90f00157f@googlegroups.com> Subject: Re: How to shuffle/jumble letters of a given word? From: Austin Obyrne Injection-Date: Mon, 29 Jun 2015 20:21:29 +0000 Content-Type: text/plain; charset=ISO-8859-1 Xref: news.eternal-september.org comp.lang.ada:26546 Date: 2015-06-29T13:21:29-07:00 List-Id: On Sunday, June 28, 2015 at 3:06:29 PM UTC+1, Trish Cayetano wrote: > I am creating a "text twist game" where you guess the words in a jumbled manner. How do I set the code to shuffle the letters? > > Example: word to be guessed is HELLO > > What should be displayed is: LOLEH or LELHO > > Thanks in advance! Hi Trish, This may not be sophisticated enough for what you want but it works. Try it with the word "Milestone" Note: You must set the 'wordlength' and the scrambling parameters ('Step' and 'Repeats') to suit - *the product of those must not exceed the 'Wordlength' other wise they will fall off the end of the arrays. I can do better if you really want to include sentences or groups of letters as words also. Cheers - Austin With Ada.Text_IO; With Ada.Integer_Text_IO; Procedure Scramble_Letters is ------------------------------------------------------------------------- --| The program reads in a prescribed word of declared length --| from the key board stores the characters and scrambles them. ------------------------------------------------------------------------- X : Integer; Total : Integer; WordLength: Constant Integer:= 9; -- set the wordlength here Step : Constant Integer := 4; Repeats : Constant Integer := 2; -- Step x Repeats =< WordLength -- SUBTYPE Index_1 IS Positive RANGE 1 .. 100; Type ReadInArray IS ARRAY (Index_1) OF Character; NextChar: ReadInArray:= (others => ' '); -- Stores the plaintext 'NextChar' items being read in. SUBTYPE Index_2 IS Positive RANGE 1 .. 100000; TYPE UnscrambledNextChars IS ARRAY (Index_2) OF Character; Alpha : UnscrambledNextChars := (others => ' '); -- before scrambling SUBTYPE Index_3 IS Positive RANGE 1 .. 100000; TYPE ScrambledNextChars_Array IS ARRAY (Index_3) OF Character; Beta : ScrambledNextChars_Array := (others => ' '); --after scrambling ---------------------------------------------------------- PROCEDURE Load_n_Scramble_Letters IS -- Pre : nil -- Post: nil BEGIN -- Load_n_Scramble_Letters FOR I IN 1 .. Total LOOP Alpha(I):= NextChar(I); Beta (I):= NextChar(I); END LOOP; Ada.Text_IO.New_Line(2); Ada.Text_IO.Put(Item => " Before After ");-- X := 0; FOR Repeater IN 1 .. Repeats LOOP FOR Count IN REVERSE X+1 .. X+Step LOOP X:=X+1; Beta(X) := Alpha(Count); Ada.Text_IO.New_Line(1); -- Ada.Text_IO.Put(Item => " ");-- Ada.Text_IO.Put(Item => Alpha(X)); -- Ada.Text_IO.Put(Item => " ");-- Ada.Text_IO.Put(Item => Beta(X)); -- END LOOP; Ada.Text_IO.New_Line;-- Ada.Text_IO.Put(item => " ---------------");-- END LOOP; End Load_n_Scramble_Letters; ---------------------------------------------------------------------------- BEGIN -- Scramble_Letters Total:=0; FOR I in 1 .. WordLength LOOP Total := Total +1; Ada.Text_IO.Put(Item => "Enter the character number"); Ada.Integer_Text_IO.Put(Item => I, Width => 2); Ada.Text_IO.Put(Item => " > " ); Ada.Text_IO.Get(Item => NextChar(Total)); END LOOP; Ada.Text_IO.New_Line; Ada.Text_IO.Put(Item => " That's it - the word for scrambling is > "); FOR I in 1 .. WordLength LOOP Ada.Text_IO.Put(Item => NextChar(I)); END LOOP; Load_n_Scramble_Letters; -- goes to the scrambling procedure from here END Scramble_Letters; ----------------------------------------------------------------