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 ]

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:
Code:
```980:prgmF[:Ans] 86 106:prgmF[:Ans] 0 // due to 106 being an unflippable number 9068906:prgmF[:Ans] 9068906```

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:

Code:
`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):

toString(Ans
Sigma(10^(A-1)inString("-----9-86",sub(Ans,A,1)),A,1,length(Ans
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
10Y+int(10fPart(779sinh(fPart(.1X->Y:int(.1X:End:Y

53 bytes with input validation.

int(10fPart(Ans10^(~1-seq(X,X,0,log(Ans+not(Ans
int(10fPart(171sinh(Ansmin(6<=gcd(72,Ans
sum(Ans10^(dim(Ans)-cumSum(1 or Ans

Bonus 38 byte program without input validation:

While real(Ans
int(10Ans-9.9real(Ans)+[i]int(10fPart(779sinh(fPart(.1real(Ans
End
abs(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
.1Ans->X
10Y+int(10fPart(779sinh(fPart(X->Y
int(X
End:Y
51 bytes by the true contest rules:

:DelvarMAns->N
:While int(N
:.1int(N->N:5fPart(Ans
:10M+5/9Ans(6+Ans-.4Ans^^2->M
:End
:Mnot(fPart(round(M,1

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:

:ZStandard
:While Ans
:.1int(Ans->N:5fPart(Ans
:10Y+5/9Ans(6+Ans-.4Ans^^2->Y
:int(N
:End
:Ynot(fPart(round(Y,1

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:
int(10fPart(Ans10^(~cumSum(not(0rand(length(toString(Ans
int(10fPart(680910^(5-Ansint(2min(fPart(1983cosh(1+Ans
sum(Ans10^(dim(Ans)-cumSum(not(0Ans

Here is my (42 byte) solution to PT's "version":
int(10fPart(680910^(5-int(10fPart(Ans10^(~cumSum(not(0rand(length(toString(Ans
sum(Ans10^(dim(Ans)-cumSum(not(0Ans

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
.1Ans->X
0
If iPart(tan(sinh(8sinh^-1(fPart(X
Return
10Y+int(10sin([e]fPart(X->Y
int(X
End:Y

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

While Ans
.1Ans->X
10Y+int(10sin([e]fPart(X->Y
int(X
End:Y

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
int(10Ans-9.9real(Ans)+[i]int(10sin([e]fPart(.1real(Ans
End

Oh, and the output is imaginary, but since we're already playing with different rules, I consider this valid as well 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).

Code:
```ZStandard While Ans   .1Ans->X   0   iPart(10(Y+fPart(48sin^-1(3fPart(10^(3fPart(X->Y   int(X End:Y```

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.

»
» 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