How to resolve the algorithm Seven-sided dice from five-sided dice step by step in the Quackery programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Seven-sided dice from five-sided dice step by step in the Quackery programming language

Table of Contents

Problem Statement

(Given an equal-probability generator of one of the integers 1 to 5 as dice5),   create dice7 that generates a pseudo-random integer from 1 to 7 in equal probability using only dice5 as a source of random numbers,   and check the distribution for at least one million calls using the function created in   Simple Random Distribution Checker.

Implementation suggestion: dice7 might call dice5 twice, re-call if four of the 25 combinations are given, otherwise split the other 21 combinations into 7 groups of three, and return the group index from the rolls. (Task adapted from an answer here)

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Seven-sided dice from five-sided dice step by step in the Quackery programming language

Source code in the quackery programming language

  [ 5 random 1+ ]   is dice5 ( --> n )

  [ dice5 5 * 
    dice5 + 6 -
    [ table 
      0 0 0 0 1
      1 1 2 2 2 
      3 3 3 4 4
      4 5 5 5 6
      6 6 7 7 7 ]
     dup 0 = iff 
       drop again ] is dice7 ( --> n )

  

You may also check:How to resolve the algorithm Digital root/Multiplicative digital root step by step in the Scala programming language
You may also check:How to resolve the algorithm Sort three variables step by step in the Factor programming language
You may also check:How to resolve the algorithm Palindrome detection step by step in the Insitux programming language
You may also check:How to resolve the algorithm Determine if a string has all unique characters step by step in the Python programming language
You may also check:How to resolve the algorithm Compiler/lexical analyzer step by step in the Raku programming language