Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 767209
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T17:10:30+00:00 2026-05-14T17:10:30+00:00

The challenge: The shortest code by character count that will generate a series of

  • 0

The challenge:

The shortest code by character count that will generate a series of (pseudo)random numbers using the Middle-Square Method.

The Middle-Square Method of (pseudo)random number generation was first suggested by John Von Neumann in 1946 and is defined as follows:

Rn+1 = mid((Rn)2, m)

For example:

34562 = 11943936

mid(11943936) = 9439

94392 = 89094721

mid(89094721) = 0947

9472 = 896809

mid(896809) = 9680

96802 = 93702400

mid(93702400) = 7024

Another example:

8432 = 710649

mid(710649) = 106

1062 = 11236

mid(11236) = 123

1232 = 15129

mid(15129) = 512

5122 = 262144

mid(262144) = 621

6212 = 385641

mid(385641) = 856

8562 = 732736

mid(732736) = 327

3272 = 106929

mid(106929) = 069

692 = 4761

mid(4761) = 476

4762 = 226576

mid(226576) = 265

Definition of mid:

Apparently there is some confusion regarding the exact definition of mid. For the purposes of this challenge, assume that you are extracting the same number of digits as the starting seed. Meaning, if the starting seed had 4 digits, you would extract 4 digits from the middle. If the starting seed had 3 digits, you would extract 3 digits from the middle.

Regarding the extraction of numbers when you can’t find the exact middle, consider the number 710649. If you want to extract the middle 3, there is some ambiguity (106 or 064). In that case, extract the 3 that is closest to the beginning of the string. So in this case, you would extract 106.

An easy way to think of it is to pad zeroes to the number if it’s not the right number of digits. For example, if you pad leading-zeroes to 710649 you get 0710649 and the middle 3 digits now become 106.

Test cases:

Make no assumptions regarding the length of the seed. For example, you cannot assume that the seed will always be 4-digit number

A starting seed of 3456 that generates 4-digit random-numbers should generate the following series (first 10):

9439, 947, 9680, 7024, 3365, 3232, 4458, 8737, 3351, 2292

A starting seed of 8653 that generates 4-digit random numbers should generate the following series (first 10):

8744, 4575, 9306, 6016, 1922, 6940, 1636, 6764, 7516, 4902

A starting seed of 843 that generates 3-digit random numbers should generate the following series (first 10):

106, 123, 512, 621, 856, 327, 69, 476, 265, 22

A starting seed of 45678 that generates 5-digit ranom numbers should generate the following series (first 10):

86479, 78617, 80632, 1519, 30736, 47016, 10504, 3340, 11556, 35411

As far as leading zeroes are concerned, the answer is no leading zeroes should be displayed :).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T17:10:31+00:00Added an answer on May 14, 2026 at 5:10 pm

    dc 26/37 chars

    26 chars the function for a single number:

    ?dZsl2^dZ1+ll-2/Ar^/All^%p
    

    37 chars with a 10 cycles loop:

    ?dZsl[2^dZ1+ll-2/Ar^/All^%pdzB>L]dsLx
    

    Explanation of the function:

    ?            Input n
    dZ           calculate number of digits
    sl           store in register l
    2^           calculate n^2
    dZ           calculate number of digits of square
    1+ll-2/Ar^/  n/(10^((squaredigits+1-l)/2)) int division truncates last digits 
    All^%        n%(10^l) modulus truncates first digits
    p            print the number
    

    Test:

    dc msml.dc
    45678
    86479
    78617
    80632
    1519
    30736
    47016
    10504
    3340
    11556
    35411
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The Challenge The shortest code by character count that will output the Morris Number
I have following challenge: Implement a function that searches for a null point of
I take no credit for this challenge at all. It's Project Euler problem 6
Have same challenge as this guy: How to copy dependencies to gae war/WEB-INF/lib Applying
I am facing a challenge and don't know how to solve this in jQuery.
I've just been doing Greplin programming challenge and went to the final level, where
This is more of a challenge question than something I urgently need, so don't
Today I was faced with a challenge to create different behaviors for my shopping
I have run into a challenge with a project - I am trying to
I'm interested in creating a challenge / response type process in Delphi. The scenario

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.