The Implementation of Rotating Numbers

We call a number X a good number, and if each of its Numbers is rotated 180 degrees one by one, we can still get a valid number that is different from X. Each number is required to be rotated.

A number is valid if each of its digits remains a number after being rotated.0, 1, and 8 are still themselves when rotated;2 and 5 can be rotated into each other (in this case, they rotate in different directions; in other words, 2 and 5 are mirror images of each other); the same thing with 6 and 9, any number other than these is no longer a valid number after rotation.

Now we have a positive integer N, how many numbers from 1 to N is X a good number?

Example:
Input: 10
Output: 4
Explanation:
There are four good Numbers in [1, 10] : 2, 5, 6, 9.
Notice that 1 and 10 are not good Numbers, because they don’t change after rotation.

Subject Analysis
This problem can be solved recursively. When solving this problem, the operation of finding the remainder is used to judge whether the units digit meets the condition of good number.And then we use division to figure out whether the tens place, the hundreds place, or the thousands place is a good number.
After n%10, the program determines whether the remainder matches the good number and is valid. Returns false if n%10 is invalid and not a good number.
If the units digit is valid or good, then the tens digit is judged, then the thousands digit is judged, and so on, up to the highest digit.The Boolean function used for marking is assigned to True if the valid conditions are met from the ones place to the highest place, and one of them is a good number. This code uses the switch function and uses the idea of recursive functions. So its space complexity is O(n).

Code

package main

import (
	"fmt"
)

func main() {
	var N int
	var answer int
	fmt.Scan(&N)
	answer=rotatedDigits(N)
	fmt.Println("Input:",N," Output:",answer)
	}
func good(n int ,flag bool) bool {
	if n == 0 {
		return  flag
	}
	d := n % 10
	switch d {
	case 3,4,7:
		return  false
		// 3,4,7不为好数且无效
	case 0,1,8:
		return good(n/10,flag) //0,1,8有效但不为好数
	}
	//2,5,6,9 为好数
	return  good(n/10,true)
}

func rotatedDigits(N int) int {
	flag := false
	answer := 0
	for i := 1 ; i <= N; i++{
		if good(i,flag){
			answer++
		}
	}
	return answer
}

Result
在这里插入图片描述

旋转电机的设计是指为实现特定的电动力学工作要求,设计电机的结构、尺寸、材料、绕组和控制系统等方面的工艺活动。旋转电机的设计过程包括以下几个关键步骤: 首先,根据实际需求确定电机的工作要求,包括额定功率、额定电压、额定转速等参数。然后,根据这些参数选择合适的电机类型,如直流电机、交流感应电机或永磁同步电机等,并确定电机的额定工作点。 接下来,进行电机的结构设计。这包括确定电机的定子和转子结构。在定子结构设计中,需要确定定子铁芯的形状和尺寸,以及绕组的布置方式。而转子结构设计则涉及转子铁芯的形状和尺寸,以及转子绕组的设计。其中,转子铁芯的形状和尺寸会直接影响电机的运行性能和效率。 在电机结构设计的基础上,进行电机的电磁设计。这包括确定电机的磁路特性,如磁阻、磁通密度等。也就是根据机械结构设计结果确定电机铁芯的磁路参数。同时,还需设计电机的绕组参数,如绕组的匝数、线径和分布方式等。这些参数的设计需要满足电机的工作要求和热界限条件。 最后,为了保证电机的安全可靠运行,还需要设计电机的控制系统。这包括选择合适的控制算法和控制器,为电机设计合理的保护措施。控制系统的设计能够提高电机的运行效率、稳定性和可靠性。 综上所述,旋转电机的设计是一个综合考虑电动力学、机械结构和控制系统的过程。通过合理的设计,可以满足电机的工作要求,并提高电机的性能。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值