No, do not check for positive-integer-ness unless you really want to. It at least has to give the right result for the test cases. Yes, Xeda, whatever you want. Just make it work at least with the test cases. Yes, PM me any solutions. Yes, z80 is judged by its final size. So would Axe. Yes, printing HAPPY/UNHAPPY would also be acceptable.
EDIT: Oh, and I will reveal all solutions in spoilers in the OP. My own solution in TI-BASIC is 71 bytes (minus the name). Let's see who can do better...
This is the first of what I hope to be many contests I will hold here on Omnimaga: Code Golf.
Code golf is a competition where you have to solve a coding challenge in the fewest bytes possible. For example, a TI-BASIC entry for a prime tester could be:
Input N:0:If N and not(fPart(N:2=sum(seq(not(fPart(abs(N)/I)),I,1,abs(N:Ans(note that this is not the speediest it could be, but speed is not factored in your score, only size) The score would be 34 bytes (for TI-BASIC programs, score=size - 9 - length of name). The lowest score out of the entries will be the winner.
How this tournament will work: First off, you need to code an actual program that will solve the given problem (or at least give the right result for all the test cases ). All languages are allowed, including calc languages and computer languages. When you have an entry, PM it to me, and I will test it if possible (but just in case I don't have an Nspire or I can't download the latest version of Perl or some such problem, try if you can to give back the results of any and all given test cases). I will then save your entry and update the scores accordingly. After one week, a winner shall be determined in each language category, as well as the smallest overall. In each language category, the winners shall all suggest possible problems for the next competition. I shall pick the next challenge out of these, and present test cases for any possible input or output. Also, you will get to see everyone else's solutions for the previous challenge.
Please, ask any and all questions that you may have about the contest!
Problem Determine if an inputted number is happy. Happy numbers are defined like this: Take any positive integer, replace it with the sum of the squares of its digits, and repeat the process until it equals 1 or it loops indefinitely in a loop that does not include 1. If it ends up with 1, the number is happy, otherwise it's sad. Deadline July 21, 2014, 1:00 AM EST Sample input 1: 1 Sample output 1:
x=input();b="UNHAPPY" for a in b: z=0 for y in str(x):z+=eval(y)**2;x=z print(b[(z==1)*2:7])
2
Juju
148
7/15/2014 4:22:50 PM
Spoiler For Spoiler:
def h(n): while n>1 and n!=4: n=sum(dict([(c,int(c)**2)for c in"0123456789"])[d] for d in str(n)) return n==1 print(("SAD","HAPPY")[h(input())])
Golfscript
Rank
User
Size
Date
Code
1
Runer112
32
7/15/2014 5:17:50 PM
Spoiler For Spoiler:
~{`0\{48-.*+}/}9*("SAD""HAPPY"if
CJam
Rank
User
Size
Date
Code
1
Runer112
30
7/15/2014 5:17:50 PM
Spoiler For Spoiler:
q~{Ab0\{_*+}/}9*("SAD""HAPPY"?
TI-83+ BASIC
Rank
User
Size
Date
Code
1
calc84maniac
46
7/16/2014 5:03:49 PM
Spoiler For Spoiler:
Repeat Ans<5 sum(.5×√int(10fPart(Ans/10^(cumSum(binomcdf(98,0→A End "HAPPY If log(A "SAD Ans
2
Runer112
46
7/16/2014 5:09:28 PM
Spoiler For Spoiler:
Repeat A≤4 iPart(10fPart(Ans10^(~cumSum(binomcdf(14,0 sum(Ans²→A End "HAPPY If log(A "SAD Ans
3
Hayleia
71
7/16/2014 2:18:36 AM
Spoiler For Spoiler:
Prompt N Repeat N=1 or N=4 sum(seq((10fPart(iPart(N10^(~I))/10))²,I,0,14→N End "HAPPY If N=4 "SAD Disp Ans
TI-83+ z80
Rank
User
Size
Date
Code
1
Runer112
58
7/20/2014 9:32:08 PM
Spoiler For Spoiler:
;#SECTION "MAIN", CODE
org userMem - 2 db 0BBh, 6Dh Start: B_CALL _RclAns StepLoop: push bc sbc hl, hl ld b, h DigitPairLoop: dec e DigitLoop: ex de, hl xor a rrd ex de, hl ld c, a SquareLoop: add hl, bc dec a jq nz, SquareLoop ld a, (de) or a jq nz, DigitLoop ld a, e cp (OP1 + 2) & 0FFh jq nz, DigitPairLoop push hl B_CALL _SetXXXXOP2 rst 30h pop hl pop bc djnz StepLoop dec l ld hl, UnhappyStr jq nz, Unhappy inc hl inc hl Unhappy: B_CALL _PutS ret
.org $9D93 .db $BB,$6D bcall(_RclAns) ex de,hl HappyCalcLoop: xor a ld c,a ld d,a ld e,a HappyByteLoop: ;Carry is reset, upper nibble of A is 0 dec l HappyNibbleLoop: rrd ld b,a HappyMulLoop: push af add a,e daa ld e,a ld a,c adc a,d daa ld d,a pop af djnz HappyMulLoop ccf jr c,HappyNibbleLoop ld a,l sub (OP1+2)&$FF jr nz,HappyByteLoop ld (hl),d inc l ld (hl),e inc l inc (hl) jr nz,HappyCalcLoop ld hl,HappyString dec e jr z,$+4 dec hl dec hl bcall(_PutS) ret
I would like to propose a monthly contest on Omnimaga: Code Golf.
Code golf is basically solving a certain coding problem in the fewest amount of bytes possible. For example, a golfed primality tester in TI-BASIC would be:
Input N:0:If N and not(fPart(N:2=sum(seq(not(fPart(abs(N)/I)),I,1,abs(N:AnsThe score then would be 43 bytes (technically, 43+length of name, but for calc-language purposes, the name is not included in the score). Lowest score wins. (note this isn't as speedy as it could be, but speed would not count against you) If possible, have it work for as many possible test cases as you can while still making it short.
Anybody could submit challenges (so long as you give test cases as well). Hopefully we can allow all calc languages, as well as computer languages (so long as you can test them, and you can show us the results of the test cases).
Who would I talk to in order to get something like this started here?
I should put this on my calc when I have time. I would like to try all 2048 Axe clones, though. I wonder how good the grayscale in yours look like on a real calc.
Also, how are the small fonts done? Are they custom fonts or is this just an image?
Well, the grayscale looks fine on an actual calc.
And the small fonts you are talking about? Those are all Bitmaps, drawn with the Bitmap() command. Every "block" of text that is not an original TI font is drawn with a Bitmap of some sort. (It's the only way I could get everything I wanted to fit to fit!)
This is a collection of phrases that describe the number of letters that the phrase has. For example, "a two written next to a one" describes 21, and has 21 letters. Here are some examples from 1 to 100: