7
\$\begingroup\$

Note: reference to Nothing up my sleeve number.

Your task is to take no input and generate this exact output:

d76aa478 e8c7b756 242070db c1bdceee f57c0faf 4787c62a a8304613 fd469501
698098d8 8b44f7af ffff5bb1 895cd7be 6b901122 fd987193 a679438e 49b40821
f61e2562 c040b340 265e5a51 e9b6c7aa d62f105d 02441453 d8a1e681 e7d3fbc8
21e1cde6 c33707d6 f4d50d87 455a14ed a9e3e905 fcefa3f8 676f02d9 8d2a4c8a
fffa3942 8771f681 6d9d6122 fde5380c a4beea44 4bdecfa9 f6bb4b60 bebfbc70
289b7ec6 eaa127fa d4ef3085 04881d05 d9d4d039 e6db99e5 1fa27cf8 c4ac5665
f4292244 432aff97 ab9423a7 fc93a039 655b59c3 8f0ccc92 ffeff47d 85845dd1
6fa87e4f fe2ce6e0 a3014314 4e0811a1 f7537e82 bd3af235 2ad7d2bb eb86d391

A trailing newline is optional.

The MD5 hash for the version with trailing newline is:

  • FC1D37B5295177E7F28509EC9197688F

The MD5 hash for the version without trailing newline is:

  • FAC194EC5EFD2E5A5AC07C2A4925699B

How the string is generated

Those 64 strings are actually the 64 hexadecimal numbers used in the MD5 hash.

The pseudocode for them:

numbers = floor(2^32 × abs(sin(i))) for i in [1,2,...,64]

The reference Python code:

from math import*
for i in range(8):print" ".join("{:08x}".format(int(abs(2**32*sin(-~j))))for j in range(8*i,8*i+8))

Ungolfed:

from math import*
for i in range(8):
    temp = []
    for j in range(8*i,8*i+8):
        temp += ["{:08x}".format(int(abs(2**32*sin(j+1))))]
    print " ".join(temp)
\$\endgroup\$
2
  • \$\begingroup\$ So we need to add one newline every 8 numbers? \$\endgroup\$
    – Denker
    Commented Jun 11, 2016 at 4:54
  • \$\begingroup\$ @DenkerAffe Yes. \$\endgroup\$
    – Leaky Nun
    Commented Jun 11, 2016 at 5:20

14 Answers 14

3
\$\begingroup\$

Python 2, 86 77 76 bytes

import math
n=0;exec(",\nn+=1;print'%08x'%(2**32*abs(math.sin(n)))"*8)[1:]*8

Test it on Ideone.

How it works

Python 2's print statement has a quirk: It appends a newline to the result of its expression, unless it is followed by a trailing ,; in this case, it appends a space. While that's usually annoying when golfing (as there's no short way to print without trailing whitespace), it's perfect for this task.

We repeat the string ,\nn+=1;print'%08x'%(2**32*abs(math.sin(n))) eight times, chop off the leading comma with [1:], and repeat the result eight times. The string that exec executes composed of eight identical copies of the following code.


n+=1;print'%08x'%(2**32*abs(math.sin(n))),
n+=1;print'%08x'%(2**32*abs(math.sin(n))),
n+=1;print'%08x'%(2**32*abs(math.sin(n))),
n+=1;print'%08x'%(2**32*abs(math.sin(n))),
n+=1;print'%08x'%(2**32*abs(math.sin(n))),
n+=1;print'%08x'%(2**32*abs(math.sin(n))),
n+=1;print'%08x'%(2**32*abs(math.sin(n))),
n+=1;print'%08x'%(2**32*abs(math.sin(n)))

Each line increments the variable n (initialized by n=0), applies the format string %08x (lowercase hexadecimal representation, left-padded with zeroes to length 8, of the integer part of its argument) to 232 times the absolute value of the sine of n, and prints the resulting string either with a trailing space or a trailing linefeed.

\$\endgroup\$
3
\$\begingroup\$

Jelly, 26 24 23 bytes

64RÆSA‘æ«32Ḟb⁴Ḋ€‘ịØhs8G

Try it online!

How it works

64RÆSA‘æ«32Ḟb⁴Ḋ€‘ịØhs8G  Main link. No arguments.

64R                      Yield [1, ..., 64].
   ÆS                    Apply sine to each.
     A                   Take absolute values.
      ‘                  Increment.
                         This avoid padding the hex strings to 8 characters.
       æ«32              Left-shift by 32 units.
           Ḟ             Floor.
            b⁴           Convert to base 16 (list of integers).
              Ḋ€         Remove the first digit of each, undoing the increment.
                ‘        Increment each base 16 digit (for 1-based indexing).
                 ịØh     Index into "0123456789abcdef".
                    s8   Split into chunks of length 8.
                      G  Grid; separate columns by spaces, rows by linefeeds.
\$\endgroup\$
2
\$\begingroup\$

MATL, 28 bytes

64:Y,|32W*k16YAkZ{Zc72e!3LZ)

Try it online!

Pretty straightforward computation. Getting the required output format takes almost half the byte count.

\$\endgroup\$
2
\$\begingroup\$

Pyth, 31 27 bytes

Thanks to @Dennis for saving 4 bytes!

jjL;c8mt.Hs*^2 32h.a.tdZS64

Try it here!

Explanation

jjL;c8mt.Hs*^2 32h.a.tdZS64

      m                 S64   # map over [1...64]
          s*^2 32h.a.tdZ      # floor(2^32 * abs(sin(d))+1)
       t.H                    # convert to hex-string and discard the first digit
    c8                        # split into 8 parts
jjL;                          # join on whitespaces and then on newlines
\$\endgroup\$
2
  • \$\begingroup\$ You can save a few bytes with jjL;c8mt.Hs*^2 32h.a.tdZS64. \$\endgroup\$
    – Dennis
    Commented Jun 11, 2016 at 5:50
  • \$\begingroup\$ @Dennis Thats clever, thanks! :) \$\endgroup\$
    – Denker
    Commented Jun 11, 2016 at 17:17
1
\$\begingroup\$

JavaScript (ES7), 115 bytes

_=>`_ _ _ _ _ _ _ _
`.repeat(8).replace(/_/g,_=>(0+(Math.abs(Math.sin(++n))*2**32>>>0).toString(16)).slice(-8),n=0)

Includes the trailing newline.

\$\endgroup\$
1
\$\begingroup\$

PHP, 131 81 bytes

for(;++$i<65;){echo str_pad(dechex(2**32*abs(sin($i))),8,"0",0).($i%8?" ":"\n");}

This is a pretty straight-forward loop with a few conditions for spacing.

@insertusernamehere's shortcuts cut it down by 50 bytes.

\$\endgroup\$
2
  • \$\begingroup\$ Hello and welcome to PPGC! A few quick tips about your answer : You can get rid of the <? tag for posting answers here. As for your code itself, you can get down to 92 bytes by getting rid of the ifand the multiple echo : for($i=1;$i<65;$i++){echo (($i%8==1)?"\n":" ").str_pad(dechex(2**32*abs(sin($i))),8,"0",0);} \$\endgroup\$
    – Sake
    Commented Jun 11, 2016 at 7:08
  • \$\begingroup\$ You can get it down to 72 bytes: for(;++$i<65;)echo str_pad(dechex(2**32*abs(sin($i))),8).($i%8?" ":"⏎"); (replace with a real newline). \$\endgroup\$ Commented Jun 11, 2016 at 7:11
1
\$\begingroup\$

Julia, 69 63 58 bytes

[@printf "%08x%c"√sin(n)^2÷.5^32 n%8>0?32:10for n=1:64]

Try it online!

How it works

For each n between 1 and 64, we compute √sin(n)^2÷.5^32 and n%8>0?32:10, apply string formatting with "%08x%c" and print to STDOUT.

  • √sin(n)^2 computes the absolute value of sin(n). abs(sin(n)) is equally short (in bytes), but it would require a space to separate it from the format string.

    ÷.5^32 divides the previous result by 0.532 = 1 / 232, effectively multiplying it by 232. However, ÷ performs integer divsion, so the result is truncated.

  • n%8>0?32:10 returns 32 (the code point of a space) whenever n is not divisible by 8 and 10 (the code point of a linefeed) otherwise.

  • "%08x%c" turns the first result into lowercase hexadecimal representation, left-padded with zeroes to length 8; and the second result into a character.

Finally, the array comprehension returns an array of 64 instances of Nothing, the return value of @printf. Outside a REPL, this does not affect output.

\$\endgroup\$
1
\$\begingroup\$

///, 568 567 bytes

/!/ f//@/fa/d76aa478 e8c7b756 242070db c1bdceee!57c0@f 4787c62a a8304613!d469501
698098d8 8b44f7af!fff5bb1 895cd7be 6b901122!d987193 a679438e 49b40821
f61e2562 c040b340 265e5a51 e9b6c7aa d62f105d 02441453 d8a1e681 e7d3fbc8
21e1cde6 c33707d6!4d50d87 455a14ed a9e3e905!ce@3f8 676f02d9 8d2a4c8a
ff@3942 8771f681 6d9d6122!de5380c a4beea44 4bdec@9!6bb4b60 bebfbc70
289b7ec6 eaa127@ d4ef3085 04881d05 d9d4d039 e6db99e5 1@27cf8 c4ac5665
f4292244 432aff97 ab9423a7!c93a039 655b59c3 8f0ccc92!feff47d 85845dd1
6@87e4f!e2ce6e0 a3014314 4e0811a1!7537e82 bd3af235 2ad7d2bb eb86d391

Try it online!

Too bad I can only golf 6 7 bytes :-(

To convince you that I can't golf it further, I challenge you to do better in just ///, should you accept it. If you do, you're a magician, since Martin Ender's code says otherwise (checked)!

People that won the challenge and are worth of crediting (format: name (id), bytes_golfed):

  • daHugLenny (56258), 1
\$\endgroup\$
2
1
\$\begingroup\$

Perl 5, 56 54 52 bytes

printf'%08x%s'x64,map{0|2**32*abs sin,$_%8?$":$/}1..64

Saved 2 4 bytes thanks to @XCali

Try it online!

\$\endgroup\$
3
  • \$\begingroup\$ Save 2 bytes \$\endgroup\$
    – Xcali
    Commented Feb 24, 2020 at 18:14
  • \$\begingroup\$ Thanks! forgot about that trick :) \$\endgroup\$
    – andytech
    Commented Feb 25, 2020 at 0:22
  • \$\begingroup\$ Actually, you can take off two more by eliminating that altogether. The %x format only considers the integer portion. Try it online! \$\endgroup\$
    – Xcali
    Commented Feb 25, 2020 at 4:49
1
\$\begingroup\$

K4, 48 bytes

Solution:

-1@" "/:'8 8#(,/$4_0x0\:)'_abs sin[1+!64]*/32#2;

Example:

q)k)-1@" "/:'8 8#(,/$4_0x0\:)'_abs sin[1+!64]*/32#2;
d76aa478 e8c7b756 242070db c1bdceee f57c0faf 4787c62a a8304613 fd469501
698098d8 8b44f7af ffff5bb1 895cd7be 6b901122 fd987193 a679438e 49b40821
f61e2562 c040b340 265e5a51 e9b6c7aa d62f105d 02441453 d8a1e681 e7d3fbc8
21e1cde6 c33707d6 f4d50d87 455a14ed a9e3e905 fcefa3f8 676f02d9 8d2a4c8a
fffa3942 8771f681 6d9d6122 fde5380c a4beea44 4bdecfa9 f6bb4b60 bebfbc70
289b7ec6 eaa127fa d4ef3085 04881d05 d9d4d039 e6db99e5 1fa27cf8 c4ac5665
f4292244 432aff97 ab9423a7 fc93a039 655b59c3 8f0ccc92 ffeff47d 85845dd1
6fa87e4f fe2ce6e0 a3014314 4e0811a1 f7537e82 bd3af235 2ad7d2bb eb86d391

Explanation:

First pass, probably a few tricks left to golf further...

-1@" "/:'8 8#(,/$4_0x0\:)'_abs sin[1+!64]*/32#2; / the solution
                                           32#2  / take 2, 32 times (2 2 2 2 2...)
                                         */      / product beginning with left argument
                               sin[     ]        / built-in sine function
                                     !64         / range 0..63
                                   1+            / add 1, so 1..64
                           abs                   / built-in abs function
                          _                      / floor
             (          )'                       / do this together for each
                   0x0\:                         / convert to byte representation
                 4_                              / drop first 4 elements
                $                                / convert to string
              ,/                                 / flatten
         8 8#                                    / reshape to 8x8
   " "/:'                                        / join each with a single space
-1@                                            ; / print to stdout and swallow return
\$\endgroup\$
0
\$\begingroup\$

Racket 125 bytes

(λ()(for((i(range 1 65)))(printf"~x "(inexact->exact(floor(*(expt 2 32)(abs(sin i))))))(when(= 0(modulo i 8))(printf"~n"))))

Ungolfed:

(define f
  (λ ()
    (for ((i (range 1 65)))
      (printf "~x " (inexact->exact(floor (*(expt 2 32) (abs (sin i)) ))))
      (when(= 0 (modulo i 8)) (printf "~n"))
      )))

Testing:

(f)

Output:

d76aa478 e8c7b756 242070db c1bdceee f57c0faf 4787c62a a8304613 fd469501 
698098d8 8b44f7af ffff5bb1 895cd7be 6b901122 fd987193 a679438e 49b40821 
f61e2562 c040b340 265e5a51 e9b6c7aa d62f105d 2441453 d8a1e681 e7d3fbc8 
21e1cde6 c33707d6 f4d50d87 455a14ed a9e3e905 fcefa3f8 676f02d9 8d2a4c8a 
fffa3942 8771f681 6d9d6122 fde5380c a4beea44 4bdecfa9 f6bb4b60 bebfbc70 
289b7ec6 eaa127fa d4ef3085 4881d05 d9d4d039 e6db99e5 1fa27cf8 c4ac5665 
f4292244 432aff97 ab9423a7 fc93a039 655b59c3 8f0ccc92 ffeff47d 85845dd1 
6fa87e4f fe2ce6e0 a3014314 4e0811a1 f7537e82 bd3af235 2ad7d2bb eb86d391 
\$\endgroup\$
0
\$\begingroup\$

Pip, 37 bytes

36 bytes of code, +1 for -S flag.

0X8-#_._MMLC(2**32*ABSI++,64)TB16<>8

Pretty straightforward implementation. Unfortunately, 10 bytes are needed to left-pad some of the values with 0. Try it online!

                         ,64          Numbers 0 to 63
                       ++             Increment to get 1 to 64
                     SI               Sine
                   AB                 Absolute value
             2**32*                   Multiply by 2^32
            (               )TB16     Convert to hex (implicitly truncating to int)
          LC                          Lowercase--Pip's base conversion uses uppercase :(
                                 <>8  Group into sublists of size 8
        MM                            Map this function to each item of each sublist:
  8-#_                                  1 if item is length 7, 0 if length 8
0X                                      That many zeros
      ._                                Concatenate to beginning of item
                                      Print separated first by newline then by space (-S)
\$\endgroup\$
0
\$\begingroup\$

Burlesque, 34 bytes

64{Tsab2 32**.*pd-.b68'0lp}GO8cosp

Try it online!

64      # Literal 64
{
 Ts     # Sin
 ab     # Abs
 2 32** # 2**32
 .*     # Times-by
 pd     # Floor
 -.     # Decrement by 1
 b6     # To base 16
 8'0lp  # Left pad to length 8 with 0s
}GO     # Range from [1, 64] and map
8co     # Chunks of 8
sp      # Pretty print array
\$\endgroup\$
0
\$\begingroup\$

05AB1E, 19 17 bytes

64LŽĞJ*hl8jð0:8ô»

-2 bytes by taking inspiration from @Dennis' Jelly answer regarding the leading 0s, so make sure to upvote him!

Outputs with trailing newline.

Try it online.

Explanation:

64L                # Push a list in the range [1,64]
   Ž              # Take the sine of each
     Ä             # Take the absolute value of that
      >            # Increase it by 1 (to avoid having to pad leading 0s later on)
       žJ*         # Multiply it by builtin 4294967296
          h        # Convert it from integer to hexadecimal
                   # (which implicitly truncates the decimals; and uses uppercase [A-F])
           l       # Convert that hexadecimal string to lowercase
            €¦     # Remove the first character from each (undoing the earlier increment)
              8ô   # Split the list into parts of size 8
                »  # Join each inner list by spaces, and then those strings by newlines
                   # (after which it is output implicitly with trailing newline)
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.