calculator

Discussion of challenges you have already solved
samc
Posts: 4
Joined: Thu Aug 20, 2009 1:23 am

Post by samc »

I copied the input to start from location 54 in memory so that I could use 0-53 for my own purposes.

After the copy, I stored my jump values (and some other values) in the single-digit memory locations so that jumping would be super easy. If a jump value needed to change, no problem, just change the hard-coded value that gets stored in memory during init.

I also stored the subroutine locations of each input handler in the location corresponding to that inputs ordinal value to make input handling really easy. My input iterator was stored in memory 0, so in order to handle the next input, all I had do was 0<<<c (unless it was a digit).

My solution (250 characters):

Code: Select all

96*1+g 1^2?1g$1v1-3*g+7g-4g*1g/3<g  0$7c1vd$7c10$7c20$30$40$ 96*0^00^<73*?0^<2^>1v1+1v1+093*-g dd0> 55+1> 86*2> 039*-3> 696*-4> 86*1-5> 95*85*1^9-1^>1^7-1^1+>1^1-    1^3+>1^4+1^5+>1^9+1^2+>1^93++1^7+> dd00 0<<2?4g7cp!0<<5<:1-8?0<<<c1<g1<*0<<2<-+0<1+0>4<g
User avatar
Hippo
Posts: 339
Joined: Sat Feb 01, 2014 12:05 am
Location: Praha 5

Post by Hippo »

I am using excell for the HVM codding:
It concatenates the code and computes the addresses, otherwise I am codding manually.
... I am describing stack states at starts and ends of code lines.
I will remove the sum of code here... of course the formulas are hidden ...
I have problems to format it properly here.. Tabs don't align :(.

Code: Select all

Label	Addr	Code	Plan	Description at the start	Description at the end	Desired jmp
	0	0<68*-00>59*c			[Dig0][45]	expr
	13	dp!		[Expr][Dig]		
readdigdrop	16	d				
readdig	17	0<1+0>0<<0^48*-264*-?			[Chr][Chr= ][-22]	readdigdrop
	38	68*-$!!		[Chr]	[Dig]	
expr	45	654**c		[Dig]	[Dig][120]	factor
exprcont	51	0^5+9?		[expr][Dig]	[expr][Dig][Dig=+][9]	plus
	57	0^3+55*?		[expr][Dig]	[exprr][Dig][Dig=-][25]	minus
	65	$				
plus	66	d98+c		[expr][+]	[expr][17]	readdig
	71	654**c		[expr][Dig]	[expr][Dig][120]	factor
	77	2v2v+1v158*-g		[expr][factor][dig]	[expr][dig][-39]	exprcont
minus	90	d98+c		[expr][-]	[expr][17]	readdig
	95	654**c		[expr][Dig]	[expr][Dig][120]	factor
	101	2v2v-1v188*-g		[expr][factor][dig]	[expr][dig][-63]	exprcont
	114	!!!!!!				
factor	120	558**c		[Dig]	[Dig][200]	kern
factcont	126	0^6+9?		[fact][Dig]	[fact][Dig][Dig=*][9]	mul
	132	0^1+55*?		[fact][Dig]	[fact][Dig][Dig=/][25]	div
	140	$				
mul	141	d98+c		[fact][*]	[fact][17]	readdig
	146	558**c		[fact][Dig]	[fact][Dig][200]	kern
	152	2v2v*1v158*-g		[fact][kern][dig]	[fact][dig][-39]	factcont
div	165	d98+c		[fact][/]	[fact][17]	readdig
	170	558**c		[fact][Dig]	[fact][Dig][200]	kern
	176	2v2v/1v188*-g		[fact][kern][dig]	[fact][dig][-63]	factcont
	189	!!!!!!!!!!!				
kern	200	0^8+47*?		[Dig]	[Dig][Dig=(][28]	open
number	208	98+c		[Num]	[Num][17]	readdig
	212	0^0:1+94+?		[Num][dig]	[Num][dig][notdigit][13]	endnum
	222	1v52**+039*-g		[Num][dig]	[Num'][-27]	number
endnum	235	$		[Num][dig]	[Num][dig]	
open	236	d98+c		[Dig]	[17]	readdig
	241	59*c		[Dig]	[Dig][45]	expr
	245	d98+c		[Expr][)]	[Expr][17]	readdig
	250	$		[Expr][dig]	[Expr][dig]	
Hckr
Posts: 27
Joined: Thu Mar 25, 2010 2:16 pm

Post by Hckr »

Hi hackers, what about your cycle counts? Let's compare :D

8+5*(1+2)
798 cycles

(((26+10)*(28*25*12))*((5+9)+(20+23))+24-12-23*20)
3098 cycles

2342524*(234663+123551+512123)*41241412-23415354
2727 cycles
User avatar
Hippo
Posts: 339
Joined: Sat Feb 01, 2014 12:05 am
Location: Praha 5

Post by Hippo »

Hckr wrote:Hi hackers, what about your cycle counts? Let's compare :D

8+5*(1+2)
798 cycles

(((26+10)*(28*25*12))*((5+9)+(20+23))+24-12-23*20)
3098 cycles

2342524*(234663+123551+512123)*41241412-23415354
2727 cycles
8+5*(1+2)
output 23, 581 cycles
output 23, 580 cycles (with simulator mentioned in next post)

(((26+10)*(28*25*12))*((5+9)+(20+23))+24-12-23*20)
output 17236352, 2932 cycles
output 17236352, 2931 cycles (with simulator mentioned in next post)

2342524*(234663+123551+512123)*41241412-23415354
integer overflow ... have you used HVM from the pages?
output 1412163254, 2674 cycles (with simulator mentioned in next post)

... seems my solution when digit serves as an operation *10+digit when no other operation is found favours you in long numbers ...
try
1234567897 as an input
output 1234567897, 583 cycles (*)
Last edited by Hippo on Mon Aug 14, 2017 8:45 am, edited 3 times in total.
Hckr
Posts: 27
Joined: Thu Mar 25, 2010 2:16 pm

Post by Hckr »

User avatar
Hippo
Posts: 339
Joined: Sat Feb 01, 2014 12:05 am
Location: Praha 5

Post by Hippo »

Nice simulator ... (at least input preparation is really easy). It's a pitty I have only the last rat as a HVM challenge.

BTW: Is there an option to change the font size in the code window? I have problems to read the code here.
Post Reply