# Calculate 6*9 in different bases

Output the following result (which is a result of calculating 6 * 9 in bases from 2 to 36). Make sure letters are uppercase, and the multiplication itself is outputed on every line.

6 * 9 = 110110
6 * 9 = 2000
6 * 9 = 312
6 * 9 = 204
6 * 9 = 130
6 * 9 = 105
6 * 9 = 66
6 * 9 = 60
6 * 9 = 54
6 * 9 = 4A
6 * 9 = 46
6 * 9 = 42
6 * 9 = 3C
6 * 9 = 39
6 * 9 = 36
6 * 9 = 33
6 * 9 = 30
6 * 9 = 2G
6 * 9 = 2E
6 * 9 = 2C
6 * 9 = 2A
6 * 9 = 28
6 * 9 = 26
6 * 9 = 24
6 * 9 = 22
6 * 9 = 20
6 * 9 = 1Q
6 * 9 = 1P
6 * 9 = 1O
6 * 9 = 1N
6 * 9 = 1M
6 * 9 = 1L
6 * 9 = 1K
6 * 9 = 1J
6 * 9 = 1I


Shortest code wins.

• @Howard: Fixed. I was considering changing 2 to 10, but forgot about this edit while fixing something else in the result, so I accidentally left it the wrong way.
– null
Commented Jan 5, 2014 at 10:06
• Calculate 6*9 in different bases I wonder why the statement is worded thus, why 6*9 and not simply 54? Perhaps the originally intended meaning was that 6 and 9 should be interpreted not always as decimal but in different bases? That would make the statement more logical, and the problem more interesting (but then we should start from base 10 to 36) Commented Jan 5, 2014 at 16:16
• @leonbloy: 6 and 9 are single-digit numbers. They mean the same in every base in which those digits are valid. Commented Jan 5, 2014 at 16:46
• @IlmariKaronen: Correct, but 6 * 9 = 110110 doesn't make a lot of sense... Commented Jan 5, 2014 at 18:09
• This is a reference to the Hitchhiker's Guide to the Galaxy series by Douglas Adams. In the series, the Answer to the Ultimate Question of Life, The Universe, and Everything is "42". Later, its revealed that the Ultimate Question of Life, the Universe, and Everything is "What do you get when you multiply six by nine?", which works out in base-13. Note: Douglas Adams said this was unintentional; "I don't write jokes in base-13". Commented Jan 10, 2014 at 21:14

### GolfScript, 39 characters

35,{2+'6 * 9 = '54@base{.9>7*+48+}%n+}/


Result can be seen here.

## Octave, 49

for i=2:36printf("6 * 9 = %s\n",dec2base(54,i))end

# Javascript, 57 55 bytes

for(i=2;++i<37;)console.log('6 * 9 = '+54..toString(i))


Could be shortened to 49 with alert, but I don't want to submit anyone to that...

• Output should be uppercase, and (54) can be replaced with 54. (to write 54..toString).
– null
Commented Jan 5, 2014 at 11:03
• for(i=1;++i<37;) also saves a character.
– grc
Commented Jan 5, 2014 at 11:42
• Can you ignore the 37? It will result in an error and stop
– l4m2
Commented Mar 21, 2018 at 16:37

# Ruby (47)

2.upto(36){|t|puts"9 * 6 = "+54.to_s(t).upcase}


Well, I know that GolfScript solution is better, but hey, at least this is not esoteric...

• 2.step{|t|puts"9 * 6 = "+54.to_s(t).upcase} saves a few bytes. It exits with an error, but that's ok :D. Commented Sep 20, 2016 at 18:06

## Python, 89

B=lambda x:x*'.'and B(x/b)+chr(x%b+7*(x%b>9)+48)
b=2
while b<37:print'6 * 9 =',B(54);b+=1

• Brilliant. Quite noticeable that I'm a total Python noob in comparison :) Commented Jan 5, 2014 at 21:02
• @JoachimIsaksson Thanks... I've got loads more to learn. Commented Jan 5, 2014 at 21:58
• You can shave off one character by using a while loop instead: b=2 <linebreak> while b<37:print'6 * 9 =',B(54);b+=1 (assuming single character for a *nix linebreak)
– Bob
Commented Jan 5, 2014 at 22:53
• @Bob Whenever I try a while loop, it's too expensive. Then, I forget to try the next time. ;) Thanks! Commented Jan 5, 2014 at 23:00

Python 2.7 (124 114)

EDIT: Cut some fluff thanks to @boothby's comment below

I think Python is doing ok considering it has no built-in (that I know of) to do the base conversion so it has to be done in code;

for b in range(2,37):print'6 * 9 = '+''.join(chr((54/b**y%b>9)*7+48+54/b**y%b)for y in range(4,-1,-1)).lstrip('0')

• I have to remind myself of this continually: print'\n'.join(...for x in y) is rather longer than for x in y:print.... Commented Jan 5, 2014 at 15:54
• @boothby Thanks, updated with your suggestion :) Commented Jan 5, 2014 at 20:32

say '6 * 9 = ',54.base($_) for 2..36  # 05AB1E, 21 20 bytes 36G54N>B"6 * 9 = ÿ",  Try it online! • I assume it's non-competing just because the language is newer than a challenge? Marking as accepted, as rules as of now allow this. – null Commented Mar 21, 2018 at 11:35 • @xfix pretty much haha Commented Mar 21, 2018 at 12:35 # Mathematica 40 Not in contention (lower case letters used): Print["6*9 = ",54~BaseForm~#]&/@2~Range~36  Perl Had to use the Math::BaseCnv module 35 chars without the use statement: map{say"6 * 9 = ",cnv(54,$_)}2..36


54 chars with the use statement:

use Math::BaseCnv;
map{say"6 * 9 = ",cnv(54,$_)}2..36  Not sure how you'd score this, so both are included. The map BLOCK LIST structure was used. List is the range 2 to 36, that was requested. The meat is in the cnv($NUMBER, $BASE) function, and the map is an implied loop. • Count the use statement. The first one doesn't work in my perl. Commented Jan 5, 2014 at 22:09 # J - 78 70 '6 * 9 = ',"1>;/(a.#~48 10 7 26 165#0 1 0 1 0){~<&.>(2+i.35)#.inv&.>54  # Haskell - 137 let s=['0'..'9']++['A'..'Z'];t _(0,r)=[s!!r];t b(q,r)=(t b$b q)++[s!!r]in mapM_(putStrLn.("6 * 9 = "++).(\b->t b$b 54).flip divMod)[2..36]  CoffeeScript 71 alert ("6 * 9 = "+59.toString(x).toUpperCase()for x in[2..36]).join "\n"  Link ## C (166 151) Got rid of some unnecessary characters and changed some declarations. Assumes that you are running the program with no arguments. p[7],i,l,v,r;main(b){for(r=2;r<37;r++){b++;printf("6 * 9 = ");v=54;while(v>0)l=v%b,p[i++]=l>9?l+55:l+48,v/=b;while(i^0)printf("%c",p[--i]);puts("");}}  ## Clojure, 75 (for[i(range 2 37)](println"6 * 9 ="(.toUpperCase(Integer/toString 54 i)))) # Python 3, 83 bytes import numpy;print('\n'.join('6 * 9 = '+numpy.base_repr(54,i)for i in range(2,37)))  • You can use '\n'.join('6 * 9 = '+numpy.base_repr(54,i)for i in range(2,37)) instead of *['6 * 9 = '+numpy.base_repr(54,i)for i in range(2,37)],sep='\n' to save a byte. Commented Dec 31, 2016 at 3:12 • You should probably specify "Python 3 with Numpy" as it's not a standard library Commented Jan 17, 2017 at 20:36 • @FlipTack Without numpy I can get it down to 143 if I have to hardcode '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ', or down to 130 if I'm allowed to import string.printable (but that results in lowercase instead of uppercase): Try it online!. Do you think that's worth making an answer? – Stef Commented Jan 14 at 13:39 # Dart, 75 bytes for(int x=2;x<37;x++)print("6 * 9 =${54.toRadixString(x).toUpperCase()}");


Dart is a bit verbose when it comes to the stdlib, but hey... at least you can read it :P

# Julia 0.6, 60 bytes

for b=2:36;@printf("6 * 9 = %s\n",uppercase(base(b,54)));end


Try it online!

Pretty painless, apart from remembering to use the macro @printf versus printf.

Import Base; not needed ...

• for b=2:36;println("6 * 9 = $(uppercase(base(b,54)))");end is also good... Commented Jan 26, 2014 at 12:13 ## Scala, 71 2 to 36 map(i=>println("6 * 9 = "+Integer.toString(54,i).toUpperCase))  Common Lisp: 56 characters (do((b 2(1+ b)))((> b 36))(format t"6 * 9 = ~vr~%"b 54))  ## Sage, 48: Shame Sage prints in lowercase... I'd only be one over Howard. Or, I guess, wrong and tied with David Carraher. for i in[2..36]:print'6 * 9 =',54.str(i).upper()  ## Forth, 54 : f 54 37 2 do ." 6 * 9 = " dup i base ! . cr loop ; f  # ///, 133 bytes /R/6 * 9 = //S/ R/R110110S2000S312S204S130S105S66S60S54S4AS46S42S3CS39S36S33S30S2GS2ES2CS2AS28S26S24S22S20S1QS1PS1OS1NS1MS1LS1KS1JS1I  Try it online! # SpecBAS - 48 bytes 1 FOR i=2 TO 36: ?"6 * 9 = ";BASE$(54,i): NEXT i


SpecBAS is actually quite competitive for a change :-)

# 8th, 65 62 bytes

This is a complete program. Exit after execution

( "6 * 9 = " . #54 swap base drop >s s:uc . cr ) 2 36 loop bye


Explanation

(
"6 * 9 = " .   \ Print the first part of the formula
#54 swap base \ Enter into the base provided by loop index and
\ convert 54 (which is always expressed in base 10)
drop          \ Get rid of previous base
>s s:uc       \ Convert number into an upper case string
. cr          \ Print result and newline
) 2 36 loop       \ Provide base from 2 to 36
bye               \ Quit


# VyxalrRMj, 119 bitsv2, 14.875 bytes

34ƛ⇧54R6*9=ṄðpJ


Try it Online!

Bitstring:

01001000111011011000001000111100010001001111010001100010011111010011011001011001000000010100011011001000011111011100011


so many flags

34ƛ⇧54R6*9=ṄðpJ­⁡​‎‏​⁢⁠⁡‌⁢​‎‎⁪⁡⁪⁠⁪⁡⁪‏⁠‎⁪⁡⁪⁠⁪⁢⁪‏⁠‎⁪⁡⁪⁠⁪⁣⁪‏‏​⁡⁠⁡‌⁣​‎‎⁪⁡⁪⁠⁪⁤⁪‏‏​⁡⁠⁡‌⁤​‎‎⁪⁡⁪⁠⁪⁢⁡⁪‏⁠‎⁪⁡⁪⁠⁪⁢⁢⁪‏⁠‎⁪⁡⁪⁠⁪⁢⁣⁪‏‏​⁡⁠⁡‌⁢⁡​‎‎⁪⁡⁪⁠⁪⁢⁤⁪‏⁠‎⁪⁡⁪⁠⁪⁣⁡⁪‏⁠‎⁪⁡⁪⁠⁪⁣⁢⁪‏⁠‎⁪⁡⁪⁠⁪⁣⁣⁪‏⁠‎⁪⁡⁪⁠⁪⁣⁤⁪‏⁠‎⁪⁡⁪⁠⁪⁤⁡⁪‏⁠‎⁪⁡⁪⁠⁪⁤⁢⁪‏‏​⁡⁠⁡‌⁢⁢​‎‎⁪⁡⁪⁠⁪⁤⁣⁪‏⁠‎⁪⁡⁪⁠⁪⁤⁤⁪‏⁠‎⁪⁡⁪⁠⁪⁢⁡⁡⁪‏‏​⁡⁠⁡‌⁢⁣​‎‏​⁢⁠⁡‌­
# ‎⁡R flag casts numbers to ranges
# ‎⁡M flag starts implicit ranges at 0
# The r flag reverses the arguments which makes the base conversion easier
34ƛ                # ‎⁢map over the range 0-34
⇧               # ‎⁣add 2, giving a range 2-36
54R            # ‎⁤Convert 54 to base B
6*9=Ṅ     # ‎⁢⁡separate the multiplication by spaces
ðpJ  # ‎⁢⁢add a space, and append the converted base

# -j flag joins output on newlines

💎


Created with the help of Luminespire.

# Julia 1.0, 59 bytes

2:36 .|>b->println("6 * 9 = ",uppercase(string(54,base=b)))


Try it online!

# Julia 0.6, 46 bytes

@.println("6 * 9 = ",uppercase(base(2:36,54)))


Try it online!