Avoid repeating letters between five simple programs

12

1

You're challenge is to write 5 different full programs for the 5 following tasks:

  1. Print Hello, World!

  2. Given an input with STDIN, output the factorial, you can assume that the input is an integer >= 0

  3. Given an integer N, calculate the sum of the primes <= N

  4. Given an input with STDIN, output the letters used in the input. For example: the input is Hello world, you need to output helowrd. Note that the output is in lowercase. You can assume that the input is always alphabetic with whitespaces, the whitespaces are ignored.

  5. Output the following diamond exactly like this:

       *
      ***
     *****
    *******
     *****
      ***
       *
    

All these challenges are probably very easy, but there is a catch. Every letter you use cannot be used again in the other programs. This is not prohibited, but will give you a penalty of +8 bytes. For example, if this is your program for the first task:

print("Hello, World!");

Then you cannot use the following letters (in uppercase or lowercase form): p, r, i, n, t, h, e, l, o, w, d in the other programs. If you do have to use them, you can 'buy' each letter for 8 bytes. So if you want to use the letter l again in another program, you get a penalty of 8 bytes. After you have paid the penalty, you can use each letter as much as you want in this program. Other characters don't matter. Also, all 5 programs should be in the same language.

This is , so least amount of bytes wins!

Adnan

Posted 2015-10-31T21:02:45.043

Reputation: 41 965

3This is a slightly different spin on challenges we've already had, but not different enough for it to not to be a multi-dupe in my eyes. – Mego – 2015-10-31T21:08:55.710

Does 8 bytes permit you to use a given letter as much as you like in the next program? – trichoplax – 2015-10-31T21:24:21.923

3@Mego I'd vote to close this as a multi-duplicate without the restriction, but the restriction makes it a whole new game. – trichoplax – 2015-10-31T21:25:02.200

1If you use a given letter in 3 programs, do you pay the 8 byte penalty twice (16 bytes)? – trichoplax – 2015-10-31T21:26:20.370

1@trichoplax, yes you pay 16 bytes – Adnan – 2015-10-31T21:28:29.643

1@trichoplax Hardly. The existing solutions for the duped problems will still be competitive. The top solutions here will just be the concatenation of the duped questions' solutions, with a higher score from the penalty. – Mego – 2015-10-31T21:47:04.143

1In TI-BASIC, there are tokens that display using certain letters (for example, sin( displays like sin(. However, they are not stored in memory that way (its token code is C2). Can we repeat the letters displayed without penalty? – lirtosiast – 2015-11-01T00:11:09.150

Are we allowed to have trailing spaces on the lines of Task 5? – lirtosiast – 2015-11-01T06:31:54.033

@ThomasKwa, the displayed letters don't matter, only the code matters. Also, trailing whitespaces are not allowed in task 5. – Adnan – 2015-11-01T10:20:47.890

@Mego although the existing solutions will be competitive at first, I would expect variations tailored to the new restriction to win eventually. I can't tell in advance though. – trichoplax – 2015-11-01T14:51:36.480

There just aren't enough versions of Print... – LegionMammal978 – 2015-11-07T21:47:04.300

Answers

10

CJam, 73 bytes

"Obkkh+'Phukc&"7f^
q~m!
ri){'j3+_3++~},:+
lS-el_&
4{_' *4@-Y*('**+}%_1>W%\+N*

Each line is a full program. Try them online: 1 | 2 | 3 | 4 | 5

Letter map

 bc  f h  k   op    u       18
            m   q            4
        ij       r          17
    e      l      s          7
             n        w y   27

If you want (and each of your programs fits in a line), you can use this CJam program to create a letter map for your own submission.

Dennis

Posted 2015-10-31T21:02:45.043

Reputation: 196 637

Proof that osascript wasn't built for this: Your entire submission is less than 2 of my programs. XD +1, nice job. – Addison Crump – 2015-11-01T14:28:44.613

4

Pyth, 90 bytes

First attempt...

Task 1: 20 bytes

+"Hello, "+C87"orld!

Task 2, 3 bytes

.!Q

Task 3, 9 bytes

sf}TPTSvz

Task 4, 6+8=14 bytes

@G{rw0

Task 5, 44 bytes

"   *
  ***
 *****
*******
 *****
  ***
   *

lirtosiast

Posted 2015-10-31T21:02:45.043

Reputation: 20 331

3

osascript, 759 Bytes

I knew this was going to be a lot when I started. o-o

Task 1: 15 Bytes

"Hello, World!"

I knew that it was going to be bad from this point.

Task 2: 64 + 8*4 = 96 Bytes

on run a
set o to 1
repeat a
set o to a*o
set a to a-1
end
o
end

Oh gawd.

Task 3: 170 + 8*13 = 274 Bytes

on run a
set o to 0
set t to false
repeat with i from 2 to a
set t to true
repeat with c from 2 to i-1
if i mod c=0 then set t to false
end
if t then set o to o+i
end
end

Dennis ≠ outgolfed.

Task 4: 225 + 8*13 = 329

on run a
set o to""
repeat with i in items of a
repeat with c in characters of i
if c is not in o then
if ASCII number of c<91 then
set o to o&(ASCII character of(ASCII number of c+32))
else
set o to o&c
end
end
end
end
o
end

...

Task 5: 45 Bytes

"   *
  ***
 *****
*******
 *****
  ***
   *"

So, yeah. I knew I was gonna lose from the start. But it was interesting, I'd be interested to know if there's a way to do this in fewer characters. Character map (as provided by Dennis):

   de  h   l  o  r    w     15
a cdef hi  lmnop rstu w    160
a  de        nop rstu       57
abcdef hi  lmnop rstu w    214
                            39
                             0

The character count above is slightly off - newlines made it have issues, as the newlines were uncounted.

NOTE: The reason for not using stuff like a's characters or the like is that the ' character has to be used when executing from the osascript command line. If I had used ', I'd have to use \' or something similar, which wouldn't have helped me at all. Also, it only recognizes " as string capturers, so I was kinda screwed there as well. But that was fun.

Addison Crump

Posted 2015-10-31T21:02:45.043

Reputation: 10 763

1

NARS2000 APL, 144 bytes (85 characters)

Task 1, 21 bytes (17 characters)

⎕←"Hello, World!"

Task 2, 10 bytes (4 characters)

⎕←!⎕

Task 3, 22 bytes (11 characters)

⎕←+/¯2π⍳2π⎕

Task 4, 53 bytes (29 characters)

⎕←∪Q[26∣Q⍸⍞∩Q←⎕AV[97+⍳26]∪⎕A]

Task 5, 38 bytes (24 characters)

⎕←" *"[1+4<∘.+⍨(⍳3),⊖⍳4]

Oberon

Posted 2015-10-31T21:02:45.043

Reputation: 2 881

1Are those actually full programs? I don't know NARS2000 (and it's not available on my platform), but all dialects I know require assigning to to print outside a REPL. – Dennis – 2015-11-01T16:58:40.340

@Dennis Sorry, forgot I was fiddling inside the REPL. – Oberon – 2015-11-01T17:12:00.163

You're not allowed to output trailing spaces for the diamond. – lirtosiast – 2015-11-02T23:53:06.297

1

Jelly, 46 bytes (non-competing)

“3ḅaė;œ»
Ɠ!
ÆRS
ɠQḲŒl
4Ḷ¤‘+¤ṖṚṭ×”*Fµ4Ḷṭ4ḶṚṖ¤F×⁶+⁸Y

Try it online! (Copy/paste each snippet)

Apparently, the restriction did not restrict golfing :) Just suggestions for the last one, of course, please.

Erik the Outgolfer

Posted 2015-10-31T21:02:45.043

Reputation: 38 134