I don't even... I only odd!

36

3

Your task is simple: write a program that receives an integer as input and outputs it if it was odd, and does nothing otherwise (not halting is allowed). The challenge is, that you can only use odd bytes.

You can optionally append a trailing newline to the output.

This is code-golf, shortest answer in (odd) bytes wins.

Standard loopholes are forbidden. Furthermore, you cannot use versions of languages, which are newer than the posting of this challenge.

Example input > output:

13 > 13

42 >

M.Herzkamp

Posted 2017-07-11T09:26:22.350

Reputation: 1 227

10I downvoted this challenge because it is a "Do X without Y" challenge. – Leaky Nun – 2017-07-11T09:32:27.220

4What exactly does does nothing otherwise mean? In Haskell a function with type Int -> Int either returns an integer or does not halt or throws some error. If the input is even it should obviously not be returned, so would not halting or throwing an error in this case be acceptable? – Laikoni – 2017-07-11T13:29:34.720

@Laikoni aren't there output operations in Haskell? – M.Herzkamp – 2017-07-11T14:10:29.503

@M.Herzkamp You mean that instead of returning an integer, a string of the integer should be printed or returned, and thus an empty string should be printed/returned for even numbers? This is possible in Haskell, but I'm not sure it's possible under the given restrictions, whereas the task of deciding odd or even is possible. – Laikoni – 2017-07-11T14:23:24.167

2If you wanna know if you can use your source code, try these scripts in your browser console. Create valid charset: alphabet=new Set(Array(256).fill(0).map((v,i)=>i).filter(v=>v%2).map(String.fromCharCode));. Check if source is valid: [..."SOURCE CODE"].every(v=>alphabet.has(v)). See invalid characters in source: [...new Set("SOURCE CODE")].filter(v=>!alphabet.has(v)). Remember to escape your quotes, " => \" ;) – kamoroso94 – 2017-07-11T15:19:19.923

14@LeakyNun "do X without Y" doesn't refer to general [tag:restricted-source] challenges, but challenges that forbid you to use certain features of a language. This challenge isn't that and neither does it have any of the issues that make actual "do X without Y" challenges problematic. – Martin Ender – 2017-07-12T06:29:04.613

1@Laikoni As there are some answers already that go into an infinite loop, I would say that it is okay to show such a behaviour. Not returning can be interpreted as doing nothing. – M.Herzkamp – 2017-07-12T14:55:48.987

Only odd bytes? Odd Unicode codepoints are not allowed? Also, is even-length solution allowed? – user202729 – 2017-07-12T15:12:29.180

@user202729: Do you have in mind some programming language with a unicode symbol table? Or do you want to encode a program in a unicode string an run it inside your program or something? – M.Herzkamp – 2017-07-12T16:05:25.840

I'd love to be proven wrong, but I don't think it's possible to solve this problem in Ruby : p, $, lambda, def or -> cannot be written. How could a method be defined, how could anything be printed out? It's also probably very hard (if not impossible), to do it in Python. – Eric Duminil – 2017-07-12T17:01:48.040

Likewise, I'd love to see a JavaScript version, since => and function are disallowed, plus ( is an even byte so I don't think JSFuck techniques can be used either... – Value Ink – 2017-07-12T21:33:20.703

@Laikoni (cc M.Herzkamp) for reference, by default answers always have to halt. So, M.Herzkamp, if you want to allow this, you should mention it explicitly in the challenge.

– Martin Ender – 2017-07-13T11:47:35.257

1Shouldn't the title of the challenge be "I can't even... I only odd!"? "I can't even" is the meme. – mbomb007 – 2017-07-13T16:27:19.333

1@EricDuminil I made an answer in Python REPL. – mbomb007 – 2017-07-13T18:33:49.423

Validate your solution. – Dom Hastings – 2017-07-14T08:44:45.277

@mbomb I was thinking along the lines of "I don't even (know what to say)" – M.Herzkamp – 2017-07-14T09:54:11.180

@DomHastings It doesn't really work. Your codepen removes whitespace characters automatically, even valid ones like tabs. – mbomb007 – 2017-07-14T15:15:50.107

@mbomb007 Ah, right you are, thanks for the heads up! I hadn't set white-space to pre. I've fixed that. I only thought I'd share since I made it to make sure I had no leftovers in mine! – Dom Hastings – 2017-07-14T15:41:04.170

Answers

1

Japt -f, 1 byte

u

u has a char-code value of 117.

Try it

Oliver

Posted 2017-07-11T09:26:22.350

Reputation: 7 160

1Late to the party, but my... what an answer! – M.Herzkamp – 2019-08-22T08:25:26.377

67

Lenguage, 645529908926937253684695788965635909332404360034079 9394157991500940492270727190763049448735 1174269748937617561533841898064735499551 2293382937520069758100171520285996319 bytes

That's roughly equal to 2 duodecillion bytes.

The file translates to the following brainfuck program:

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

Takes input as an ASCII code, with a maximum value of 256. Uses wrapping.

Okx

Posted 2017-07-11T09:26:22.350

Reputation: 15 025

@Okx My mistake. But why don't you just use ,[<<+>+>-]<[>>+<<-]+>>[-[->]<]<[<[<]>.<]? – user202729 – 2017-07-13T13:32:13.380

1

How about ,[[>]++[-<]<+>>]>[<<<.<] for only 3452857532394791089951 bytes?

– Jo King – 2019-08-21T03:52:42.520

Actually, since infinite loops are allowed, ,-[-->++<]>+. works as well

– Jo King – 2019-08-22T02:02:49.533

20

x86-64 Machine Code, 8 bytes

Inspired by Bruce Forte's solution, but slightly under par. :-)

8D 07          lea      eax, [rdi]    ; put copy of input parameter in EAX
D1 EF          shr      edi, 1        ; shift LSB into CF
             InfiniteLoop:
F3 73 FD       rep jnc  InfiniteLoop  ; test CF; infinite loop back here if input was even
C3             ret                    ; return with original input in EAX if it was odd

A single integer parameter is taken in the EDI register, following the System V AMD64 calling convention.

A copy of this value is initially made, and put into EAX so it can be returned if appropriate. (LEA is used instead of the normal MOV because we need an instruction with odd bytes.)

Then, the value in EDI is shifted right by 1, which places the shifted-off bit into the carry flag (CF). This bit will be 0 if the number was even, or 1 if it was odd.

We then test CF using the JNC instruction, which will branch only if CF is 0 (i.e., the number was even). This means that we will go into an infinite loop for even values. For odd values, we fall through and the original value (in EAX) is returned.

There is a bit of a trick with the JNC instruction, though—it has a REP prefix! Normally, REP prefixes are only used with string instructions, but because the Intel and AMD manuals both agree that irrelevant/superfluous/redundant REP prefixes are ignored, we throw one on the branch instruction here to make it 3 bytes long. That way, the relative offset that gets encoded in the jump instruction is also odd. (And, of course, REP is itself an odd-byte prefix.)

Thank goodness RET is encoded using an odd byte!

Try it online!


In case you don't think returning the value if it's odd or going into an infinite loop if it's even (so that you never return) satisfies the "output" requirements of the challenge, or you just want something more interesting, here's a function that outputs the value to a serial port (but only if it's odd, of course).

x86-64 Machine Code (output to serial port), 17 bytes

8D 07         lea   eax, [rdi]   ; put copy of input parameter (EDI) in EAX

B1 F7         mov   cl, 0xf7     ; put 0xF7 into low-order bits of CX
B5 03         mov   ch, 0x03     ; put 0x03 into high-order bits of CX
FE C1         inc   cl           ; increment low-order bits of CX to 0xF8 (so all together it's now 0x3F8)
0F B7 D1      movzx edx, cx      ; move CX to DX ("MOV DX, CX" would have a 16-bit prefix of 0x66)

D1 EF         shr   edi, 1       ; shift LSB of input parameter into CF
73 01         jnc   IsEven       ; test CF: branch if 0 (even), fall through if 1 (odd)
EF            out   dx, eax      ; output EAX (original input) to I/O port 0x3F8 (in DX)
            IsEven:
C3            ret                ; return

What makes this a bit more interesting is that the code does more, which means it was more challenging to do it all using instructions that are encoded using only odd bytes. Of course, this also means that it fails at code golf, so it's kind of a tradeoff—do you want interesting and challenging, or do you want short?

Anyway, this uses the x86 OUT instruction to write to I/O port 0x3F8, which is the standard COM1 serial port on a PC. The fun part, of course, is that all standard I/O ports (serial and parallel) have even addresses, so they can't simply be encoded as immediates for the OUT instruction or moved directly into a register. You have to initialize with one less than the actual value, and then increment the value in the register. You're also limited to using certain registers for the manipulation because you need registers that are encoded using odd bytes in the instruction when used as operands.

Also, I had to initialize the DX register (via the CX register) at the top of the loop, even though this is only needed if the value is odd, to ensure that the JNC instruction would have an odd offset. However, since what we're skipping over is the OUT instruction, all this code does is waste cycles and clobber scratch registers; it doesn't actually output anything, so it doesn't break the rules.

Finally, this function will return (after having either done or not done the output to the serial port) with the input value left in EAX. But that doesn't actually break any rules; all functions in assembly language will return with a value in EAX—the question is just is it a significant value or a garbage value. That's determined by the function's documentation (essentially, does it return a value or does it return void), and in this case, I'm documenting it as not returning a value. :-)

No TIO link for this one, as it doesn't implement output to serial ports. You'll need real iron, or an imagination.

Cody Gray

Posted 2017-07-11T09:26:22.350

Reputation: 2 639

+1 for the explanation! Why can you use mov in the second line but not in the first? – M.Herzkamp – 2017-07-12T16:17:27.377

In addition to encoding that it's a MOV instruction, its operands also have to be encoded in the bytes. In this case, that would be the source and destination registers (although operands can also be immediate values, which are like constants). Different registers map to different bytes, and some of those bytes are even. So, for example, what I would want to use would be mov eax, edi, but that is 89 F8 in bytes. See way more than you ever wanted to know on encodings here, under the "code" section. @M.Herzkamp

– Cody Gray – 2017-07-12T18:34:52.213

19

Jelly, 2 bytes

ẋḂ

These characters correspond to bytes 0xF7 and 0xBF in Jelly's code page.

Try it online!

Dennis

Posted 2017-07-11T09:26:22.350

Reputation: 196 637

5Would be a shame if this solution with even byte count won the challenge... a 1 byte solution anyone? – M.Herzkamp – 2017-07-14T09:50:19.440

9

05AB1E, 3 bytes

Éi=

The code corresponds to the byte values C9,69,3D or 201,105,61 which are all odd.

Try it online!

Explanation

É     # input % 2 == 1
 i    # if true
  =   # print without popping

Emigna

Posted 2017-07-11T09:26:22.350

Reputation: 50 798

= # print without newline that's actually print with newline without popping – Erik the Outgolfer – 2017-07-11T10:43:04.613

@EriktheOutgolfer: True. I'll fix the explanation. – Emigna – 2017-07-11T10:45:00.810

Unfortunately, É× doesn't seem to work ): – kalsowerus – 2017-07-11T10:55:06.037

@kalsowerus: Yeah, I noticed that as well. Works correctly with a D in front, but that's even and not any shorter. The reason it doesn't work is that the repeated implicit input is taken as 2nd argument. – Emigna – 2017-07-11T11:03:54.797

@Emigna but the weird thing is, swapping the top two values on the stack twice, makes it work as well... – kalsowerus – 2017-07-12T11:21:31.243

@kalsowerus: That's because in this case, Éss× is the same thing as ɹs× which are both just longer ways of writing DÉ×. – Emigna – 2017-07-13T05:27:48.057

5

MATL, 3 bytes

o?G

MATL uses ASCII characters, so o?G corresponds to bytes (in decimal) 111, 63, 71.

Try it online!

Explanation

o     % Push (implicit) input modulo 2
?     % If nonzero
  G   %   Push input
      % End (implicit)
      % Display stack contents (implicit)

Luis Mendo

Posted 2017-07-11T09:26:22.350

Reputation: 87 464

5

Haskell, 36 33 bytes

c[1]=1;c[m]=1+1+c[m-1-1];o	m=c[m]

Try it online!

Usage: o 7 yiedls 7, o 8 enters an infinite loop.

The actual algorithm is

o 1 = 1
o m = 2 + o(m-2)

The first problem I faced was the lack of space and (, because a function o which takes an argument m is usually defined as o m=... or o(m)=.... However I found out that an inline comment {- some comment -} works as token delimiter too, so a definition o{--}m=... is possible under the given rules. Edit: Ørjan Johansen pointed out that one can use a tab character instead of a space, saving three bytes: o m=...

The second problem was the recursive call o(m-2). -2 is just -1-1, but here the comment trick does not work because the parentheses are required. I fixed this by letting the function work on a singleton list containing a number: o[m-2], however, as this is not a standard way of providing input, I outsourced the computation to a helper function c which works on lists and call c from o which has the correct format.

Laikoni

Posted 2017-07-11T09:26:22.350

Reputation: 23 676

You can use a tab instead of a space. – Ørjan Johansen – 2017-07-12T16:36:57.317

@ØrjanJohansen I can verify that it works with \t instead of {--}. – Esolanging Fruit – 2017-07-12T22:48:15.057

@ØrjanJohansen Thanks, that's good to know. – Laikoni – 2017-07-13T07:01:56.947

5

Python REPL, 38 bytes

Takes input as the value of the previous expression using _. Output will be a string (the string representation of the integer for odd, or the empty string for even).

'%s'%[['']+[_]][-1][[_%[1+1][-1]][-1]]

Try it online

To run it in an actual shell, you can try it here. Type the input, hit enter. Paste the code, hit enter.

Explanation:

This took a while to figure out. There's no multiplication, no branching, no slicing, no commas, no periods, no imports, no parentheses, no exec, no eval, no print, and no functions. I got one solution working that output using stderr, but then I realized we had to output the actual integer, not just a truthy/falsey value.

I use brackets in place of parentheses with [expression][-1]. Simplifying that turns the above code into '%s'%(['']+[_])[_%(1+1)].

Since there can be no commas, I used list addition to create ['',_]. Using string formatting, the desired result is obtained.

mbomb007

Posted 2017-07-11T09:26:22.350

Reputation: 21 944

Kudos. As a bonus, it also works for Ruby IRB :) Nitpick: is it okay to return a string for odd numbers, is it okay to return an empty string for even numbers? – Eric Duminil – 2017-07-13T20:14:29.220

Doing nothing and printing or returning nothing are the same, I'd think. In a way, empty string is nothing. – mbomb007 – 2017-07-13T20:29:32.780

Yes, I was really nitpicking. It still returns a string instead of nothing. In Python REPL, I'd say that None would be an even better match than ''. Anyway, that's still 10000 times better than anything I could come up with. – Eric Duminil – 2017-07-13T20:31:28.383

@EricDuminil I could return False. Idk how you could get None, though. – mbomb007 – 2017-07-13T20:59:38.953

4

Cubix, 23 19 17 bytes

;;u!I1)%/;O=!;;/;

Try it!

@, which terminates a Cubix program, is ascii 64, so unfortunately this actually just enters an infinite loop after testing for oddness. No TIO link since it'll time out.

= (ascii 61) is a no-op in Cubix.

This is a slight modification of the prior algorithm (same # of bytes) that actually works for negative integers.

Cube version:

    ; ;
    u !
I 1 ) % / ; O =
! ; ; / ; . . .
    . .
    . .

Algorithm:

  • I (73) : read in input as number
  • 1 (49) : push 1
  • ) (41) : increment
  • % (37) : take the mod
  • / (47) : turn left
  • ! (33) : skip next instruction if odd
    • 1;;/; ; is (59) : prepares the stack for output
    • O (79) : Output as a number.
    • Then it re-enters the algorithm but I reads a 0 for end of input, so we are guaranteed to enter the even branch
  • u (117) : right-hand u-turn
  • ;;;!I : loop, effectively doing nothing.

Giuseppe

Posted 2017-07-11T09:26:22.350

Reputation: 21 077

@MickyT that fails for negative input, which is why I avoided using ? – Giuseppe – 2017-07-14T12:27:47.977

Apologies, I didn't check it properly – MickyT – 2017-07-14T15:14:02.347

4

CJam, 6 bytes

q_iY%%

113 95 105 89 37 37

This program takes the mod 2 of the input (call it r) and prints every r th character in the input string. If the input number is odd, it prints the whole string, but if asked to print every 0th character the program throws an error.

Try it here

geokavel

Posted 2017-07-11T09:26:22.350

Reputation: 6 352

Nice! I was going to post qi_Y%]W%{}/M? and then I saw this. – Esolanging Fruit – 2017-07-12T22:40:50.627

3

Charcoal, 9 bytes

¿﹪Iθ÷χ⁵→θ

Try it online!

Basically it prints rightwards the input if it is not a multiple of 10/5 (the ² char is even in the Charcoal code page). The characters used are:

  • ¿: code BF.
  • : code A5.
  • : code C9.
  • θ: code F1.
  • ÷: code AF.
  • χ: code E3.
  • : code B5.
  • : code 13.

In fact the near the end is redundant but then I saw that the answer had to have an odd length...

Explanation:

¿      if (
 ﹪      Modulo (
  Iθ      the input as number,
  ÷χ⁵      χ (predefined value: 10) divided by 5 = 2 ) [is 1])
 →θ      then print rightwards the input as string

Charlie

Posted 2017-07-11T09:26:22.350

Reputation: 11 448

You're printing and then moving right; print rightwards would actually be →θ. – Neil – 2017-07-11T12:11:58.337

@Neil oops, fixed. At least that didn't invalidate my answer... :-D – Charlie – 2017-07-11T12:15:21.387

3

x86_64 machine code (Linux), 12 11 bytes

Unfortunately 0x80 is even, but it still worked out (assuming "does nothing" means not to return):

0000000000000000 <odd>:
   0:   8d 07                   lea  (%rdi), %eax
   2:   83 e7 01                and    $0x1, %edi
   5:   83 ff 01                cmp    $0x1, %edi
   8:   75 fb                   jne       5  <odd+0x5>
   a:   c3                      retq

-1 byte, thanks @CodyGray!

Try it online!

ბიმო

Posted 2017-07-11T09:26:22.350

Reputation: 15 345

1Since this is x86-64, lea (%edi),%eax requires an address size override prefix (0x67) when the source is a 32-bit register. You can eliminate that by doing lea (%rdi),%eax. That saves a byte, and actually would make the code slightly more efficient (prefixes slow down decoding and fill up i-cache). There are some other things you can do to shorten this even more, but that essentially constitutes a complete rewrite, so I'll post my own answer. :-) I've upvoted this, too, of course! (Oh, just realized you may have used the prefix to make the jump offset odd. Well, you'll need more magic.) – Cody Gray – 2017-07-12T11:10:03.553

Also, really clever solution for TIO! I've been skipping it in most of my asm answers because I didn't want to write all of the boilerplate in the "footer" to print output in asm. I finally broke down and did it the other day, but this is a much better idea, allowing you to use C for everything else. I'll be stealing this from now on! :-) – Cody Gray – 2017-07-12T11:20:06.297

Cheers for your inputs, I'm a complete noob at assembly but this seemed easy enough! Curious for your solution. Oh, credit goes to @ceilingcat - I stole it myself ;) – ბიმო – 2017-07-12T11:51:42.847

I didn't actually save you a byte… What you have now has an even byte (F6) for the JNE instruction because it has an even offset. That's what I meant by the last parenthetical I edited into my first comment. You actually need that prefix to create an odd alignment. Or you have to rewrite the code in some other way. I played with a bunch of different variations. I actually looked at this last night and was trying to figure out a good way to use OUT to output odd values, but no good solutions really occurred to me. The insight here for me is to go into an infinite loop for even values. – Cody Gray – 2017-07-12T14:08:53.790

This is a pretty silly challenge, actually, because none of the reasonable solutions work. It really just tests how well you know the obscure corners of the x86 instruction set. I even tried the BT family of instructions, which nobody uses ever (unfortunately, all register encodings are even bytes). I thought it might be more interesting to write code that output to a serial port, rather than just returning a value or whatever, but that does jack the byte count up there (especially since serial port addresses in hex are even!), so I gave up on it. – Cody Gray – 2017-07-12T14:12:12.013

Oh boy, I didn't even check.. Fixed it though ;) – ბიმო – 2017-07-12T14:46:16.697

You could try to modify the code during runtime.. But with 11 bytes there's not a lot of room. – ბიმო – 2017-07-12T14:53:10.283

3

Mathematica, 20 bytes

Appear to be the first solution in non-golfing language.

a=1+1;g[i_/;!a\[Divides]i]=i

In MacintoshChineseTraditional character encoding. \[Divides] is {161, 253} (2 bytes)

Alternative version (23 bytes)

\[CapitalAlpha]=1+1;\[CapitalGamma][\[CapitalChi]_/;\[CapitalAlpha]\[LeftFloor]\[CapitalChi]/\[CapitalAlpha]\[RightFloor]\[NotEqual]\[CapitalChi]]=\[CapitalChi]

or (shown in Unicode)

Α=1+1;Γ[Χ_/;Α⌊Χ/Α⌋≠Χ]=Χ

in Symbol character encoding. (use only 1-byte characters)

The solution defines a function g (or Γ) that, evaluate to input when the input is odd, and literally "do nothing" (does not evaluate) when the input is even.

user202729

Posted 2017-07-11T09:26:22.350

Reputation: 14 620

+1 byte (; at the end) if the number of byte must be even; and \[Divides] also have odd Unicode codepoint. – user202729 – 2017-07-12T15:30:48.857

You don't need I[1+1], you can just use {1+1}. Also, have you checked whether the bytes of the flooring brackets are valid? If so, you can obtain 2 from \[LeftFloor]E\[RightFloor]. – Martin Ender – 2017-07-12T16:09:21.077

@MartinEnder Only Symbol make floor valid, but it has neither E nor \[ExponentialE]. – user202729 – 2017-07-13T11:21:00.130

I'm afraid you aren't allowed to use the characters D; v; nor d, since they have an even byte-value.. :( – Kevin Cruijssen – 2017-07-14T08:32:07.267

1@KevinCruijssen \[Divides] is one single character in Mathematica, which is represented by 2 bytes {161, 253}. – user202729 – 2017-07-14T09:01:57.133

@user202729 Ah ok, didn't knew that, Thanks for clarifying and +1 from me ;) – Kevin Cruijssen – 2017-07-14T21:01:40.650

3

Perl, 54 bytes

Requires -E.

I really really enjoyed this challenge, I think I'd like to try and improve this answer, but I think that's might be the shortest I can make for now. I've been playing with these answers on and off for a few days now, but feel I'm happy with the 54 byte solution!

s//A_=Y[;A_=A_%O?A_W''/;y/#A-_/#-A/;s/[#-}]+/uc/ee;say

Try it online!

Explanation

By default, most of Perl's string functions work on $_, which is empty to start.

First, s//A_=Y[;A_=A_%O?A_W''/ replaces the empty string in $_ with A_=Y[;A_=A_%O?A_W'', then y/#A-_/#-A/ replaces characters based on the following list (char above becomes char below):

#ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_
#$%&'()*+,-./0123456789:;<=>?@A

which updates $_ to contain $_=<>;$_=$_%2?$_:''. Next s/[#-}]+/uc/ee replaces all chars [#-}]+ with uc. Without the /ee this would just be the string uc, but /ee evaluates the contents of the string twice. The first evaluation returns the result of uc, which is an uppercase version of $_ but since $_ contains no alphabetic characters, this just returns the whole string, then the second /e evaluates the string again, which sets $_ to either $_ (the input number) or '' depending on whether or not the number is odd or even.

Finally, since $_ now contains what we want, we call say (which is what requires -E instead of -e) which prints $_ followed by a newline.


Alternative Perl, 93 bytes

92 bytes code + 1 for -p, which I feel would make it non-competing.

s//_/g;s//uc/e;y/\x09-\x0b/_/;s/____/}[/;s/___/%C]/;s/_/{''H/;y/'{}1CDGH/'-)1-3+--/;s/[#-}]+/uc/ee

Contains a tab and a vertical tab in the y///, indicated as \x09 and \x0b.

Try it online!

Dom Hastings

Posted 2017-07-11T09:26:22.350

Reputation: 16 415

2

LOGO, 390 46 52 50 bytes

[ask    1   se[make]iseq    1-3 cos ?/ask   1[1/sum 1   179]?]

That is a template-list that return the input if the input is odd, and cause an error if the input is even.

Usage:

show invoke [ask ... (paste code here) ... ] 5

output

5

since 5 is odd, and

invoke [ask ... (paste code here) ... ] 6

will cause an error because 6 is even.


user202729

Posted 2017-07-11T09:26:22.350

Reputation: 14 620

2

TI-BASIC, 14 bytes

Input Q
sinֿ¹(gcd(Q²,int(e
Q

This throws a domain error (printing nothing to the homescreen) on an even number.

Input Q             Q is a variable with an odd code. We cannot use "Ans" as it's even.

            int(e   floor(e) = 2; "2" is even.
         Q²         Q may be negative, so we square it which preserves parity.
     gcd(Q²,int(e   1 if Q is odd; 2 if Q is even.
sinֿ¹(gcd(Q²,int(e   Error iff Q is even.

Q                   If there was no error, print Q.

lirtosiast

Posted 2017-07-11T09:26:22.350

Reputation: 20 331

1

Pyth, 14 11 10 9 bytes

I+Q_+K/Q+3_1KQ
I!sIcQ+3_1Q
I!u+1_GQ1Q
?u+1_GQ1k

Test suite.

Leaky Nun

Posted 2017-07-11T09:26:22.350

Reputation: 45 011

That's a clever way, but shouldn't something like I%Qy1Q also work? – Jakube – 2017-07-12T06:42:47.820

@Jakube I clearly didn't figure out y1... However, % is not allowed, sadly. – Leaky Nun – 2017-07-12T07:07:25.247

Why not? % has ascii value 37 and is odd. – Jakube – 2017-07-12T09:17:32.897

3

@Jakube because apparently I trusted in this list the OP provided (which is wrong)

– Leaky Nun – 2017-07-12T09:30:46.277

1

Japt, 4 bytes

u)çU

Japt uses ISO/IEC 8859-1, so this corresponds to (in decimal) 117 41 231 85.

Test it online!

Explanation

Uu)çU   Implicit: U = input integer
Uu)     Return Python-style U % (missing argument = 2). This gives 1 if U is odd, 0 if even.
   çU   Implicitly convert U to a string and repeat it that many times.
        Implicit: output result of last expression

I first tried solutions using p, which is basically ç with reversed arguments. However, p performs exponentiation if its left argument is a number, so we'd need to explicitly convert it to a string. This solution turns out to actually be a byte shorter, in addition to not containing any odd bytes.

ETHproductions

Posted 2017-07-11T09:26:22.350

Reputation: 47 880

1

dc, 21 bytes

[c]sa?kKKCI-1;1k%1!=a

Decimal: 91 99 93 115 97 63 107 75 75 67 73 45 49 59 49 107 37 49 33 61 97

As per this IO default, this program leaves the input on the main stack if it is odd and empties the stack otherwise. This can be confirmed by adding the f debug command to the end of the program as is the case on the TIO page.

Try it online!

Explanation

[    # Begin macro definition.
 c   # Clear the main stack.
]sa  # End macro definition and push the macro into register "a".
?k   # Prompt for input and store it into precision parameter "k".
KK   # Push two copies of the input to the main stack.
CI-  # Push C-I = 12-10 = 2 to the main stack  
1;1  # Push the value stored in the first index of array "1" (0 by default) 
     # to the main stack. 
k    # Push 0 into parameter "k" to reset the precision (otherwise the modulus 
     # function will not work correctly).
%    # Push the input (mod 2) to the main stack.
1!=a # If the input (mod 2) does not equal 1, execute the macro in register "a".
f    # OPTIONAL: Output the contents of the main stack.

R. Kap

Posted 2017-07-11T09:26:22.350

Reputation: 4 730

1

TI-Basic, 18 bytes

Saved 2 bytes thanks to lirtosiast

:Prompt Q
:While 5Q/ᴇ1-int(5Q/ᴇ1
:Q

in bytes (+2 newlines = 3F)

:Prompt Q
 DD     51
:While 5Q/ᴇ1-int(5Q/ᴇ1
 D1    35 3B B1  35 3B  
        51 31     51 31
         83 71     83
:Q
 51

See http://tibasicdev.wikidot.com/one-byte-tokens

Oki

Posted 2017-07-11T09:26:22.350

Reputation: 311

1Why not use fPart(? – lirtosiast – 2017-07-13T23:11:02.877

@lirtosiast seems to be an even byte (BA = 186) according to http://tibasicdev.wikidot.com/one-byte-tokens

– Oki – 2017-07-14T22:32:30.763

Oh, I misread which entries were rows and which are columns. – lirtosiast – 2017-07-14T22:46:11.000

1I found Input Q[newline]sinֿ¹(gcd(Q²,int(e[newline]Q (14 bytes). May I post as separate answer? – lirtosiast – 2017-07-14T23:47:14.287

@lirtosiast Wow! It's definitely different enough for a seperate answer. Love it – Oki – 2017-07-15T00:11:09.353

@lirtosiast don't see the use for ² tough – Oki – 2017-07-15T00:24:44.643

We need to square to make nonnegative, because gcd( only works on nonnegative integers. – lirtosiast – 2017-07-15T22:41:42.163

1

MathGolf, 3 bytes

¥{k

Try it online!

The used bytes are 157, 123, 107.

Explanation

¥     Input modulo 2
 {    Loop that many times
  k   Push input

Jo King

Posted 2017-07-11T09:26:22.350

Reputation: 38 234

0

Bash, 31 bytes

read a
[ $[a%2] = 0 ] ||echo $a

Try it online!

Explanation:

read a                   reading the input and define it on the variable a
[ $[a%2] = 0 ]      outputs exit status 0 when a/2 is 0 and exit status 1 if not.
||                           evaluates only when the exit status left of it is 1
echo $a                displays the variable a

ADDB

Posted 2017-07-11T09:26:22.350

Reputation: 171

You seem to have missed that this is a restricted source challenge - you are using forbidden bytes. (rd $20|h and newline.) – Ørjan Johansen – 2017-07-13T22:58:56.340

@ØrjanJohansen fixed I guess – ADDB – 2017-07-13T23:00:40.263

2Um no. There is no restriction on the length of the program, but every character in it must have an odd byte value. – Ørjan Johansen – 2017-07-13T23:04:29.763