Even and Odd Numbers

23

Sandbox

Adapted from exercise 4 of 100 little Keg exercises

The ability to repeat chunks of code within a program is an important part of any programming language. Also just as important is the ability to make decisions based on different values.

The Challenge

I want you to write a program that:

  • Starts at the number 0, and:
  • For each number from 0 to 100 (inclusive):
  • If the number is even, print the letter E (uppercase or lowercase)
  • Otherwise: print the number

Keeping in the spirit of this challenge, your source code must fit the pattern of having characters with an odd ordinal value followed by characters with an even ordinal value. Note that ordinal value is defined here as if I called python's ord() function on the character using your language's prefered code page. In other words, the code points of your program should be as such:

Odd Even Odd Even Odd Even ...

or

Even Odd Even Odd Even Odd ...

More concisely, the code points of your program must alternate between being odd and even.

Example Output

E 1 E 3 E 5 E 7 E 9 E 11 E 13 E 15 E 17 E 19 E 21 E 23 E 25 E 27 E 29 E 31 E 33 E 35 E 37 E 39 E 41 E 43 E 45 E 47 E 49 E 51 E 53 E 55 E 57 E 59 E 61 E 63 E 65 E 67 E 69 E 71 E 73 E 75 E 77 E 79 E 81 E 83 E 85 E 87 E 89 E 91 E 93 E 95 E 97 E 99 E

Output can be in any other convenient format with any other separator. Leading and trailing whitespace is acceptable.

Script Validation (UTF-8 only)

Here is a Keg script to see if your program fits the parity pattern requirement

Note that this can only be used for languages that use utf-8 as their codepage.

Here is an alternate Haskell script written by @WheatWizard which can handle newlines and shows which characters are invalid.

Here is a Python Script that tells you where you need to insert extra characters. (As well as the binary codes and the ord code of the characters)

Scoring

This is so the answer with the fewest amount of bytes wins.

Let it be known that flags don't count towards being in the pattern. They also don't count towards byte count in this challenge.

Leaderboards

Here is a Stack Snippet to generate both a regular leaderboard and an overview of winners by language.

To make sure that your answer shows up, please start your answer with a headline, using the following Markdown template:

# Language Name, N bytes

where N is the size of your submission. If you improve your score, you can keep old scores in the headline, by striking them through. For instance:

# Ruby, <s>104</s> <s>101</s> 96 bytes

If there you want to include multiple numbers in your header (e.g. because your score is the sum of two files or you want to list interpreter flag penalties separately), make sure that the actual score is the last number in the header:

# Perl, 43 + 2 (-p flag) = 45 bytes

You can also make the language name a link which will then show up in the leaderboard snippet:

# [><>](http://esolangs.org/wiki/Fish), 121 bytes

var QUESTION_ID=197210;
var OVERRIDE_USER=78850;
var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;function answersUrl(d){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+d+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(d,e){return"https://api.stackexchange.com/2.2/answers/"+e.join(";")+"/comments?page="+d+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(d){answers.push.apply(answers,d.items),answers_hash=[],answer_ids=[],d.items.forEach(function(e){e.comments=[];var f=+e.share_link.match(/\d+/);answer_ids.push(f),answers_hash[f]=e}),d.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(d){d.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),d.has_more?getComments():more_answers?getAnswers():process()}})}getAnswers();var SCORE_REG=function(){var d=String.raw`h\d`,e=String.raw`\-?\d+\.?\d*`,f=String.raw`[^\n<>]*`,g=String.raw`<s>${f}</s>|<strike>${f}</strike>|<del>${f}</del>`,h=String.raw`[^\n\d<>]*`,j=String.raw`<[^\n<>]+>`;return new RegExp(String.raw`<${d}>`+String.raw`\s*([^\n,]*[^\s,]),.*?`+String.raw`(${e})`+String.raw`(?=`+String.raw`${h}`+String.raw`(?:(?:${g}|${j})${h})*`+String.raw`</${d}>`+String.raw`)`)}(),OVERRIDE_REG=/^Override\s*header:\s*/i;function getAuthorName(d){return d.owner.display_name}function process(){var d=[];answers.forEach(function(n){var o=n.body;n.comments.forEach(function(q){OVERRIDE_REG.test(q.body)&&(o="<h1>"+q.body.replace(OVERRIDE_REG,"")+"</h1>")});var p=o.match(SCORE_REG);p&&d.push({user:getAuthorName(n),size:+p[2],language:p[1],link:n.share_link})}),d.sort(function(n,o){var p=n.size,q=o.size;return p-q});var e={},f=1,g=null,h=1;d.forEach(function(n){n.size!=g&&(h=f),g=n.size,++f;var o=jQuery("#answer-template").html();o=o.replace("{{PLACE}}",h+".").replace("{{NAME}}",n.user).replace("{{LANGUAGE}}",n.language).replace("{{SIZE}}",n.size).replace("{{LINK}}",n.link),o=jQuery(o),jQuery("#answers").append(o);var p=n.language;p=jQuery("<i>"+n.language+"</i>").text().toLowerCase(),e[p]=e[p]||{lang:n.language,user:n.user,size:n.size,link:n.link,uniq:p}});var j=[];for(var k in e)e.hasOwnProperty(k)&&j.push(e[k]);j.sort(function(n,o){return n.uniq>o.uniq?1:n.uniq<o.uniq?-1:0});for(var l=0;l<j.length;++l){var m=jQuery("#language-template").html(),k=j[l];m=m.replace("{{LANGUAGE}}",k.lang).replace("{{NAME}}",k.user).replace("{{SIZE}}",k.size).replace("{{LINK}}",k.link),m=jQuery(m),jQuery("#languages").append(m)}}
body{text-align:left!important}#answer-list{padding:10px;float:left}#language-list{padding:10px;float:left}table thead{font-weight:700}table td{padding:5px}
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="https://cdn.sstatic.net/Sites/codegolf/primary.css?v=f52df912b654"> <div id="language-list"> <h2>Winners by Language</h2> <table class="language-list"> <thead> <tr><td>Language</td><td>User</td><td>Score</td></tr></thead> <tbody id="languages"> </tbody> </table> </div><div id="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr></thead> <tbody id="answers"> </tbody> </table> </div><table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td><a href="{{LINK}}">{{SIZE}}</a></td></tr></tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td><a href="{{LINK}}">{{SIZE}}</a></td></tr></tbody> </table> 

Lyxal

Posted 2019-12-19T20:33:45.783

Reputation: 5 253

You say "100 (inclusive)", but the sample output only goes up to 99 – caird coinheringaahing – 2019-12-19T21:09:40.627

@cairdcoinheringaahing Fixed. – Lyxal – 2019-12-19T21:11:11.160

4Why is this a decision problem? – xnor – 2019-12-20T06:25:20.143

@xnor because you have to decide if integers are odd or even. – Lyxal – 2019-12-20T06:30:19.013

4... That's not what a [tag:decision-problem] is. Decision problems check whether the input meets a certain criteria and outputs based on that – Jo King – 2019-12-20T10:49:16.750

1Are we allowed to output a lowercase e instead of uppercase one? Also, are we allowed to output as a list (instead of a string so I could save on the additional join)? – Kevin Cruijssen – 2019-12-20T16:46:15.977

2It should be noted that the Keg script in the question only checks the first line if you input more than one. – Post Rock Garf Hunter – 2019-12-20T19:52:19.250

2Here is a version that handles bad lines and also highlights the wrong characters – Post Rock Garf Hunter – 2019-12-20T20:02:11.893

I don't fully understand what the source restriction on this challenge is. Is it possible to explain it more clearly? – Skoddie – 2019-12-20T21:53:52.787

2@Skoddie the code points of your program must alternate between being odd and even. I don't really see how that is hard to understand. Codepoints are the ordinal value of a character in an encoding (usually UTF-8). For example a space has the codepoint 32, which is even. Your code must alternate between odd and even, starting with either. This means that a lot of commonly used function names, like print, range or any of the same character in a row (&& or ||) cannot be used in your program, since they violate that rule – Jo King – 2019-12-21T07:44:00.320

@JoKing That makes sense. That does disqualify languages that don't have alternatives to certain keywords. Oh well. – Skoddie – 2019-12-22T22:16:51.867

Answers

9

JavaScript (ES6), 42 bytes

Contains a literal Tab.

f= y =>y>98? ' E ':' E ' + -~y +f   (1 -~y )

Try it online!

Arnauld

Posted 2019-12-19T20:33:45.783

Reputation: 111 334

8

Python 3, 72 bytes

x="E";z= 1
while 	z	<101:	x=x+ ["E"	,	f' {z} ' ] [z%2] ;z=z+ 1
exit	(	x)

Try it online!

Just by coincidence, exit and while are both available. The rest is just the program separated by spaces and tabs to make it alternate.

I'm hoping it's forgivable to output as an exit code, since print is unavailable.

Matthew Jensen

Posted 2019-12-19T20:33:45.783

Reputation: 713

I'm perfectly happy with output being given as an exit code. – Lyxal – 2019-12-19T23:55:09.570

@Jono2906 Great, that's good! – Matthew Jensen – 2019-12-20T00:07:01.577

Output as exit code is in the list of standard I/O – frank – 2019-12-20T00:19:03.157

7this isn't an "exit code", it's printed to stderr - but that's also valid by our rules – Doorknob – 2019-12-20T02:10:21.187

I was messing with your tio.run instance and I was able to shave several bytes off your code by removing tabs and it still worked. – Joel Trauger – 2019-12-20T16:59:56.383

1@JoelTrauger Did it still met restricted source condition? – val says Reinstate Monica – 2019-12-20T18:55:55.587

@valsaysReinstateMonica Oh I did not see that condition. I was wondering why it seemed too easy... Fortunately Python is forgiving of whitespace as long as certain code block constraints aren't violated. – Joel Trauger – 2019-12-20T19:23:20.170

6

MATL, 14 bytes

69H!Vo:E q"c@y

Try it online!

MATL uses ASCII encoding. The code points of the source code are

54  57  72  33  86 111  58  69  32 113  34  99  64 121

How it works

69    % Push 69. This is the code point of 'E'
H     % Push 2
!     % Transpose: does nothing to 2
V     % Convert to string: gives '2'
o     % Convert to double: gives code point of '2', which is 50
:     % Range. Gives [1 2 ... 50]
E     % Multiply each element by 2. Gives [2 4 ... 100]
      % (Space:) Does nothing
q     % Subtract 1 from each element. Gives [1 3 ... 99]
"     % For each k in [1 3 ... 99]
  c   %   Convert to char. In the first iteration the top of the stack contains 69,
      %   which is converted into 'E'. In subsequent iterations the top of the stack
      %   contains 'E', which is left as is
  @   %   Push current k
  y   %   Duplicate from below: pushes another copy of 'E'
      % End (implicit)
      % Display stack, botom to top (implicit)

Luis Mendo

Posted 2019-12-19T20:33:45.783

Reputation: 87 464

6

05AB1E, 15 11 9 bytes

т Ýxт>çÞ‡

-2 bytes thanks to @Grimmy.

Outputs as a list with lowercase e.

Try it online.

Explanation:

Shortest base version I could find was 8 7 bytes: тÝx'EÞ‡ (Outputs as a list with uppercase E.)

-1 byte thank to @Grimmy.

т        # Push 100
 Ý       # Pop and push a list in the range [0, 100]
  x      # Push a list with each value doubled (without popping the original list)
   'E   '# Push "E"
     Þ   # Pop and push an infinite list of "E": ["E","E","E",...]
      ‡  # Transliterate each doubled number to "E" in the original list
         # (after which this list is output implicitly as result)

The codepoints of this 7-byter are [15,221,120,39,69,222,135] / [1,1,0,1,1,0,], which is already pretty good.

So I now have this:

т          # Push 100
           # No-op space
  Ý        # Pop and push a list in the range [0, 100]
   x       # Push a list with each value doubled (without popping the original list)
    т      # Push 100
     >     # Increase it by 1 to 101
      ç    # Convert this integer to a character with this ASCII codepoint: "E"
       Þ   # Pop and push an infinite list of "e": ["e","e","e",...]
        ‡  # Transliterate each doubled number to "e" in the original list
           # (after which this list is output implicitly as result)

This 9-byter has the codepoints: [15,32,221,120,15,62,231,222,135] / [1,0,1,0,1,0,1,0,1].

Kevin Cruijssen

Posted 2019-12-19T20:33:45.783

Reputation: 67 575

2

Here's a shorter base: тÝx'EsǝJ. Also 8 bytes: тÝx'EÞ‡J.

– Grimmy – 2019-12-20T16:13:43.940

2Here's a 10 that complies with the source restriction but outputs lowercase es. – Grimmy – 2019-12-20T16:44:11.170

1@Grimmy Nice. I've asked OP if a lowercase e (or an output as list) is allowed. I'll wait for his reaction before changing it. Thanks, though! :) – Kevin Cruijssen – 2019-12-20T16:47:07.930

1Lowercase is now allowed. Golf away! – Lyxal – 2019-12-21T02:52:25.683

@Jono2906 And my other question? Are we allowed to output as a list (i.e. ["E",1,"E",3,...] instead of a joined string? – Kevin Cruijssen – 2019-12-21T11:02:06.767

1The challenge already says it can be in any other convenient format so yes, you can. – Lyxal – 2019-12-21T21:20:26.643

6

Haskell, 112 105 99 bytes

The code produces a string as in the example.

[ c|s<-"E 1 E 3 E 5 E 7 E 9 E"	:[ ' ':k:m:' ':	"E"	|k<-"123456789"	,m<-"1 3 5 7 9"	,m>' ' ],c<- s ]

I was not able to find a way to print an integer or convert it to string. This is why the solutions looks like this.

Try it online!

user28667

Posted 2019-12-19T20:33:45.783

Reputation: 579

5

Ruby, 41 bytes

n= 1
eval'puts"E";p	n;n=n+2; '*50;puts"E"

Try it online! (with parity check)

This builds a string that contains the code to output "E" and n, then add 2 to n. Then it multiplies the string by 50 (repeating it 50 times) and evals it. Finally, it prints the last "E" at the end.

Doorknob

Posted 2019-12-19T20:33:45.783

Reputation: 68 138

5

Jelly, 13 bytes

³Ż¹⁾E Ḥ‘{$¦ K

Code-points: [131, 210, 129, 142, 69, 32, 175, 252, 123, 36, 5, 32, 75]

A full program, which given no arguments prints the result.

Try it online!

(As a bonus given a non-negative integer argument it will print the sequence for that number, e.g.)

How?

³Ż¹⁾E Ḥ‘{$¦ K - Main Link: no arguments
³             - literal 100 (if there are arguments provided, this is the 1st)
 Ż            - zero-range = [0,1,2,3,...,100]
  ¹           - identity (no-op)
          ¦   - sparse application...
         $    -   ...to indices: last two links as a monad:
      Ḥ       -      double = [0,2,4,6,...,200]
        {     -      use left argument as input to:
       ‘      -        increment = [1,3,5,7,...,201]
                     (note Jelly uses 1-based indexing)
   ⁾E.        -   ...what: literal character pair =  ['E', ' ']
           .  - no-op
            K - join with spaces
              - implicit, smashing print

Jonathan Allan

Posted 2019-12-19T20:33:45.783

Reputation: 67 804

5

C (gcc) with -trigraphs flag, 161 141 bytes

Thanks to WheatWizard for the validation script, which revealed that I mistakenly identified line endings as CR instead of LF! The fix didn't change the byte count, however.

To get this to even work, in addition to the many spaces and tabs, I used a macro that uses digraphs and token-pasting to generate the disallowed function names (main and printf). As Unix line endings are LF (decimal 10), I had to add a space at the end of the first line to continue the odd/even pattern. Saving some more space, I could coalesce in because the two letters fit the odd/even pattern.

Parity verification

#define y(a,c,g,i ) a %:%:c %:%:	 in%:%:g %:%:i
	b; y(m,a,	,	 )() {for	(; 	b	<101 ;b	 = 	b+ 1 ) y(	p	,	r	,	t	,	f)(	b%2?"%d	"	:	"E 	"	,	b) ; }

Try it online!

ErikF

Posted 2019-12-19T20:33:45.783

Reputation: 2 149

3

Jelly, 18 bytes

ØA 5ị¶ 101Ḷ× Ḃ$oÑK

Try it online!

In the Jelly code page, these character have the byte values of

12 41 20 35 D8 7F 20 31 30 31 B2 11 20 BF 24 6F 10 4B

which follows the pattern Even Odd Even Odd ...

How it works

Removing the extra spaces we get:

ØA5ị
101Ḷ×Ḃ$oÑK

which is:

ØA5ị       - Helper link: Yield "E"
ØA         - Yield the upper case alphabet
  5ị       - Take the fifth element ("E")

101Ḷ×Ḃ$oÑK - Main link: Yield "E 1 E 3 ... E 99 E"
101        - Yield 101
   Ḷ       - Lowered range:            [0, 1, 2, ..., 99, 100]
     Ḃ$    - Take the parity of each:  [0, 1, 0, ..., 1, 0]
    ×      - Multiply each together:   [0, 1, 0, 3, ..., 99, 0]
        Ñ  - Call the helper link:     "E"
       o   - Replace the 0s with "E"s: ["E", 1, "E", ..., 99, "E"]
         K - Join with spaces:         "E 1 E 3 ... E 99 E"

caird coinheringaahing

Posted 2019-12-19T20:33:45.783

Reputation: 13 702

3

Runic Enchantments, 32 bytes

>'D1+k$1:/$'D1+k$/2+:1.C(1+?.;8?
EOEOEOEOEOEOEOEOEOEOEOEOEOEOEOEO

Try it online!

EO sequence above just indicates whether each byte is even or odd.

Draco18s no longer trusts SE

Posted 2019-12-19T20:33:45.783

Reputation: 3 053

3

Pyth, 16 bytes

V101p? %N/T5NK\E

Try it online!

Verify it online!

Separated by ""

How it works:

V101p? %N/T5NK\E
V101                  - For 'N' in 0..100
     ? %N/T5        - If N modulo (10÷5) (or N%2) is truthy...
            N       - ...return N
             K\E    - Otherwise, return 'E' (K here is just a separator)
    p               - Print the result

frank

Posted 2019-12-19T20:33:45.783

Reputation: 941

3

R, 35 bytes

Thanks to ErikF for correcting a bug.

x=0	:{ 98+2} ;x[ c(	T	,!T) ] ="E";x

Try it online!

Defines x as the vector of integers from 0 to 100, then replaces all the even values with "E" and outputs x.

Previous, quite different version:

R, 42 bytes

for	(i in	 1:50) write(c(i*+2- 1,	"E"),1 )

Try it online!

Includes a few tabs instead of spaces. Uses newlines as separators.

cat and print are unusable, but luckily write is OK. I had to resort to i*+2 -1 instead of i*2-1 to keep the alternation.

Robin Ryder

Posted 2019-12-19T20:33:45.783

Reputation: 6 625

Ahh right my bad – niko – 2019-12-22T17:24:14.023

2

Jelly, 15 bytes

101Ḷ¹⁾E Ḃ ?€Ḣ€K

Try it online! Try it online with parity!

A full program that takes no argument and prints the desired output. The footer demonstrates both the parity and result.

Nick Kennedy

Posted 2019-12-19T20:33:45.783

Reputation: 11 829

2

MathGolf, 20 bytes

"E"q♀{î♥☻/÷i¿{"E"}îq

Try it online!

Very similar to the FizzBuzz example. Uses the MathGolf codepage, can verify parity with this script.

"E"q                # Push and output "E"
    ♀               # Push 100
     {              # Loop from 1 to 100
      î             # Push loop counter
       ♥☻/          # Push 32, 16, and divide (basically pushes 2)
         ÷          # Is the loop counter divisible by 2?
          i         # Convert to integer (does nothing)
           ¿{"E"}   # If so, push "E"
                 î  # If not, push the loop counter
                  q # Output

79037662

Posted 2019-12-19T20:33:45.783

Reputation: 1 739

2

Ruby, 50 bytes

Adaptation of the Python answer. Unlike Python, however, Ruby puts is valid code to use for output, eliminating the need for exit hacks.

I didn't want to do a direct port, but map, each, upto, and times are all forbidden by the spec...

x=0;(	puts ["E"	,	x] [x%2] ;x=x+ 1 ) while 	x	<101

Try it online!

Value Ink

Posted 2019-12-19T20:33:45.783

Reputation: 10 608

2

W z, 19 bytes

10#0#.a2m a&#"E"#|M

Pretty much the same as below. 100.a2ma&"E"|M The only difference is the 0-range (which does no good for the program).

W, 19 bytes

101 a2m"E"#&a 1 -|M

Explanation

Pretty simple: # and are both readability characters here and have no result on the stack.

101a2m"E"&a1-|M
101           M % Foreach the range 1 -> 101
   a2m          % Modulo the current item by 2
      "E"&      % If true, return "E" (Because odd-1 -> even)
          a1-|  % Otherwise, return a-1

user85052

Posted 2019-12-19T20:33:45.783

Reputation:

2

Japt, 15 bytes

ò#d_v) ?"E"):»Z

Test it

ò#d               range [0-100]
   _              passed through
    v) ?          divisible by 2?
        "E"):»Z   replace with 'E' else replace with number

Layout : [242,35,100,95,118,41,32,63,98,69,98,41,58,187,90]

AZTECCO

Posted 2019-12-19T20:33:45.783

Reputation: 2 441

2

Haskell, 296 bytes

w = k 1
a(c:e ) = c
i =(id)
e a =(a:)
m 1 =(a"1")
m 3 =(a"3")
m 5 =(a"5")
m 7 =(a"7")
m 9 =(a"9")
m c|c<1 = '0'|c<3 = '2'|c<5 = '4'|c<7 = '6'|c<9 = '8'
m c =(m$c - 10)
q 1 =0;
q c|m c<a"1"= 1 + q(c - 1 )
q c = q$c - 1
k c|c>98= e(a"E")$e(a"9")$e(a"9")$i"E";
k c = e(a"E")$e(m$q c )$e(m c )$k$c +2

Try it online!

This was pretty hard since show and print are both unusable, so I had to convert integers to strings on my own.

Post Rock Garf Hunter

Posted 2019-12-19T20:33:45.783

Reputation: 55 382

2

Python 3, 65 bytes

exit	([ ["E"	,	j] [j%2]for	j	 in	 eval	('ran' +"g"+"e")(101 ) ] )

Try it online!

This submission was built on using tabs and spaces, as well as a Very Clever™ abuse of eval.

Edit: Fixed program to adhere to (I had an extra space by mistake).

osuka_

Posted 2019-12-19T20:33:45.783

Reputation: 391

2

PowerShell, 72 bytes

for`t(`t`$i =0;`$i -le 101 - 1 ;`$i =`$i + 1 ) {`$ab=(' e ',`t`$i ) ;`$ab[`$i %2] }

For testing:

$a = "for`t(`t`$i =0;`$i -le 101 - 1 ;`$i =`$i + 1 ) {`$ab=(' e ',`t`$i ) ;`$ab[`$i %2] }"

# Even/odd ok?
0..($a.Length-1) | % { [char]$a[$_] + "  " + ([byte][char]$a[$_] % 2)}
$a.Length

Invoke-Expression $a

Missed the even-odd part in the code, thanks for pointing it out!

Try It Online

PowerKjell

Posted 2019-12-19T20:33:45.783

Reputation: 61

2

GolfScript, 18 bytes

I didn't expect such a small amount of whitespace ...

101,{.3(%\"E"if} %

Try it online!

Explanation

101,               # Generate range [0 1 2 ... 99 100]
    {          } % # Map every item using this scheme
     .             # Copy the item
      3(%          # Modulo by 3-1 (2)
         \         # If modulo-ing by 2 is truthy: return the item
          "E"if    # Otherwise, return "E"

user85052

Posted 2019-12-19T20:33:45.783

Reputation:

1{"E".2+}51*;; does what you did but 2 byes shorter (15, since the space before % isn't needed). – Mathgeek – 2020-02-26T18:01:50.653

1

Charcoal, 24 18 bytes

F¹⁰¹«¿⊗﹪⊕ι²E↥I⌈ι⁰→

Try it online! Link is to verbose version of code. Here are the 18 hex codes in Charcoal's code page:

C6 B1 B0 B1 A8 BF 9E A5 9C E9 B2 45 18 C9 1A A9 B0 13

Explanation:

F¹⁰¹«

Loop from 0 to 100.

¿⊗﹪⊕ι²

Test whether the index is even. The index is incremented to comply with the source code restriction, which reverses the sense of the test. The result of the test is doubled to comply with the source code restriction, but this doesn't change the outcome of the decision.

E

If the number was even then output an E.

↥I⌈ι

Otherwise take the ceiling of the number to comply with the source code restriction, cast the result to string, and uppercase the result to comply with the source code restriction.

Print 0 -s to comply with the source code restriction.

Leave a space between successive outputs.

Note: If a trailing space is acceptable, then the last two characters can be replaced with a space for 17 bytes, although there are alternative solutions, such as this:

F¹⁰¹«¿⊗﹪⊕ι²E ⁺⌈ι 

Try it online! Link is to verbose version of code. Here are the 17 hex codes in Charcoal's code page:

C6 B1 B0 B1 A8 BF 9E A5 9C E9 B2 45 20 AB 1A E9 20

Explanation: Much like the above, except that in the even case we directly include the space in the literal while in the odd case the ceiling of the number is concatenated with a space.

Neil

Posted 2019-12-19T20:33:45.783

Reputation: 95 035

1

Zsh, 50 30 34 bytes

Bug fix: I was checking each pair of letters to make sure it had a character of each parity, instead of ensuring it alternated.

"e"cho E"	"{"1"'.'.9"9"'.'.'0'2} E

Try it online! Try it online! Try it online! Self-tests. Contains a literal tab.

I couldn't figure out a way to finagle the most straightforward echo E\ {1..99..2} E into anything, mostly due to the double period. EDIT: I did it. Turns out in normal expressions, quotes inside brace ranges don't really matter.

GammaFunction

Posted 2019-12-19T20:33:45.783

Reputation: 2 838

1

Pip, 16 bytes

1 +2	*	,50	JW"E"

Try it online!

Outputs without separators.

Spaces and tabs are no-ops, so this boils down to:

    ,50       Range(50)                                               0, 1, ..., 49
  2*          Multiply each by 2                                      0, 2, ..., 98
1+            Add 1                                                   1, 3, ..., 99
       JW"E"  Join with "E", wrapping the outside with "E"s as well   E1E3E...E99E

DLosc

Posted 2019-12-19T20:33:45.783

Reputation: 21 213

-2

Python 69 59 57 46 bytes

l=["E" if i%2==0 else i for i in range(101)]

List comprehension is the best feature in python.

sticktoy

Posted 2019-12-19T20:33:45.783

Reputation: 1

3It looks like you missed that this challenge is restricted source. You might want to read it again carefully since currently your answer does not meet the requirements of the challenge. – Lyxal – 2019-12-21T07:28:35.730