Login [Register]
Don't have an account? Register now to chat, post, use our tools, and much more.

The smallest Number Flipper is…
>70 bytes
 0%  [ 0 ]
<=70 and >60 bytes
 0%  [ 0 ]
<=60 and >50 bytes
 0%  [ 0 ]
<=50 and >40 bytes
 57%  [ 4 ]
<=40 and >30 bytes
 42%  [ 3 ]
Total Votes : 7

LJ Open: The Third Hole - Number Flipper

This program should take a number in Ans and return the "flipped" number in Ans. Because this program does not output anything during execution, it is an "invisible" program. The program should physically flip the number upside down, i.e. 6->9 8->8 60->09. I deem only 0 6 8 9 flippable digits, so if a unflippable number is given, simply return 0 (see examples below) leading and ending zeros can be ignored due to the nature of flipping numbers. Input is assumed to be a positive integer or zero (Whole Numbers).

Examples of usage:

0 // due to 106 being an unflippable number


PT_ requested no example code, so I'll leave it up to everyone else to create their own example code.

Restrictions wrote:
Restricted tokens: prgm
(input/output) Ans must be a positive integer or zero (Whole Numbers)

Size: The program's size is measured as:

on-calc-size - 9 - length(name)

The poll will be open for a week. I will post my solution as soon as someone beats it or about a week has passed. Good luck!

Current Results: where invalid inputs -> 0
lirtosiast: 38 (with error on invalid)
lirtosiast: 45
kg583: 51
LogicalJoe: 56

Alternate Results: where invalid inputs -> unknown outputs
lirtosiast: 30
PT: 33 (with imaginary output)
LogicalJoe: 42
PT: 42
kg583: 43
Here is my 42-byte solution, with the condition that input is always valid (and invalid inputs yields unknown outputs, as it should be):

Can we assume that the calculator has been reset prior to running the program (ie. that lists have not been initialized, variables are 0, etc.)
Is one not flippable?
36 bytes by PT_'s rules.

ZStandard:While Ans:Ans->X

53 bytes with input validation.

sum(Ans10^(dim(Ans)-cumSum(1 or Ans

Bonus 38 byte program without input validation:

While real(Ans

mr womp womp wrote:
Can we assume that the calculator has been reset prior to running the program (ie. that lists have not been initialized, variables are 0, etc.)

I believe this is the default assumption. If so, I have 34 bytes (without input validation).

Edit: 32 bytes, without input validation or initializing variables.

While Ans
51 bytes by the true contest rules:

:While int(N

Drop the last line and you have 43 bytes that satisfy PT's cop-out. /s

If you want to be really pedantic, my output is not strictly a whole number, since it tends to have a minuscule (10^-7 ish) fractional part. That could be fixed at the cost of a byte by switching around the round( command.

EDIT: Thanks to lirtosiast for the tip about ZStandard (and how to loop properly lol), which brings this down to 47 bytes:

:While Ans

If the calculator is assumed to have been just reset, then ZStandard (the first line above) can be dropped to grant 45 bytes.
I am glad to see lirtosiast came up with something similar to my (56 byte) solution:

Here is my (42 byte) solution to PT's "version":

Edit 1: Fix zero input error
Up until now I had been using the hash finder from my guide.

I fired up the slower, more general expression finder I used to return 2017 without using digit characters and managed 43 bytes with input validation. 45 if we can't assume a freshly cleared calc.

While Ans
If iPart(tan(sinh(8sinh^-1(fPart(X

This also brings the version without input validation down to an even 30 bytes:

While Ans

Edit: Added expression finder to guide.
Based on the 30-bytes version of @lirtosiast, here's my 33 bytes solution which uses complex numbers and is a few lines shorter:

While real(Ans

Oh, and the output is imaginary, but since we're already playing with different rules, I consider this valid as well Razz
Can we set Ans to the correct value and then throw an error? This is allowed under CG.SE rules. If so I think I can get 36-37 bytes (assuming freshly cleared calc). If not I don't see a way to get under 39ish.

Edit: 38 bytes, with some help from kg583. 37 may be possible, but I'm too busy to generalize the expression finder to find it.

This uses the 3fPart(10^(3fPart(X to map invalid digits to numbers outside [-1,1], then sin^-1( to throw an error on those, in which case 0 is left in Ans. It takes 4 more bytes to process the result for valid digits into (0,9,8,6).

While Ans
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are GMT - 5 Hours
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum