Pointlessly make your way down the alphabet

40

Disclaimer: This challenge inspired by me spending the morning debugging recursive functions, which have been frying my brain a little.

Here's an example of recursion, from a letter, we keep going to the previous letter of the alphabet, printing out each one as we go, until we hit the letter a, then we print that and stop. We do this for each letter in a string and there's a pretty pattern at the end of it.

The task

  • Start with a string of characters
    • The input string may only contain the lower-case letters a-z and the space character.
  • For each letter, produce a line of text (terminal output or variable or whatever)
    • Print out the letter
    • Print out the previous letter (on the same line)
    • Print out the previous letter (on the same line)
    • Print out the previous letter (on the same line)
    • ...
    • If the letter is 'a', print it out and move to the next line.
    • If it's a space, print out an empty line (or one just containing the space character.

The rules

  • It's golf, try and make your code short.
  • Any language you like.
  • Please include a link to an online interpreter.
  • The output should be human-readable (e.g. I can't work it out from a list of bytes.
  • Follow the rules of the standard loopholes ¯\_(ツ)_/¯
  • Recursion is not mandated by the rules, but it's probably necessary.

Test Cases

Input: 'abcdefghijklmnopqrstuvwxyz' Output:

a
ba
cba
dcba
edcba
fedcba
gfedcba
hgfedcba
ihgfedcba
jihgfedcba
kjihgfedcba
lkjihgfedcba
mlkjihgfedcba
nmlkjihgfedcba
onmlkjihgfedcba
ponmlkjihgfedcba
qponmlkjihgfedcba
rqponmlkjihgfedcba
srqponmlkjihgfedcba
tsrqponmlkjihgfedcba
utsrqponmlkjihgfedcba
vutsrqponmlkjihgfedcba
wvutsrqponmlkjihgfedcba
xwvutsrqponmlkjihgfedcba
yxwvutsrqponmlkjihgfedcba
zyxwvutsrqponmlkjihgfedcba

Input: 'zyxwvutsrqponmlkjihgfedcba'

zyxwvutsrqponmlkjihgfedcba
yxwvutsrqponmlkjihgfedcba
xwvutsrqponmlkjihgfedcba
wvutsrqponmlkjihgfedcba
vutsrqponmlkjihgfedcba
utsrqponmlkjihgfedcba
tsrqponmlkjihgfedcba
srqponmlkjihgfedcba
rqponmlkjihgfedcba
qponmlkjihgfedcba
ponmlkjihgfedcba
onmlkjihgfedcba
nmlkjihgfedcba
mlkjihgfedcba
lkjihgfedcba
kjihgfedcba
jihgfedcba
ihgfedcba
hgfedcba
gfedcba
fedcba
edcba
dcba
cba
ba
a

Input: 'hello world' Output:

hgfedcba
edcba
lkjihgfedcba
lkjihgfedcba
onmlkjihgfedcba

wvutsrqponmlkjihgfedcba
onmlkjihgfedcba
rqponmlkjihgfedcba
lkjihgfedcba
dcba

AJFaraday

Posted 2019-11-21T12:25:43.067

Reputation: 10 466

2May we output a list of strings instead of a single string with linefeeds? – Arnauld – 2019-11-21T13:10:17.680

@Arnauld Fine with me – AJFaraday – 2019-11-21T13:10:31.270

@Shaggy That's correct, from 'the task': The input string may only contain the lower-case letters a-z and the space character. We can assume this, so there's no need for input validation. – AJFaraday – 2019-11-21T13:28:34.570

Can we have spaces between the letters in the output eg d c b a? – Jonah – 2019-11-21T19:58:39.693

12I don't think a single answer uses recursion – Jo King – 2019-11-22T01:39:25.987

3“Human readable” prohibits most of the languages popular here! – WGroleau – 2019-11-22T02:50:10.790

@Jonah that’s fine. – AJFaraday – 2019-11-22T06:44:51.023

@WGroleau if I’m unable to parse the result, how should I know if it’s a valid answer? – AJFaraday – 2019-11-22T06:45:52.470

1

I was expecting a challenge where you had to write point-free code.

– user2357112 supports Monica – 2019-11-22T08:05:26.957

If it passes all your test cases, then either it meets the requirements or your test cases are incorrect. Don’t get me wrong—after nearly forty years in software engineering, the last thing I’d do would be to encourage unreadable code. I just stop in here occasionally to see what the most extreme examples look like. – WGroleau – 2019-11-22T08:57:25.650

2@WGroleau Ah, I think I've spotted what's gone wrong here. I didn't require that the code should be human-readable, only the result. – AJFaraday – 2019-11-22T09:13:31.683

@user2357112supportsMonica Nope, just me being frustrated at the time. – AJFaraday – 2019-11-22T10:26:38.077

3Recursion is never necessary. At the very worst, you can just use stack data structure to have your own "recursion" in a flat loop, ending when the stack is empty. – Tomáš Zato - Reinstate Monica – 2019-11-22T11:41:50.117

May we have a leading newline character, before printing each line of text? – dingledooper – 2019-11-23T20:38:01.347

Answers

32

Dyalog APL Extended, 4 bytes

⌽∘⍳¨

Try it online!

 ∘    the function composition of
  ⍳     iota - 'a'..input for alphabet chars, empty array for space
⌽       and after, reverse
   ¨  applied to each

dzaima

Posted 2019-11-21T12:25:43.067

Reputation: 19 048

31We have peaked as a species. – TRose – 2019-11-21T22:16:51.697

3Answers in obscure languages usually make the language name a link to documentation. Could you add that? – Justin – 2019-11-22T01:01:12.640

2

@JustinLardinois I don't think APL is exactly an obscure language, but here's the link: APL - Wikipedia.

– Trebor – 2019-11-22T11:51:32.190

@JustinLardinois Added (I did manually remove the link from the TIO format when renaming the title...) The only used difference from regular Dyalog APL is the (surprisingly useful) extended . – dzaima – 2019-11-22T11:58:51.140

@Trebor APL isn't obscure, but this flavor of it is. It's not even mentioned in that Wikipedia article. – Justin – 2019-11-22T22:17:17.800

14

Haskell, 26 24 bytes

-2 bytes thanks to FrownyFrog.

map(\i->reverse['a'..i])

Try it online!

Pointless (or pointfree :P) for you.

totallyhuman

Posted 2019-11-21T12:25:43.067

Reputation: 15 378

224 with map(\i->reverse['a'..i]) – FrownyFrog – 2019-11-21T23:04:02.380

2Those darn enumFromThenTo functions and their ungolfiness. – totallyhuman – 2019-11-21T23:31:14.110

2I want to say map(\i->[i,pred i..'a']) but it's the same size. – Joseph Sible-Reinstate Monica – 2019-11-22T02:24:54.083

1I want to say map$ \i->reverse['a'..i] but it's the same size, too. – Andrew Ray – 2019-11-26T18:03:30.163

12

C (gcc),  58  56 bytes

Saved 2 bytes thanks to @KritixiLithos

c;f(char*s){while(c=c&&putchar(c>96?c:10)^10?c-1:*s++);}

Try it online!

Arnauld

Posted 2019-11-21T12:25:43.067

Reputation: 111 334

I believe the putchar call can be used in the while condition to save a byte. – user41805 – 2019-11-22T10:24:34.063

@KritixiLithos Thanks! This saves 2 bytes, although I suspect there's a way to save more. – Arnauld – 2019-11-22T10:52:35.653

You can also use 0 instead of 10 and get spaces instead of newlines between the outputs. (only tested on TIO YMMV) – John Hamilton – 2019-11-22T10:56:43.307

1@JohnHamilton The delimiter will then be NULL-bytes (\0). Although TIO shows them as spaces, most compilers will not show any output for NULL-bytes instead. 9 instead of 10 can be used with tab-delimiters though, for the same -2. – Kevin Cruijssen – 2019-11-22T11:03:20.753

@KevinCruijssen Yeah, you're right. It could create problems with the null character. Tab delimiter works better. – John Hamilton – 2019-11-22T11:05:09.377

9

Malbolge20 and Malbolge Unshackled polyglot, around 2MB, 107KB compressed.

Alright. I spent around 30 minutes on this answer (current record). It's really optimal answer. Albeit not so fast and not so memory-exhausting (only ~512 megabytes), it's still a Malbolge answer so please keep that noted.

The program is packed using 7zip and PPMd compression algorithm. You can download it here.

Interpreter that works the best with the program.

#include <malloc.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

const char* translation = "5z]&gqtyfr$(we4{WP)H-Zn,[%\\3dL+Q;>U!pJS72Fh"
        "OA1CB6v^=I_0/8|jsb9m<.TVac`uY*MK'X~xDl}REokN:#?G\"i@";

typedef struct Word {
    unsigned int area;
    unsigned int high;
    unsigned int low;
} Word;

void word2string(Word w, char* s, int min_length) {
    if (!s) return;
    if (min_length < 1) min_length = 1;
    if (min_length > 20) min_length = 20;
    s[0] = (w.area%3) + '0';
    s[1] = 't';
    char tmp[20];
    int i;
    for (i=0;i<10;i++) {
        tmp[19-i] = (w.low % 3) + '0';
        w.low /= 3;
    }
    for (i=0;i<10;i++) {
        tmp[9-i] = (w.high % 3) + '0';
        w.high /= 3;
    }
    i = 0;
    while (tmp[i] == s[0] && i < 20 - min_length) i++;
    int j = 2;
    while (i < 20) {
        s[j] = tmp[i];
        i++;
        j++;
    }
    s[j] = 0;
}

unsigned int crazy_low(unsigned int a, unsigned int d){
    unsigned int crz[] = {1,0,0,1,0,2,2,2,1};
    int position = 0;
    unsigned int output = 0;
    while (position < 10){
        unsigned int i = a%3;
        unsigned int j = d%3;
        unsigned int out = crz[i+3*j];
        unsigned int multiple = 1;
        int k;
        for (k=0;k<position;k++)
            multiple *= 3;
        output += multiple*out;
        a /= 3;
        d /= 3;
        position++;
    }
    return output;
}

Word zero() {
    Word result = {0, 0, 0};
    return result;
}

Word increment(Word d) {
    d.low++;
    if (d.low >= 59049) {
        d.low = 0;
        d.high++;
        if (d.high >= 59049) {
            fprintf(stderr,"error: overflow\n");
            exit(1);
        }
    }
    return d;
}

Word decrement(Word d) {
    if (d.low == 0) {
        d.low = 59048;
        d.high--;
    }else{
        d.low--;
    }
    return d;
}

Word crazy(Word a, Word d){
    Word output;
    unsigned int crz[] = {1,0,0,1,0,2,2,2,1};
    output.area = crz[a.area+3*d.area];
    output.high = crazy_low(a.high, d.high);
    output.low = crazy_low(a.low, d.low);
    return output;
}

Word rotate_r(Word d){
    unsigned int carry_h = d.high%3;
    unsigned int carry_l = d.low%3;
    d.high = 19683 * carry_l + d.high / 3;
    d.low = 19683 * carry_h + d.low / 3;
    return d;
}

// last_initialized: if set, use to fill newly generated memory with preinitial values...
Word* ptr_to(Word** mem[], Word d, unsigned int last_initialized) {
    if ((mem[d.area])[d.high]) {
        return &(((mem[d.area])[d.high])[d.low]);
    }
    (mem[d.area])[d.high] = (Word*)malloc(59049 * sizeof(Word));
    if (!(mem[d.area])[d.high]) {
        fprintf(stderr,"error: out of memory.\n");
        exit(1);
    }
    if (last_initialized) {
        Word repitition[6];
        repitition[(last_initialized-1) % 6] =
                ((mem[0])[(last_initialized-1) / 59049])
                    [(last_initialized-1) % 59049];
        repitition[(last_initialized) % 6] =
                ((mem[0])[last_initialized / 59049])
                    [last_initialized % 59049];
        unsigned int i;
        for (i=0;i<6;i++) {
            repitition[(last_initialized+1+i) % 6] =
                    crazy(repitition[(last_initialized+i) % 6],
                        repitition[(last_initialized-1+i) % 6]);
        }
        unsigned int offset = (59049*d.high) % 6;
        i = 0;
        while (1){
            ((mem[d.area])[d.high])[i] = repitition[(i+offset)%6];
            if (i == 59048) {
                break;
            }
            i++;
        }
    }
    return &(((mem[d.area])[d.high])[d.low]);
}

unsigned int get_instruction(Word** mem[], Word c,
        unsigned int last_initialized,
        int ignore_invalid) {
    Word* instr = ptr_to(mem, c, last_initialized);
    unsigned int instruction = instr->low;
    instruction = (instruction+c.low + 59049 * c.high
            + (c.area==1?52:(c.area==2?10:0)))%94;
    return instruction;
}

int main(int argc, char* argv[]) {
    Word** memory[3];
    int i,j;
    for (i=0; i<3; i++) {
        memory[i] = (Word**)malloc(59049 * sizeof(Word*));
        if (!memory) {
            fprintf(stderr,"not enough memory.\n");
            return 1;
        }
        for (j=0; j<59049; j++) {
            (memory[i])[j] = 0;
        }
    }
    Word a, c, d;
    unsigned int result;
    FILE* file;
    if (argc < 2) {
        // read program code from STDIN
        file = stdin;
    }else{
        file = fopen(argv[1],"rb");
    }
    if (file == NULL) {
        fprintf(stderr, "File not found: %s\n",argv[1]);
        return 1;
    }
    a = zero();
    c = zero();
    d = zero();
    result = 0;
    while (!feof(file)){
        unsigned int instr;
        Word* cell = ptr_to(memory, d, 0);
        (*cell) = zero();
        result = fread(&cell->low,1,1,file);
        if (result > 1)
            return 1;
        if (result == 0 || cell->low == 0x1a || cell->low == 0x04)
            break;
        instr = (cell->low + d.low + 59049*d.high)%94;
        if (cell->low == ' ' || cell->low == '\t' || cell->low == '\r'
                || cell->low == '\n');
        else if (cell->low >= 33 && cell->low < 127 &&
                (instr == 4 || instr == 5 || instr == 23 || instr == 39
                    || instr == 40 || instr == 62 || instr == 68
                    || instr == 81)) {
            d = increment(d);
        }
    }
    if (file != stdin) {
        fclose(file);
    }
    unsigned int last_initialized = 0;
    while (1){
        *ptr_to(memory, d, 0) = crazy(*ptr_to(memory, decrement(d), 0),
                *ptr_to(memory, decrement(decrement(d)), 0));
        last_initialized = d.low + 59049*d.high;
        if (d.low == 59048) {
            break;
        }
        d = increment(d);
    }
    d = zero();

    unsigned int step = 0;
    while (1) {
        unsigned int instruction = get_instruction(memory, c,
                last_initialized, 0);
        step++;
        switch (instruction){
            case 4:
                c = *ptr_to(memory,d,last_initialized);
                break;
            case 5:
                if (!a.area) {
                    printf("%c",(char)(a.low + 59049*a.high));
                }else if (a.area == 2 && a.low == 59047
                        && a.high == 59048) {
                    printf("\n");
                }
                break;
            case 23:
                a = zero();
                a.low = getchar();
                if (a.low == EOF) {
                    a.low = 59048;
                    a.high = 59048;
                    a.area = 2;
                }else if (a.low == '\n'){
                    a.low = 59047;
                    a.high = 59048;
                    a.area = 2;
                }
                break;
            case 39:
                a = (*ptr_to(memory,d,last_initialized)
                        = rotate_r(*ptr_to(memory,d,last_initialized)));
                break;
            case 40:
                d = *ptr_to(memory,d,last_initialized);
                break;
            case 62:
                a = (*ptr_to(memory,d,last_initialized)
                        = crazy(a, *ptr_to(memory,d,last_initialized)));
                break;
            case 81:
                return 0;
            case 68:
            default:
                break;
        }

        Word* mem_c = ptr_to(memory, c, last_initialized);
        mem_c->low = translation[mem_c->low - 33];

        c = increment(c);
        d = increment(d);
    }
    return 0;
}

It works!

It works!

Krzysztof Szewczyk

Posted 2019-11-21T12:25:43.067

Reputation: 3 819

8

PowerShell, 37 28 bytes

-9 bytes thanks to mazzy

$args|%{-join($_..'a'-le$_)}

Try it online!

Takes input via splatting and uses char ranges introduced in PS v6. The range is then filtered out by only taking elements that are less than the current character. This in turns means decreasing ranges are unaffected (e.g. 'z'..'a') whereas increasing ranges (e.g. ' '..'a') will filter out everything except the space.

Veskah

Posted 2019-11-21T12:25:43.067

Reputation: 3 580

2

you can save some bytes Try it online!

– mazzy – 2019-11-21T15:17:25.020

1@mazzy I will never in my life remember to filter a range. Thanks – Veskah – 2019-11-21T15:26:16.120

6

JavaScript (Node.js), 56 bytes

Takes input as a list of characters. Returns a list of strings.

s=>s.map(g=c=>(c|=(B=Buffer)(c)[0])>96?B([c--])+g(c):'')

Try it online!

Commented

s =>                 // s[] = input characters
  s.map(g = c =>     // for each character c in s[], using the recursive function g:
    ( c |=           //   update c:
        (B = Buffer) //     on the first iteration, c is a character and Buffer(c)[0]
        (c)[0]       //     returns its ASCII code; on later iterations, c is an
                     //     integer and Buffer(c) creates a buffer filled with NUL bytes
    ) > 96 ?         //     if c is greater than 96:
      B([c--])       //       append the character of ASCII code c and decrement c
      + g(c)         //       append the result of a recursive call
    :                //     else:
      ''             //       stop recursion
  )                  // end of map()

Arnauld

Posted 2019-11-21T12:25:43.067

Reputation: 111 334

6

R, 63 62 61 bytes

-16 bytes thanks to Giuseppe

-7 more bytes, again, thanks to Giuseppe

-1 byte adding a line break in place of \n

-1 byte thanks to Robin Ryder

for(l in utf8ToInt(scan(,""))-96)cat(letters[l:0],'
',sep="")

Try it online!

R, 86 bytes (my original answer)

x=utf8ToInt(scan(,''));s=sapply;cat(gsub(" .+"," ",s(s(x,`:`,97),intToUtf8)),sep="\n")

Ungolfed:

x=utf8ToInt(scan(,''))                                 #Takes input, converts to ASCII
s=sapply;                                              #Alias sapply function to save a byte
                     s(x,`:`,97)                       #Create vector from 97 to respective ASCII value
                   s(           ,intToUtf8)            #Convert to character
    gsub(" .+"," ",                        )           #Removes everything after space
cat(                                        ,sep="\n") #Outputs to console

Try it online!

Could likely be golfed.

NOTE: It does not use recursion. I do not know whether that would be shorter or not. I'll experiment later.

Sumner18

Posted 2019-11-21T12:25:43.067

Reputation: 1 334

180 bytes – Giuseppe – 2019-11-21T19:37:28.480

Just when I felt confident I had found a solid answer, @Giuseppe comes back again with something better! As expected... – Sumner18 – 2019-11-21T19:52:02.963

well if we put our heads together, we get this beautiful 70 byte answer -- sadly, sapply is often longer than a for loop!

– Giuseppe – 2019-11-21T20:31:11.773

I've recognized that, but I was hoping it would win in this case. Once again, I was proven wrong. – Sumner18 – 2019-11-21T20:35:09.180

2

ooh, or 63 bytes -- I'm just very excited to get back into golfing!!!!

– Giuseppe – 2019-11-21T20:36:51.787

1Aha, I found 1 more byte! I don't feel as useless anymore. Haha – Sumner18 – 2019-11-21T20:44:53.537

161 bytes – Robin Ryder – 2019-11-22T13:08:58.830

6

C (gcc), 56, 53 bytes

c;f(char*s){for(c=*s;c;)putchar(c<97?c=*++s,10:c--);}

Try it online!

Now down to 53 bytes! It can probably be golfed more though...

dingledooper

Posted 2019-11-21T12:25:43.067

Reputation: 421

You can put your putchar call as the second statement of your for loop, since putchar returns the value of the character just written i.e. c. Saves you a grand total of one byte. – Orion – 2019-11-23T17:32:12.407

Thanks for the insight. I don't think it works though, since c=*++s,10 actually returns 10. Please correct me if I'm wrong though! – dingledooper – 2019-11-23T20:00:31.377

5

Perl 6, 24 bytes

*.comb>>.&{[R~] 'a'..$_}

Try it online!

Returns a list of strings.

Explanation

*.comb  # Split into characters
      >>.&{            }  # Map to
                'a'..$_   # Range 'a' to current character
           [R~]           # Reverse concat

nwellnhof

Posted 2019-11-21T12:25:43.067

Reputation: 10 037

5

Python 3, 65 bytes

lambda s:print([''.join(map(chr,range(ord(c),96,-1)))for c in s])

Outputs a list of strings as clarified in @Arnauld's comment.

If we could assume that a string s existed with the content it would be 56 bytes.

Try it online!

Brojowski

Posted 2019-11-21T12:25:43.067

Reputation: 141

1I didn't see this before I posted my very similar edit for a second method in my answer. You beat me by managing to lose the second map and keeping it looking nice :) +1 – ElPedro – 2019-11-21T17:27:49.313

2

btw, you can get it down to 58 as you don't need the print inside the lambda. It's allowed to just return the value then print it from outside.

– ElPedro – 2019-11-21T17:35:29.890

5

Jelly,  8  7 bytes

A monadic link returning a list of strings.

ḲOr97ỌK

Try it online!

ḲOr97ỌK   - a monadic link taking a string, e.g. "ab c"
Ḳ         - split at spaces                 --> ["ab", "c"]
 O        - get ASCII codes                 --> [[97, 98], [99]]
  r97     - build descending range to 97    --> [[[97], [98, 97]], [[99, 98, 97]]]
     Ọ    - turn back into ASCII            --> [["a", "ba"], ["cba"]]
      K   - join with spaces                --> ["a", "ba", " ", "cba"]

Arnauld

Posted 2019-11-21T12:25:43.067

Reputation: 111 334

2You asked if we may output a list of lines - since we may you can safely remove the trailing Y (add ÇY to the footer to show it run as a full program) - I posted a different 7 too :) – Jonathan Allan – 2019-11-25T18:33:18.760

5

Sed (with -r switch), 65 61 60 59 characters

s/./&zyxwvutsrqponmlkjihgfedcba \n/g
s/(.).*\1/\1/gm
s/ //g

Thanks to:

  • Kritixi Lithos for finding an unnecessary capturing (-3 characters)
  • Kritixi Lithos for anchoring to line start not anchoring instead of word start (-1 2 characters)
  • Kritixi Lithos for combining the 2 solutions advantages (2 characters)

Sample run:

bash-5.0$ sed -r 's/./&zyxwvutsrqponmlkjihgfedcba \n/g;s/(.).*\1/\1/gm;s/ //g' <<< 'cg cc'
cba
gfedcba

cba
cba

Try it online!

Sed (with -r switch), 53 52 characters

s/./&zyxwvutsrqponmlkjihgfedcba \n/g
s/(.).*\1/\1/gm

In case trailing spaces are acceptable.

Try it online!

manatwork

Posted 2019-11-21T12:25:43.067

Reputation: 17 865

The capturing group in the first substitution can be removed, and the second substitution can be shortened by a bit. Additionally you can find another way to treat spaces (note the rules allow printing a space instead of a blank line when the char is a space) to golf it some more. – user41805 – 2019-11-21T18:10:55.223

Thank you, @KritixiLithos. I was so happy I got rid of initial 77 character version with looping, that I forgot to recheck some details. – manatwork – 2019-11-21T18:47:29.793

One more byte can be removed from the second substitution (60b), and you can use the approach by the 53-byte solution to get a valid solution shorter than the now 60 byte solution. – user41805 – 2019-11-22T06:55:47.620

Thank you, @KritixiLithos. No I idea why I kept anchoring that expression. – manatwork – 2019-11-22T18:37:40.557

Maybe you missed the second part of my comment, you can have s/ // at the end of the 52b solution to get a valid 58b solution – user41805 – 2019-11-23T16:09:40.310

No, didn't missed it, just didn't understood it until now. Thank you for another 2 characters saved. But unfortunately I just found a bug in my code and the earlier correct version should be 61 characters. (Due to the lacking g flag on the 3rd substitution, the code didn't handled correctly more than 1 spaces. ☹) – manatwork – 2019-11-23T18:39:15.487

5

K (oK), 17 14 bytes

-3 bytes thanks to streetster

-3 bytes thanks to ngn

`c$96-!:'0&96-

Try it online!

Galen Ivanov

Posted 2019-11-21T12:25:43.067

Reputation: 13 815

1You dont need to wrap it in a lambda; f:{`c$97+|!0|x-96}' – streetster – 2019-11-23T19:48:42.100

1@streetster Yes, of course! Thank you! – Galen Ivanov – 2019-11-23T19:54:10.613

1!x works for negative ints too, giving us a reverse for free: {\c$96-!0&96-x}'` – ngn – 2019-11-24T15:22:22.360

1without the lambda: \c$96-!:'0&96-` – ngn – 2019-11-24T15:27:15.027

@ngn Thank you! I think I didn't know about ! with negative argument until now. – Galen Ivanov – 2019-11-24T18:37:14.253

1it depends on the version of k. afaik in k5 !-n was "permutations", in k6 (and ngn/k and oK) !-n was -n-!n, and in other versions it's an error. – ngn – 2019-11-24T18:45:31.507

4

Ruby, 41 characters

->s{s.chars{|c|puts [*?a..c].reverse*''}}

or

->s{s.gsub(/./){[*?a..$&].reverse*''+$/}}

No recursion here.

Sample run:

irb(main):001:0> ->s{s.chars{|c|puts [*?a..c].reverse*''}}['cgcc']
cba
gfedcba
cba
cba

Try it online!

manatwork

Posted 2019-11-21T12:25:43.067

Reputation: 17 865

4

05AB1E, 14 12 5 bytes

AAηí‡

-2 bytes by outputting as a list of strings.
-7 bytes (byte-count more than halved) thanks to @Grimy.

Input as a list of characters.

Try it online or verify all test cases.

Or alternatively:

AÂ.s‡

Try it online or verify all test cases.

Explanation:

A      # Push the lowercase alphabet
 Aη    # Push a list of prefixes of the lowercase alphabet
   í   # Reverse each prefix
    ‡  # Transliterate all characters of the alphabet to these reversed prefixes in
       # the (implicit) input-list
       # (after which the resulting string-list is output implicitly)

A      # Push the lowercase alphabet
 Â     # Bifurcate it; short for Duplicate & Reverse copy
  .s   # Get the prefixes of that reversed alphabet
    ‡  # Transliterate all characters of the alphabet to these reversed prefixes in
       # the (implicit) input-list
       # (after which the resulting string-list is output implicitly)

Kevin Cruijssen

Posted 2019-11-21T12:25:43.067

Reputation: 67 575

2k followed by è is just the built-in. This yields a 6: εAAηí‡. And if we take input as a list of characters, we can omit the ε for a 5, though that might be pushing it, since output has to be a list of lines, not characters. – Grimmy – 2019-11-21T19:54:34.260

@Grimmy "k followed by è is just the built-in." I'm such an idiot.. And taking a string input as a list of characters is allowed by default, since in most languages a string simply is a CharacterSequence. So thanks for more than halving my byte-count.. :D – Kevin Cruijssen – 2019-11-21T22:24:52.620

Alternate 5-byter: AÂ.s‡ – Grimmy – 2019-11-29T13:09:11.530

4

Wren, 103 bytes

Hopefully this beats the Lua answer.

Fn.new{|x|
for(i in x)System.print(i==" "?"":(i.bytes[0]..97).map{|j|String.fromCodePoint(j)}.join())
}

Try it online!

Wren, 159 bytes

I am not having enough fun.

Fn.new{|x|
for(i in 122..97)x=x.replace(String.fromCodePoint(i),String.fromCodePoint(i)+String.fromCodePoint(i-1))
return x.replace("`","
").replace(" ","
")
}

Try it online!

user85052

Posted 2019-11-21T12:25:43.067

Reputation:

Unfortunately, this fails the 'hello world' case. There's a special case for the space character, which should just step on to the next line. – AJFaraday – 2019-11-21T14:22:18.747

4

PostgreSQL, 119 characters

\prompt s
select(select string_agg(chr(s),'')from generate_series(ascii(c),97,-1)s)from regexp_split_to_table(:'s','')c

(Those verbose function names are killing me…)

Sample run:

bash-5.0$ psql -Atf pointlessly-recurse.sql <<< 'hello world'
hgfedcba
edcba
lkjihgfedcba
lkjihgfedcba
onmlkjihgfedcba

wvutsrqponmlkjihgfedcba
onmlkjihgfedcba
rqponmlkjihgfedcba
lkjihgfedcba
dcba

manatwork

Posted 2019-11-21T12:25:43.067

Reputation: 17 865

4

V (vim), 15 bytes

\Óçá/A¬za
͈…±

Try it online!

Hexdump:

00000000: 5cd3 e7e1 2f41 ac7a 610d cd88 8185 b1    \.../A.za......

Fun fact: Recursion is the only form of looping that V has, yet this submission doesn't use any.

James

Posted 2019-11-21T12:25:43.067

Reputation: 54 537

4

Befunge-98 (PyFunge), 18 bytes

#@~#;:'``j;:,1-;a,

Try it online!

david

Posted 2019-11-21T12:25:43.067

Reputation: 180

4

PHP, 88 bytes

<?php
for(;$i<strlen($s=$argv[1]);){for($j=ord($s[$i++]);$j>96;)echo chr($j--);echo"
";}

Try it online!

Thanks to Shaggy for -21 bytes! :)

Dan D.

Posted 2019-11-21T12:25:43.067

Reputation: 141

Also, if you can figure out how to get shorttags working on TIO, you can save another 4. I can never remember! – Shaggy – 2019-11-22T22:45:48.417

4

Jelly, 7 bytes

Øa>Ðḟ)U

A monadic link accepting a list of characters which yields a list of lists of characters.

Try it online! (adds newlines, since as a full program Jelly will print a smashed version of the lists)

How?

Øa>Ðḟ)U - Link: list of characters, S
     )  - for each (character, c, in S):
Øa      -   yield the lowercase alphabet ['a', 'b', ..., 'z']
   Ðḟ   -   filter discard those for which:
  >     -     greater than (c)?
      U - reverse each resulting list (each line)

Jonathan Allan

Posted 2019-11-21T12:25:43.067

Reputation: 67 804

4

Brainfuck, 240 chars

,[>,[>+>+<<-]>------------------------------------------------------------------------------------------------[>.-<-]++++++++++.---------->------------------------------------------------------------------------------------------------<<<-]

Try it online!

Explanation:

, takes an input for the length of the input for the loop

[>,[>+>+<<-]> takes an input and duplicates it

------------------------------------------------------------------------------------------------ takes 97 from the ascii value of the input to iterate over

[>.-<-] outputs the ascii character and then takes one away from the pointer, ready for the next loop

++++++++++.----------> outputs the newline

------------------------------------------------------------------------------------------------<<<-] resets everything ready for another iteration

brainfuck best language

Posted 2019-11-21T12:25:43.067

Reputation: 41

Can be golfed down quite a bit by just using loops for the reset to 0 and subtracting a constant value. This also fixes the problem, that your answer ignores the first letter. 66 bytes But it also has the problem, that it fails when you put in a space (like your solution)

– david – 2019-12-12T10:16:39.680

89 bytes including the check for space. Other than that, basically the same solution you used. – david – 2019-12-12T11:02:33.630

Thanks @david, forgot about that! – brainfuck best language – 2019-12-13T11:47:18.497

3

Japt -mR, 6 bytes

Takes input as an array of characters.

;CÔk>U

Try it

Shaggy

Posted 2019-11-21T12:25:43.067

Reputation: 24 623

3

GolfScript, 27 18 17 bytes

{),97>-1%10}/]''+

Try it online!

Explanation:

 {           }/       Iterate over (implicit) input
  ),                  Create array [0 1 2 ... n]
    97>               Remove items less than 97
        -1%           Reverse order
           10         Push 10
               ]      Place in array
                ''+   Convert ascii values to string

Pseudo Nym

Posted 2019-11-21T12:25:43.067

Reputation: 181

3

SNOBOL4 (CSNOBOL4), 94 bytes

	I =INPUT
S	I LEN(1) . X REM . I	:F(END)
	Y =
	&LCASE ARB . Y X
	OUTPUT =X REVERSE(Y)	:(S)
END

Try it online!

Giuseppe

Posted 2019-11-21T12:25:43.067

Reputation: 21 077

3

Bash, 73 63 57 bytes

while read -n1 a;do [ - $a]&&echo||eval echo {$a..a};done

Try it online!

-6 bytes thanks to Kritixi Lithos

Jonah

Posted 2019-11-21T12:25:43.067

Reputation: 8 729

1You can skip out on fold with read -n1 a. Also apparently [ = $a] can replace [ -z $a] – user41805 – 2019-11-22T10:26:49.563

Beautiful. Tyvm. – Jonah – 2019-11-22T12:28:02.123

3

Brachylog, 13 bytes

ẹ{;Ẓ↔⟨a₁h⟩|}ᵐ

Try it online!

This feels... bad.

ẹ{         }ᵐ    For each element of the input,
      a₁         output the suffix of
   Ẓ             the lowercase alphabet reversed
  ; ↔⟨  h⟩       for which the first element is the input,
          |      or the input if there is no such suffix.

A 9-byte generator is possible if spaces are completely ignored: ∋;Ẓ↔⟨a₁h⟩. Accounting for spaces brings it up to the same byte count:

Brachylog, 13 bytes

∋{;Ẓ↔⟨a₁h⟩!|}

Try it online!

Unrelated String

Posted 2019-11-21T12:25:43.067

Reputation: 5 300

Without handling spaces, a 9 byte generator is possible: ∋;Ẓ↔⟨a₁h⟩

– Unrelated String – 2019-11-22T01:45:35.920

3

Julia 1.0, 36 29 bytes

f(s)=[join(i:-1:'a') for i=s]

Try it online!

Note: Outputs as an array of strings.

To display in a nice output format, use, for example, println.(f("hello world"))

Glen O

Posted 2019-11-21T12:25:43.067

Reputation: 2 548

26 bytes by using an anonymous function and broadcast over a generator: s->join.(i:-1:'a' for i=s) – TimD – 2019-11-22T07:21:12.600

3

Poetic, 482 bytes

transmit a letter or two,a-z
enter in letters from a-z+space
i did a print,i say a letter&go down
i am moving in a cycle
i get to letter a,and maybe to space
i then create lines as i output the ten,a ASCII N/L char
i figure x>y,and i do admire a way i check it
if indeed x>y,then i rerun;if not,i finish it to output N/L char
i write it out&i follow it up until no char i input is here
o,et cetera as i run
i do admit,i do run relatively longish
o,i say,i do loads of BS deriving it

Try it online!

Not sure why no one's posted a pure brainfuck solution yet, the brainfuck program I made this poem from amounts to only 108 bytes.

JosiahRyanW

Posted 2019-11-21T12:25:43.067

Reputation: 2 600

3

Scala, 53 bytes

def f(s:String)=s.map(c=>('a'to c).reverse.mkString) 

Try it online!

Note: return the list of strings. To do the actual output, use .map(println) or so

trolley813

Posted 2019-11-21T12:25:43.067

Reputation: 225

Save 10 bytes by using lambdas: (_: String).map('a'.to(_).reverse.mkString) Try it online!

– Soren – 2019-11-23T19:12:20.130

3

IBM/Lotus Notes Formula, 116 bytes

a:="zyxwvutsrqponmlkjihgfedcba";p:="";@For(x:=1;x<=@Length(i);x:=x+1;c:=@Right(@Left(i;x);1);p:=p:(c+@Right(a;c)));p

I have never found a practical use for @For except when golfing.

enter image description here

ElPedro

Posted 2019-11-21T12:25:43.067

Reputation: 5 301

3

Common Lisp, 127 bytes

Also the first truly recursive answer:

(labels((p(x)(princ(code-char x))(if(< 97 x)(p(1- x))(terpri)))(s(s n)(p(char s n))(if(>(length s)n)(s(1+ n))))(x(s)(s 0)))#'x)

Test:

(funcall (labels((p(x)(princ(code-char x))(if(< 97 x)(p(1- x))(terpri))t)
                 (s(n s)(and(>(length s)n)(p(char-code(char s n)))(s(1+ n)s)))
                 (x(s)(s 0 s)))#'x)
         "hello world")

Try it online!

The recursive p function prints from an ascii code down to 97, then a newline (terpri) (this also covers the space case since its code is 32).

The recursive s function iterates over string s by increasing index n, calling p at each step for the character at position n.

coredump

Posted 2019-11-21T12:25:43.067

Reputation: 6 292

3

Retina, 38 bytes

L$`.
27*$&
+T` l`_al`(?<=(.))\1+
aa+
a

Try it online! Explanation:

L$`.
27*$&

List each character 27 times each on its own line.

+T` l`_al`(?<=(.))\1+

Count all the characters back down to a, except the first of each run, and also delete trailing spaces.

aa+
a

Remove trailing as.

Neil

Posted 2019-11-21T12:25:43.067

Reputation: 95 035

3

PHP, 68 63 55 bytes

Simple approach, similar to my previous answer.

for(;$c=$argn[$i++];)echo$c<a?"":join(range($c,a)),"\n";

The \n was counted as 1 character, not 2 characters.

This is meant to be used with php -R.


Thanks to @manatwork for saving 5 bytes, and providing the link to try the code: https://tio.run/##BcHRCYAgEADQ/6YQEVSoBSpohxaI6zKvEE9OofHtvRMq9UJFTbuy/WYJgORqk6OW9DRnQGL2UA36gMQGV9i0nl9@shPIMTiDI3g/6kEv3XYKKbH6WNL1Aw

Thanks to @Shaggy for saving another 8 bytes, and providing an updated link: https://tio.run/##BcFBCoAgEADAe68QWVDRPpBFf@gaHTYzNcQVO/R8mznxjb3GysaNiX5TkxbcAthC2SFpfVjlXSRwM66cTw@lIhuW4CU4g0oZPnDbRY8@Z2IftXz9

Ismael Miguel

Posted 2019-11-21T12:25:43.067

Reputation: 6 797

The only input character below “a” will be “ ”, so you can just use $c<a instead of $c==' '. And the $glue parameter of join() is optional and “Defaults to an empty string.” Try it online!

– manatwork – 2019-11-22T18:02:31.913

@manatwork Thanks for the tips. I was mostly just banging out a solution. – Ismael Miguel – 2019-11-22T18:06:45.687

55 bytes – Shaggy – 2019-11-23T00:32:06.170

@Shaggy Thank you! I didn't though about trying that. – Ismael Miguel – 2019-11-25T09:42:58.557

3

J, 22 bytes

(u:97+i._26)&(i.}.[)"0

Try it online!

Traws

Posted 2019-11-21T12:25:43.067

Reputation: 331

3

Keg, 33 bytes

@f1|: =[,|:a=[,|:,;@fƒ]]ƒ?(@fƒ
,)

Try it online!

Unlike most people here, this answer actually uses recursion!

Keg, -ir -lp, 22 bytes

(: >[:&aɧ(&\`-;|,)],
,

Try it online!

Iterative approach as suggested by @A

Lyxal

Posted 2019-11-21T12:25:43.067

Reputation: 5 253

3

Lua, 99 bytes

function r(l)return l:find"[` ]"and"\n"or l..r(string.char(l:byte()-1))end
print((...):gsub(".",r))

Try it online!

Only works if we can have redundant output, else +1 byte.

Explanation

Creates a recursive function r that returns what each letter should turn into. When the input letter of this function is a space or the character before a (which is `) then this should not be printed, but a new line instead.

Replace each character in the input string (the first command-line argument) with the output of the function r called with this character.

Anderium

Posted 2019-11-21T12:25:43.067

Reputation: 81

3

Matlab / Octave, 25 bytes

for i=s['' i-0:-1:97]
end

Assumes the input string s, prints out to console.

  • Iterate over the contents of the string with for i=s
  • i-0 implicitly converts char to number
  • num:-1:97 outputs the range descending from the number down to 97 (ascii a)
  • space results in empty output as it already is less than 97
  • ['' int] concatenates an empty char with a number, resulting in a char (saves one byte compared to char(num).
  • each loop iteration output is printed as a line to console, which is what Matlab does when there is no semicolon terminating the line.

Try it online!

Lukas K.

Posted 2019-11-21T12:25:43.067

Reputation: 191

3

brainf**k 123 bytes

,[>>[-]<----[---->+<]>+<++++[->>++++++++<<]++++++++++>>[-<<<->>>>+<]<<<[->>->[-]+>+<<<<]>>>[-<[+>>.-<<]>]<<.[-]>>>[-]<<<<,]

Try it online!

Not better than the other brainfuck solutions posted in the comments, but still too much work not to post it ;-) In contrast to the bf solutions above, this does not need a circular cell ring.

How it works

p0 
,
[  {input}
p1 >  
p2 > [-] < ----[---->+<]>+< #64
p3 ++++[->>++++++++<<]  #32
p1 ++++++++++ # 10
p2 >
p3 >
   [
     -
p2   <
p1   <
p0   < -
p1   >
p2   >
p3   >
p4   > +
p3   <
   ]
p2 <
p1 <
p0 <
   [
     -
p1   >
p2   > -
p3   >[-]+ # indicates that output is required
p4   > +
p3   <
p2   <
p1   <
p0   <
   ]
p1 > 
p2 >
p3 >  # if output required
   [
     -
p2   <
     [
       +
p3     >
p4     > . -
p3     <
p2     <
     ]
p3   >
   ]
p2 <
p1 < . [-]   
p2 >
p3 >
p4 > [-]
p3 <
p2 <
p1 <
p0 < ,
]

Patrick Happel

Posted 2019-11-21T12:25:43.067

Reputation: 141

3

naz, 104 bytes

2a2x1v2m8m2x2v3m1a2x3v1x1f3x1v4e3x2v3e1o2f0x1x2f3x3v3e1s1o2f0x1x3f1r3x1v4e2x4v0m9a1a1o4v1f0x1x4f0a0x1r1f

Works for any input string terminated with the control character STX (U+0002).

If an extra trailing newline is allowed, we can save another 14 bytes:

2a2x1v2m8m2x2v3m1a2x3v1x1f1r3x1v4e3x2v3e1o2f0x1x2f3x3v3e1s1o2f0x1x3f0m9a1a1o1f0x1x4f0a0x1f

Explanation of the 104-byte version (with 0x commands removed)

2a2x1v                       # Set variable 1 equal to 2
2m8m2x2v                     # Set variable 2 equal to 32 (space)
3m1a2x3v                     # Set variable 3 equal to 97 ("a")
1x1f3x1v4e3x2v3e1o2f         # Function 1
                             # Jump to function 4 if the register equals variable 1
                             # Jump to function 3 if the register equals variable 2
                             # Otherwise, output and jump to function 2
1x2f3x3v3e1s1o2f             # Function 2
                             # Jump to function 3 if the register equals variable 3
                             # Otherwise, subtract 1, output,
                             # and jump back to the start of the function
1x3f1r3x1v4e                 # Function 3
                             # Read a byte
                             # Jump to function 4 if it equals variable 1
            2x4v             # Otherwise, store it in variable 4,
                0m9a1a1o     # output a newline,
                        4v1f # read variable 4 into the register, and jump to function 1
1x4f0a                       # Function 4
                             # Add 0 to the register
1r1f                         # Read the first byte of input and jump to function 1

sporeball

Posted 2019-11-21T12:25:43.067

Reputation: 461

3

GolfScript, 12 bytes

{),97>-1%n}%

Try it online!

Explanation

{         }% # Map over the implicit input
 ),          # Generate range to 0x00
   97>       # Remove all that is less than 97
      -1%    # Reverse the string
         n   # Add a newline

user85052

Posted 2019-11-21T12:25:43.067

Reputation:

2

Lua, 107 103 bytes

s=string
for n in io.read():gmatch"."do t=''for j=s.byte(n)-96,1,-1 do t=t..s.char(j+96)end print(t)end

Try it online!

Again, still a newbie to this.

Corsaka

Posted 2019-11-21T12:25:43.067

Reputation: 581

For the string.byte you can also do n:byte(). As for the loop, can't you also loop from byte to 97? That would remove 5 bytes as well. I tried this with actual recursion, but yours can definitely be shorter than mine is now. See this where I tried to golf yours even more

– Anderium – 2019-11-23T10:14:54.000

I tried n:byte() and it didn't seem to work. Started complaining about function calls. – Corsaka – 2019-11-26T08:57:07.150

2

Perl 5 (-nF//), 31, 28 bytes

-3 bytes thanks to @nwellnhof

say/\w/&&reverse a..$_ for@F

Try it online!

Nahuel Fouilleul

Posted 2019-11-21T12:25:43.067

Reputation: 5 582

indeed, reading again the post, the input may only contain the lower-case letters a-z and the space character – Nahuel Fouilleul – 2019-11-21T13:25:50.643

2

Charcoal, 9 bytes

ES⮌…β⊕⌕βι

Try it online! Link is to verbose version of code. Explanation:

 S          Input string
E           Map over characters
    β       Lowercase alphabet
   …        Truncated to length
      ⌕     Position of
        ι   Current charcter in
       β    Lowercase alphabet
     ⊕      Incremented
  ⮌         Reversed
             Each prefix implicitly printed on its own line

Neil

Posted 2019-11-21T12:25:43.067

Reputation: 95 035

2

Python 2, 68 bytes

for x in input():
 o="";c=ord(x)
 while c>96:o+=chr(c);c-=1
 print o

Try it online!

Nothing very clever here.

Python 2, 64 53 bytes

lambda i:[map(chr,range(x,96,-1))for x in map(ord,i)]

Try it online!

Here's one for 64 53 but it outputs a list of lists which is not only ugly but probably stretches "flexible input/output" to near breaking point.

ElPedro

Posted 2019-11-21T12:25:43.067

Reputation: 5 301

2

Kotlin, 56 bytes

{it.map{println(('a'..it).joinToString("").reversed())}}

Try it online!

Brojowski

Posted 2019-11-21T12:25:43.067

Reputation: 141

2

jq, 39 characters

explode|map([range(.;96;-1)]|implode)[]

Or remove the trailing [] to get the output as array of strings.

Sample run:

bash-5.0$ jq -Rr 'explode|map([range(.;96;-1)]|implode)[]' <<< 'cgcc'
cba
gfedcba
cba
cba

Try it online!

manatwork

Posted 2019-11-21T12:25:43.067

Reputation: 17 865

2

Pyth, 7 bytes

m_<GhxG

Try it online!

Lowercase alphabet autos feel like cheating but oh well. Might add a recursive solution if I come up with anything good. Returns list of strings.

How it works

m_<GhxG
m         - Map on implicit input
 _        - The reverse of
  <G      - The lowercase alphabet at and below
     xG   - The index of the implicit element of input in the lowercase alphabet
    h     - above + 1

frank

Posted 2019-11-21T12:25:43.067

Reputation: 941

2

Red, 56 bytes

func[s][foreach c s[until[prin c#"a"> c: c - 1]print""]]

Try it online!

Galen Ivanov

Posted 2019-11-21T12:25:43.067

Reputation: 13 815

2

Icon, 66 bytes

procedure f(s)
c:=ord(!s)&write()&writes(char(c to 97by-1))&\z
end

Try it online!

Longer alternative:

Icon, 72 bytes

procedure f(s)
c:=ord(!s)-95&write((0>c&"")|reverse(&lcase[1:c]))&\z
end

Try it online!

Galen Ivanov

Posted 2019-11-21T12:25:43.067

Reputation: 13 815

2

SimpleTemplate, 46 66 bytes

This was a simple challenge, but quite fun!

{@eachargv.0}{@echol}{@if_ matches"@\w@"}{@forfrom _to"a"}{@echo_}

Loops over all the chars (that match with \d) in the string, and then outputs all the characters from that char to "a".


Ungolfed:

{@each argv.0 as char}
    {@echo "\n"}
    {@if char matches "@^[a-z0-9_]$@"}
        {@for letter from char to "a"}
            {@echo letter}
        {@/}
    {@/}
{@/}

The argv variable contains all the arguments passed to the render() method, or to the function, when converted.

The {@echo "\n"} ({@echol} in the golfed version) is needed because all whitespace will be automatically trimmed.

You can try the golfed version on https://ideone.com/Ru8shP

Ismael Miguel

Posted 2019-11-21T12:25:43.067

Reputation: 6 797

1Glad you enjoyed it! I find simple challenges seem to capture folks' imaginations and are more likely to take off than something overcomplicated. – AJFaraday – 2019-11-22T10:26:06.487

2

Standard ML (MLton), 84 79 bytes

fun t#"a"="a"|t#" "=" "|t x=(str x)^t(chr((ord x)-1));fun q p=map t(explode p);

Try it online!

Done by coworker, I insisted it should recursive at least partially.

Thanks for -5 to Galen Ivanov!

Thoma

Posted 2019-11-21T12:25:43.067

Reputation: 71

Several spaces can be removed for 79 bytes

– Galen Ivanov – 2019-11-22T19:06:48.623

2

C# (Visual C# Interactive Compiler), 80 77 bytes

a=>{var b="";foreach(var c in a){for(var j=c;j>96;)b+=j--;b+="\n";}return b;}

Try it online!

-3 bytes thanks to @my pronoun is monicareinstate for pointing out some unnecessary stuff

Malivil

Posted 2019-11-21T12:25:43.067

Reputation: 345

1>=97 -> >96; the innermost curly braces are unnecessary. Unfortunately, (_=>{code})(0) doesn't execute code as an expression :( (related fun fact: the C++ code [](){}() executes an empty lambda expression, so I include it or something like <:](){%>() with digraphs everywhere) – my pronoun is monicareinstate – 2019-11-24T04:15:05.403

Of course! How did I miss such obvious stuff. Thanks for pointing it out – Malivil – 2019-11-24T16:19:58.930

2

Rust, 63 bytes

|s:&str|s.bytes().map(|c|(b'a'..=c).rev()).collect::<Vec<_>>();

Try it online!

betseg

Posted 2019-11-21T12:25:43.067

Reputation: 8 493

2

Perl 5 + -a -M5.010, 23 bytes

say reverse a..$_ for@F

Try it online!

Dom Hastings

Posted 2019-11-21T12:25:43.067

Reputation: 16 415

@JoKing goddammit. I thought it was too easy... Thanks! – Dom Hastings – 2019-11-28T19:42:51.497

2

Forth (gforth), 66 bytes

: f bounds do i c@ dup 96 - 0 max 0 ?do dup emit 1- loop cr loop ;

Try it online!

Code Explanation

: f            \ start a new word definition
  bounds       \ get starting and ending address of string
  do           \ loop from starting address to ending address
    i c@       \ get ascii value at current address
    dup 96 -   \ get numerical position in alphabet
    0 max      \ if negative (char is space), set to 0
    0 ?do      \ loop from 0 to position in alphabet
      dup emit \ output character
      1-       \ subtract 1 from current character (move backwards in alphabet)
    loop       \ end inner loop definition
    cr         \ output a newline
  loop         \ end outer loop definition
;              \ end word definition

reffu

Posted 2019-11-21T12:25:43.067

Reputation: 1 361

2

W, 7 5 bytes

Lowercase alphabet auto feels like cheating. This one does not use any alphabet built-in with the same bytecount. DISCLAIMER: insert literal spaces as \x20 in your input strings.

^'a.E

Explanation

   E Map over every item in the input
^    Trim out all literal whitespace in this item
 'a. Generate a range to the character 'a'
     An error-proof mechanism returns the null string
     if any of those operands are the null string
     Implicit print on each iteration

user85052

Posted 2019-11-21T12:25:43.067

Reputation:

2

Pip -l, 11 bytes

CRV97\,A_Ma

Try it online!

Explanation

          a  Input as a command-line argument
         M   Map this function to each of its characters:
       A_     Get ASCII code
   97\,       Range from 97 up to and including the above
 RV           Reverse the range
C             Convert to (a list of) characters
             With -l, output each list of chars concatenated on separate lines

DLosc

Posted 2019-11-21T12:25:43.067

Reputation: 21 213

2

Burlesque, 13 bytes

XX{'ajr\<-}m[

Try it online!

XX  # Explode a string into characters
{
'a  # Literal "a"
jr\ # Create range from "a" -> char and join as string
<-  # Reverse string
}m[ # Apply to each char

DeathIncarnate

Posted 2019-11-21T12:25:43.067

Reputation: 916

2

Python 3, 76 60 53 bytes

(thanks to @Jo King & @sporeball)

for a in input():print(*map(chr,range(ord(a),96,-1)))

Try it online! (original 76 bytes solution)

Try it online! (53 bytes solution)

kpaul

Posted 2019-11-21T12:25:43.067

Reputation: 141

1

You can move the second for loop inside the print to save on using the second print, 68 bytes. And then map for even shorter, 60 bytes

– Jo King – 2020-01-15T22:36:44.417

1

Having spaces between letters is allowed, so if you omit sep, you can get it down to 53 bytes.

– sporeball – 2020-01-18T21:26:06.560

2

x86-16 machine code, IBM PC DOS, 27 23 bytes

Binary:

00000000: b408 cd21 b40e cd10 483c 617d f9b0 0acd  ...!....H<a}....
00000010: 10b0 0dcd 10eb e9                        .......

Test and build using xxd -r from above.

Unassembled:

        IN_LOOP: 
B4 08       MOV  AH, 08H        ; DOS read char without echo function
CD 21       INT  21H            ; load next char from STDIN
B4 0E       MOV  AH, 0EH        ; BIOS write char teletype output function
        CHR_LOOP: 
CD 10       INT  10H            ; write to console 
48          DEC  AX             ; move to next char 
3C 61       CMP  AL, 'a'        ; end with an 'a' 
7D F9       JGE  CHR_LOOP       ; keep looping descending chars 
B0 0A       MOV  AL, 0AH        ; CR char 
CD 10       INT  10H            ; write to console 
B0 0D       MOV  AL, 0DH        ; LF char 
CD 10       INT  10H            ; write to console 
EB E9       JMP  IN_LOOP        ; keep looping until ^C/^Break

I/O:

Input via STDIN or interactive input, output to console. Will run until EOF or ^C/^Break.

enter image description here

Iterative approach. Of course, it's 8 bytes just to write a newline character...

640KB

Posted 2019-11-21T12:25:43.067

Reputation: 7 149

1

Ruby, 40 bytes

ARGV[0].chars.map{|c|print *'a'..c;puts}

Try it online!

kpaul

Posted 2019-11-21T12:25:43.067

Reputation: 141

1I'm afraid you missed a small detail: the sequences of letters have to be in descending order — from the letter used in input down to letter “a”. – manatwork – 2019-11-24T14:09:30.823

1

TCL, 179 bytes

rename string d;proc a s {set b zyxwvutsrqponmlkjihgfedcba;if {$s=={}} return;if {[set c [d first [d index $s 0] $b]]<0} {puts {}} {puts [d range $b $c end]};a [d replace $s 0 0]}

Try it online!

ungolfed version

proc a {s} {
    set b zyxwvutsrqponmlkjihgfedcba
    if {$s=={}} return


    if {[set c [string first [string index $s 0] $b]]<0} then {
            puts {} # if it's a space print a newline
    } else {
        puts [string range $b $c end] # print the substring of $b starting at the character
    }

    #recurse on the string minus the front character
    a [string replace $s 0 0]
}

a [concat $argv]

Samuel

Posted 2019-11-21T12:25:43.067

Reputation: 191

1

Pushy, 22 bytes

N@$'&32!?&97-:t';;T'..

Try it online!

N@$'&32!?&97-:t';;T'..

N                       \ Set output delimiter to empty string
 @                      \ Reverse input
  $                     \ While there are characters left on stack:
   '                    \   Print the top character
    &32!?        ;       \   if not a space:
         &97-:  ;       \     char(top) - 97 times do:
              t'        \       Decrement character and print
                  T'    \   Print a newline
                    ..  \   Clear up stack (pops items we are done with)  

FlipTack

Posted 2019-11-21T12:25:43.067

Reputation: 13 242